Sunday 13 January 2013

Core Java Interview Questions



1. Is java platformindependent? Explain.
Java is platform independent. we can write and compile the java code in one platform (like  Windows) to generate the class files and can execute the class in any other supported platform (like Linux,Solaris,etc). Java is called “Write once and run anyware”.

2. How a class file can be run different platforms?
The JVM takes care of running the class files. There are unique JVM for all known platforms. So depending on the platforms the JVM differs.

3. What is the initial value of instance variable in java?
null

4. What is a constructor?
It is just like a method which is used to initialize variables or perform some operation when an object is created for the class.

5. Can a constructor be final?
No

6. What is a Static variable?
Static variable gets only one memory when the class is first loaded. Any changes made to static variable are reflected in all the objects of the class.

7. What is a Static method?
Static method can be invoked without even creating the object for the class.
It belong to the class rather than its object. Static method can access only other static method.

8. Why main method is static?
Main method has to be called first in java. If main is not static then JVM has to create an object and then call the method.

9. What static block?
Static blocks are executed only once,  when the class is loaded for the first time.

10. What is THIS in java?
It refers to current object.

                                                                           Next

No comments:

Post a Comment