Friday, September 23, 2011


As you all know java is a pure Object Oriented language.
Is java Really a pure Object Oriented Language?

The answer is NO..Java is not a pure object oriented language.
1)The main reason for this is it does not always deal with objects.
int,char,float,etc are not in the form of objects and java uses them. So this is the main reason why java is not object oriented language.
2)The other reason is that java does not support Multiple inheritance in case of classes,but a pure object oriented language supports multiple inheritance.

Now let us see some of the basic thing in java which is to be noted. Those who already know java can skip this.

What is the default value of Byte?

Now a question may arise in your mind,that the default value of byte is false.Your question is correct.
If you observe clearly,then you will find that default value of Byte is asked not byte.And Byte is a class that means it will store reference. Remember in the first java basic, i told to see the data types start with lower case.

Point to be remembered: In java a class is always declared with first letter as Upper case letter(This is not a rule but it is a best practice so that you never make mistake).

Similarly you will find some more class which may confuse you like Boolean with boolean ,Float with float,Double with double. So don't get confuse with these classes.

 Now a question may arise in your mind that why they have made these confusing classes.What is the use of these classes.Your question is correct,following is the explanations for this.

Sometimes we need objects of these primitive data types,for this Java has made WRAPPER CLASSES for these primitive data types. All the primitive data types have Wrapper Class. Now by using these Wrapper classes,we can convert these data types to Objects and can use them.
Following are the wrapper classes of the primitive data types
1)int    --> Integer
2)byte   -->Byte
3)short   ---> Short
4)char    --->Character
5)boolean  --> Boolean
6)float    --->Float
7)double   --->Double
8)long     --->Long
9)void    ---> Void

Compilation of program:
The java compiler search for a particular signature in the main function.
The signature is
public static void main(String[] args)
This is the signature,that should exist in a program to run ,otherwise it will not run.

Example for the above concept
Class A
public static void main(String[] args)
     System.out.println("my string");
public static void main(char b)

Output: x
            my string

Reason: It will only treat the first main method as the main method as it is having proper signature and treats 2nd method like a normal java method.

Example2:Count how many objects are created and how many references exist:

Customer a=new Customer();
Customer b=new Customer();
Customer c=a;
Customer d= b;
new Customer();

Ans: 3 Objects 4 references

In these types of questions just count the number of new keywords that will give you the number of objects.
and count the number of references by the class name count and in some examples please make the heap and object diagram which we made earlier and then there will be no mistakes.

In next we will learn the concept of static in java..So keep reading...