Hello and welcome to With Ninja

We're thrilled to have you here and hope you enjoy reading our content. Our blog is dedicated to Top 20 Java Interview Questions & Answers , and we're passionate about sharing our knowledge and insights with you.

If you ever have any questions or comments, please don't hesitate to reach out to us. We love hearing from our readers and value your feedback.



Top 20 Java Interview Questions & Answers 


1. What is a class in Java?

Answer: Java encapsulates the codes in various classes which define new data types. These new data types are used to create objects. 


2. What is a JVM?

Answer: JVM is Java Virtual Machine which is a run time environment for the compiled java class files. 


3. What is the right data type to represent a price in Java?

Answer: BigDecimal, if memory is not a concern and Performance, is not critical, otherwise double with predefined precision. 


4. Does Java support multiple inheritances?

Answer: Java doesn’t support multiple inheritances.


5. What are the supported platforms by Java Programming Language?

Answer: Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX/Linux like HP-Unix, Sun Solaris, Red hat Linux, Ubuntu, Cent OS, etc.


6. List any five features of Java?

Answer: Some features include Object Oriented Platform Independent Robust Interpreted Multi-threaded 


7. Explain method overloading?

Answer: When a Java program contains more than one methods with the same name but different properties, then it is called method overloading. 


8. What restrictions are placed on the location of a package statement within a source code file? 

Answer: A package statement must appear as the first line in a source code file (eliminating blank lines and comments). 


9. What method is used to specify a container’s layout?

Answer: The setLayout() method is used to specify a container’s layout. 


10. What is the immediate superclass of the Applet class?

Answer: The Panel class is the immediate superclass of the Applet class. 


11. What are the access modifiers in Java?

Answer: There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly. 


12. What is are packages?

Answer: A package is a collection of related classes and interfaces providing access protection and namespace management. 


13. What is meant by Inheritance and What are its advantages?

Answer: Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses. 


14. Can we rethrow the same exception from catch handler?

Answer: Yes, we can rethrow the same exception from our catch handler. If we want to rethrow checked exception from a catch block we need to declare that exception. 


15. what value is a variable of the String type automatically initialized?

Answer: The default value of a String type is null. 


16. When a thread blocks on I/O, what state does it enter?

Answer: When it blocks on I/O, A thread enters the waiting state. 


17. Which containers use a Flow Layout as their default layout?

Answer: The Panel and Applet classes use the Flow Layout as their default layout. 


18. Explain Java Coding Standards for Constants ?

Answer: Constants in java are created using static and final keywords. 1) Constants contain only uppercase letters. 2) If the constant name is a combination of two words it should be separated by an underscore. 3) Constant names are usually nouns. Ex:MAX_VALUE, MIN_VALUE, MAX_PRIORITY, MIN_PRIORITY 


19. What is synchronization and why is it important?

Answer: The term synchronization is the ability to control the access of multiple threads to shared resources. And it is important because, without it, it is not possible for one thread to modify a shared object while another thread is in the process of using or updating that object’s value. This often leads to major errors. 


20. Explain Java Coding Standards for variables? 

Answer: 1) Variable names should start with small letters. 2) Variable names should be nouns 3) Short meaningful names are recommended. 4) If there are multiple words every inner world should start with Uppercase character. Ex : string,value,empName,MEP salary 


21. What is an abstract class?

Answer: An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.




Thank you for choosing With Ninja as your go-to source for Top 20 Java Interview Questions & Answers . We can't wait to embark on this journey with you!

Best regards,


With Ninja