0% found this document useful (0 votes)
2 views

20 commonly asked Java interview questions and their concise answers

The document lists 20 commonly asked Java interview questions along with concise answers. Key topics include Java's features, differences between JDK and JRE, class vs. object, exception handling, and various keywords like 'final' and 'static'. It also covers data structures like ArrayList and LinkedList, as well as concepts like method overriding and access modifiers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

20 commonly asked Java interview questions and their concise answers

The document lists 20 commonly asked Java interview questions along with concise answers. Key topics include Java's features, differences between JDK and JRE, class vs. object, exception handling, and various keywords like 'final' and 'static'. It also covers data structures like ArrayList and LinkedList, as well as concepts like method overriding and access modifiers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

20 commonly asked Java interview questions and their concise

answers. Here they are:

1. What is Java? Java is a high-level, object-oriented

programming language known for its platform independence and

used for developing a wide range of applications.

2. What are the main features of Java? Java features include

object-oriented programming, platform independence, automatic

memory management, and robust exception handling.

3. What is the difference between a JDK and a JRE? JDK (Java

Development Kit) is a software package that includes the tools

needed to develop Java applications, while JRE (Java Runtime

Environment) is required to run Java applications.

4. What are the differences between a class and an object? A

class is a blueprint or template for creating objects, while an object

is an instance of a class that represents a real-world entity.

5. What is the difference between the stack and the heap? The

stack is used for storing method invocations and local variables,

while the heap is used for dynamic memory allocation of objects.

6. What is the difference between a static method and an

instance method? A static method belongs to the class and can be


accessed without creating an instance, while an instance method

is associated with an instance of the class.

7. What is method overriding in Java? Method overriding is a

feature that allows a subclass to provide its own implementation of

a method defined in its superclass.

8. What are the access modifiers in Java? Access modifiers are

keywords used to specify the accessibility of classes, methods, and

variables. They include public, private, protected, and default (no

modifier).

9. What is the difference between an abstract class and an

interface? An abstract class can have method implementations and

variables, while an interface only contains method signatures and

constants.

10. What is the difference between checked and unchecked

exceptions? Checked exceptions must be declared or caught, while

unchecked exceptions do not require handling or declaration.

11. What is the difference between the "==" operator and the

".equals()" method? The "==" operator checks for reference

equality, while the ".equals()" method compares the contents of

objects for equality.


12. What is the purpose of the "final" keyword? The "final"

keyword is used to make a variable, method, or class

unchangeable, preventing modifications or inheritance.

13. What is the purpose of the "static" keyword? The "static"

keyword is used to create class-level variables and methods that

can be accessed without creating an instance of the class.

14. What is the purpose of the "this" keyword? "this" refers to the

current instance of a class and can be used to refer to instance

variables and invoke constructors.

15. What is the Java Virtual Machine (JVM)? The JVM is an

abstract machine that executes Java bytecode and provides a

platform-independent runtime environment.

16. What is the difference between an ArrayList and a LinkedList?

ArrayList uses a dynamic array to store elements, while LinkedList

uses a doubly-linked list, making it efficient for insertions and

deletions.

17. What is the difference between method overloading and

method overriding? Method overloading allows multiple methods

with the same name but different parameters in a class, while


method overriding provides a new implementation of a method in a

subclass.

18. What is the purpose of the "super" keyword? The "super"

keyword is used to refer to the superclass of a class and can be

used to invoke the superclass's constructor or access its methods

and variables.

19. What is a static initializer block? A static initializer block is a

block of code that is executed once when the class is loaded,

typically used to initialize static variables.

20. What is the difference between a HashSet and a TreeSet?

HashSet uses hash-based storage for efficient lookup, while

TreeSet stores elements in a sorted order based on their natural

order or a specified comparator.

You might also like