Thursday, April 21, 2011

Java Interview Questions Part 14

1. Is String a primitive data type in Java?
No String is not a primitive data type in Java, even though it is one of the most extensively used object. Strings in Java are instances of String class defined in java.lang package.

2. Is main a keyword in Java?
No, main is not a keyword in Java.

3. Is next a keyword in Java?
No, next is not a keyword.

4. Is delete a keyword in Java?
No, delete is not a keyword in Java. Java does not make use of explicit destructors the way C++ does.


5. Is exit a keyword in Java?
No. To exit a program explicitly you use exit method in System object.


6. What happens if you dont initialize an instance variable of any of the primitive types in Java?
Java by default initializes it to the default value for that primitive type. Thus an int will be initialized to 0, a boolean will be initialized to false.


7. What will be the initial value of an object reference which is defined as an instance variable?
The object references are all initialized to null in Java. However in order to do anything useful with these references, you must set them to a valid object, else you will get NullPointerExceptions everywhere you try to use such default initialized references.

No comments:

Post a Comment