Java Interview Questions
1 .
The memory allocated by JVM to execute the program is called?
Run time data areas.
2 .
What is the difference between #include and import statement?
#include directive makes the compiler go to the C/C++ standard library and copy the code from the header files into the program. As a result, the program size increases, thus wasting memory and processor’s time.

import statement makes the JVM go to the java standard library, execute the code there, and substitute the result into the program. Here, no code is copied and hence no waste of memory or processor’s time. So, import is an efficient mechanism than #include
3 .
What happens if String args[] is not written in main() method?
When main() method is written without String args[] as :
 public static void main()
The code will compile but JVM cannot run the code because it cannot recognize the main() method as the method from where it should start execution of the java program. 

Remember JVM always looks for main() method with string type array as parameter.
4 .
What is the difference between print() and println() method?
Both methods are used to display the results on the monitor. Print() method displays the result and then retains the cursor in the same line, next to the result. 

Println() displays the result and then throws the cursor to the next line.
5 .
Do I need to import java.lang package any time? Why?
No. It is by default loaded internally by the JVM.
6 .
Can I have multiple main methods in the same class?
No the program fails to compile. The compiler says that the main method is already defined in the class.
7 .
What if I write static public void instead of public static void?
Program compiles and runs properly.
8 .
What if the static modifier is removed from the signature of the main method?
Program compiles. But at runtime throws an error "NoSuchMethodError".
9 .
What if the main method is declared as private?
The program compiles properly but at runtime it will give "Main method not public." message.
10 .
What is the base class of all the classes?
java.lang.Object