Java Interview Questions


1) What is JAVA?

Java is a platform Independent programming language.

Java is secured, high-level and object-oriented programming language.


2) What are the Features of JAVA?

Features of Java:

  • Platform Independent.
  • Multi-threaded.
  • Robust.
  • Object-oriented.
  • High-Level.
  • Interpreted.

3) Write a program in Java to print "HELLO WORLD"?

Basic Java program example to print "HELLO WORLD".


4) Can main() method in Java can return any data?

No, main() method can not return any data that's why we always declared main() method with void return type.


5) Why multiple inheritance is not supported in java through class?

Because of "Ambiguity" , multiple inheritance is not supported in java through class.

Example:


6) What is the base class of all classes?

java.lang.Object is the base class of all classess.


7) Write a program in java to print factorial number using recursion?

Example of factorial using recursion:


8) What kind of thread is the garbage collector thread?

"Daemon thread" is the garbage collector thread.


9) Write a java program to check palindrome number?

Example of palindrome number:


10) In the below example, how many String Objects are created?

Here, two string objects are created. a1 and a3 are references to same object.


11) What are the types of "Access Modifiers" in java?

There are four types of access modifiers in java:

  • Private.
  • Default.
  • Protected.
  • Public.

12) What will be the output of following piece of code?

Here, postfix ++ operator used which first print the value and then increment. Hence it's output will be 5.


13) Can we have two methods in a class with the same name?

Yes, we can define two methods in a class with same name but different no of arguments /parameters.

Example:


14) Does the following code compile? If yes, what will be the output?

Yes , Code compiles.

Output:

ArithmeticException

15) Does the following code compile? If yes, what will be the output?

Yes , Code compiles.

Output:

Hello javaTpoint