Saturday, April 26, 2014

About "new" Keyword in Java

About "new" Keyword

Normally people always get confused with the usage of "new" in Java. Yes we do create objects with it but there's something more to it.

The "new" operator instantiates a class by allocating memory for a new object and returning a Reference to that memory. The new operator also invokes the object constructor. This reference is usually assigned to a variable of the appropriate type.

Concider this code: 

MyObject obj; 
obj = new MyObject(); 

In the first line you only create a Reference to an object of type MyObject. But that reference is blank and points nowhere! So if you tried doing something like obj.myFunction() your program would crash. 

In the second line we use the "new" keyword to actually allocate an Instance of MyObject. Then we point our blank reference obj to that newly created instance. From there on, we can use obj to refer to that object and can use its member functions and properties like obj.myFuncion() and obj.myProperty = 2.

Creating an object of a Class without using "new" Keyword


It is of general practice to create an object with new keyword. It is also possible to create an object without new keyword. This is of logical significance only and not used in regular practice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Hello
{
  public void display()
  {
    System.out.println("Hello World");
  }
  public static void main(String args[]) throws Exception
  {
    Class c1 = Class.forName("Hello");  // throws ClassNotFoundException
    Object obj1 = c1.newInstance( );    // throws InstantiationException and 
                   // IllegalAccessException
    Hello h1 = (Hello) obj1;
    h1.display();
  }
}

forName() is a static method of java.lang.Class that loads the .class file of Hello into the RAM and returns the Hello as an object of class Class. c1 contains the reference of Hello. newInstance() method of class Class returns an object of Object class. Now, obj1 contains the reference of Hello. Internally, JVM may use new keyword. The object obj1 is explicitly type casted to Hello object, h1.

Tuesday, October 1, 2013

iOS vs Android

A lot of people just don't understand and say iOS is faster and smoother than Android. Well there's a lot of explanations behind it.

First iOS gives the UI threads top priority so that the UI stays responsive even if the background task has to stop. On the other hand Android treats the UI thread as any other thread and thus giving normal priority. And this means while interacting with the UI Background task also runs. And that brings some serious multitasking capability. So if any task wants the resource and CPU is not idle then you experience a little lag. But end user thinks that the lag is because of the App.

So basically the both OS are great but they have their own pros and cons. Personally I think Android implementation is close to real desktop OS and is more functional in terms of multitasking. If you want an example you can try to open a browser and load an URL. While loading try to play around a bit like zooming or panning. You will notice Android is loading the page while iOS is not. This is because iOS is focusing all it's resource on UI interaction rather than loading and rendering the page.

Hope this clears out some doubt. Well I am an Android fan writing this on my iPad :P


Sunday, September 8, 2013

Android OS Partitions Explained


Unless you have been using your Android phone just for calls, SMS, browsing and basic apps, you should know that Android uses several partitions to organize files and folders on the device. Each of these partitions has a distinct role in the functionality of the device, but not many Android users know the significance of each partition and its contents. In this guide, I will take you on a tour of Android partitions, what they contain and what can be the possible consequences of modifying their content.

Let’s start with a list of standard internal memory partitions on Android phones and tablets. These are:
  • /boot
  • /system
  • /recovery
  • /data
  • /cache
  • /misc
In addition, there are the SD card partitions.
  • /sdcard
  • /sd-ext (if your device has SD Card support)
Let’s now take a look at the purpose and contents of each of these partitions.
/boot
This is the partition that enables the phone to boot, as the name suggests. It includes the kernel and the ramdisk. Without this partition, the device will simply not be able to boot. Wiping this partition from recovery should only be done if absolutely required and once done, the device must NOT be rebooted before installing a new one, which can be done by installing a ROM that includes a /boot partition. This can be flashed from recovery (S-OFF i.e. secure boot off) or from PC using fastboot utility. Also do remember to flash the boot image corresponding to the custom ROM or Stock. If boot image is wrong than you device may enter into a infinite boot loop.
/system
This partition basically contains the entire operating system, other than the kernel and the ramdisk. This includes the Android user interface as well as all the system applications that come pre-installed on the device. Wiping this partition will remove Android from the device without rendering it unbootable, and you will still be able to put the phone into recovery or bootloader mode to install a new ROM. If you have root than you can un-install some system Apps.
/recovery
The recovery partition can be considered as an alternative boot partition that lets you boot the device into a recovery console for performing advanced recovery and maintenance operations on it. You can flash custom ROMs or take a Nandroid backup.

/data
Also called userdata, the data partition contains the user’s data – this is where your contacts, messages, settings and apps that you have installed go. Wiping this partition essentially performs a factory reset on your device, restoring it to the way it was when you first booted it, or the way it was after the last official or custom ROM installation. When you perform a wipe data/factory reset from recovery, it is this partition that you are wiping.
/cache
This is the partition where Android stores frequently accessed data and app components. Wiping the cache doesn't effect your personal data but simply gets rid of the existing data there, which gets automatically rebuilt as you continue using the device. 
/misc
This partition contains miscellaneous system settings in form of on/off switches. These settings may include CID (Carrier or Region ID), USB configuration and certain hardware settings etc. This is an important partition and if it is corrupt or missing, several of the device’s features will will not function normally.
/sdcard
This is not a partition on the internal memory of the device but rather the SD card. In terms of usage, this is your storage space to use as you see fit, to store your media, documents, ROMs etc. on it. Wiping it is perfectly safe as long as you backup all the data you require from it, to your computer first. Though several user-installed apps save their data and settings on the SD card and wiping this partition will make you lose all that data.
/sd-ext
It is basically an additional partition on your SD card that acts as the /data partition when used with certain ROMs that have special features called APP2SD+ or data2ext enabled. It is especially useful on devices with little internal memory allotted to the /data partition. Thus, users who want to install more programs than the internal memory allows can make this partition and use it with a custom ROM that supports this feature, to get additional storage for installing their apps. Wiping this partition is essentially the same as wiping the /data partition – you lose your contacts, SMS, market apps and settings.
With this, I think you now have a basic understanding of Android partitions and it's importance. Now whenever you install a ROM or mod that requires you to wipe certain partitions before the installation, you should be in a better position to know what you’re losing and what not and thus, you’ll know what to backup and what not.

Thursday, August 22, 2013

What's behind that Apple logo ?

We sure love that shiny Apply logo behind our iDevices (specially iPhone and iPad). But have you ever wondered what's beneath ? Here are some component details for iPhone & iPad

  1. Display : Manufactured by LG (majority) and SHARP (IGZO display)
  2. CPU : Manufactured by Samsung (TSMC in future) 
  3. Camera (Sensor) : Manufactured by Sony (Exmor R)
  4. Battery (iPhone 5) : Manufactured by Sony
  5. Memory : Manufactured by Hynix (Sometimes TOSHIBA also)
and lot's more ...

So basically when you praise (blindly) that beautiful Apple logo do remember to give others some credit.

You can check all the component details from iFixit site where they do all kinds of tear-down stuff. 

Monday, August 19, 2013

Android 4.3 Top Features


Top features of Android 4.3

  1. Play Games is now bundled with the OS
  2. Connectivity improvements (specially Bluetooth and WiFi)
    • Bluetooth 4.0 support (low power)
    • Always on WiFi scanning
  3. Restricted Profiles
  4. OpenGL ES 3.0 support 
  5. TRIM Support
Along with these there is also under the hood changes which makes the system even more responsive.

Friday, November 26, 2010

Everyone is gifted - but some people never open their package.

Tuesday, October 19, 2010

Some people have so much respect for their superiors they have none left for themselves.