Top 100 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. 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.