Core JAVA Interview Questions and Answers

1. What is the most important feature of java?
Java is platform independent language.

2. What do you mean by Platform Independence?
Platform Independence you can run and compile program in one platform and can execute in any other platform.

3. What is JVM (Java Virtual Machine)?
JVM is Java Virtual Machine which is a run time Environment for the compiled java class.

4. What is JIT Compiler?
Just-In-Time (JIT) compiler is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time.

5. Are JVM’s Platform Independent?
JVM’S are not platform Independent. JVM’S are platform Specific.

6. What if main method declare as private?
No, It will compile fine but in run time it will error like main method should be in public. Cannot find main method.

7. What is platform?
A platform is basically the hardware or software environment in which a program runs.
There are two types of platforms software and hardware.
Java provides software-based platform.

8. What all memory areas are allocated by JVM?
Heap, Stack, Program Counter Register and Native Method Stack.

9. What is the base class of all classes?

10. What is javac?
It produces the java byte code from *.java file.
It is the intermediate representation of your source code that contains instructions.

11. Can we mark constructors final?
No, Constructor cannot be declared final.

12. What are two different ways to call garbage collector?
gc () OR Runtime. getRuntime ().gc ().

13. Can we override a static method?
No, we cannot override a static method. Static means class level.

14. Use of finalize () method in java?
finalize () method is used to free the allocated resource.

15. Is it possible to overload main() method of a class?
Yes, we can overload main () method as well.
But every time public static main (String [] args) will be called automatically by JVM.
Other methods need to call explicitly.

16. Does Java support operator overloading?
Operator overloading is not supported in Java.

17. Can I declare a data type inside loop in java?
Any Data type declaration should not be inside the loop. It’s possible but not recommended.

18. List two java IDEs?
Eclipse, Net beans and IntelliJ

19. Can we inherit the constructors?
No, we cannot inherit constructors.
We can call super class constructors from subclass constructor by using super() call.

20. Can this keyword be assigned null value?
No, this keyword cannot have null values assigned to it.