Java Interview Questions and Answers for Freshers
Tags: java, javainterview, interviewquestions, corejava
Published: 2023-04-27 10:39:02

Practice here the most popular [Core Java Interview Questions](https://www.onlineinterviewquestions.com/core-java-interview-questions/) and Answers, which asked many times in Java Interview.

**What is Java?**
**Answer:** Java is a high-level, object-oriented programming language that is designed to be platform-independent, meaning that code written in Java can run on any machine that has a Java Virtual Machine (JVM).

**What is an object in Java?**
**Answer:** An object is an instance of a class that has state and behavior.

**What is a class in Java?**
**Answer:** A class is a blueprint or template for creating objects.

**What is the difference between a class and an object?**
**Answer:** A class is a blueprint or template for creating objects, while an object is an instance of a class.

**What is the difference between a constructor and a method in Java?**
**Answer:** A constructor is a special type of method that is used to initialize the object's state, while a method is a regular function that performs some action on the object.

**What is the difference between an abstract class and an interface in Java?**
**Answer:** An abstract class is a class that cannot be instantiated and may contain both abstract and concrete methods, while an interface is a collection of abstract methods and constants.

**What is Java?**
**Answer:** Java is a high-level, object-oriented programming language that is designed to be platform-independent, meaning that code written in Java can run on any machine that has a Java Virtual Machine (JVM).

**What is an object in Java?**
**Answer:** An object is an instance of a class that has state and behavior.

**What is a class in Java?**
**Answer:** A class is a blueprint or template for creating objects.

**What is the difference between a class and an object?**
**Answer:** A class is a blueprint or template for creating objects, while an object is an instance of a class.

**What is the difference between a constructor and a method in Java?**
**Answer:** A constructor is a special type of method that is used to initialize the object's state, while a method is a regular function that performs some action on the object.

**What is the difference between an abstract class and an interface in Java?**
**Answer:** An abstract class is a class that cannot be instantiated and may contain both abstract and concrete methods, while an interface is a collection of abstract methods and constants.

**What is inheritance in Java?**
**Answer:** Inheritance is a mechanism in which one class acquires the properties and behaviors of another class.

**What is the difference between method overloading and method overriding in Java?**
**Answer:** Method overloading is when two or more methods have the same name but different parameters, while method overriding is when a subclass provides a specific implementation for a method that is already provided by its parent class.

**What is the final keyword in Java?**
**Answer:** The final keyword can be used to mark a class, method, or variable as immutable or unchangeable.

**What is the static keyword in Java?**
**Answer:** The static keyword can be used to mark a class, method, or variable as belonging to the class rather than to a specific instance of the class.

**What is encapsulation in Java?**
**Answer:** Encapsulation is the process of hiding the implementation details of a class and providing a public interface for accessing the class's properties and methods.

**What is polymorphism in Java?**
**Answer:** Polymorphism is the ability of an object to take on many forms, meaning that an object can be used as if it is of many different types.

**What is the difference between a StringBuffer and a StringBuilder in Java?**
**Answer:** A StringBuffer is thread-safe and synchronized, while a StringBuilder is not.

**What is the difference between a checked and an unchecked exception in Java?**
**Answer:** A checked exception is a type of exception that must be declared in a method or caught by a try-catch block, while an unchecked exception is a type of exception that does not need to be declared or caught.

**What is the difference between a stack and a queue in Java?**
**Answer:** A stack is a last-in, first-out (LIFO) data structure, while a queue is a first-in, first-out (FIFO) data structure.

**What is the difference between a HashSet and a TreeSet in Java?**
**Answer:** A HashSet is an unordered collection of unique elements, while a TreeSet is an ordered collection of unique elements.

**What is a lambda expression in Java?**
**Answer:** A lambda expression is a concise way of expressing an anonymous function in Java.

**What is the difference between a stream and a collection in Java?**
**Answer:** A stream is a sequence of elements that can be processed in parallel or sequentially, while a collection is a group of elements that can be accessed and modified.
Answer: Inheritance is a mechanism in which one class acquires the properties and behaviors of another class.

**What is the difference between method overloading and method overriding in Java?**
**Answer:** Method overloading is when two or more methods have the same name but different parameters, while method overriding is when a subclass provides a specific implementation for a method that is already provided by its parent class.

**What is the final keyword in Java?**
**Answer:** The final keyword can be used to mark a class, method, or variable as immutable or unchangeable.

**What is the static keyword in Java?**
**Answer:** The static keyword can be used to mark a class, method, or variable as belonging to the class rather than to a specific instance of the class.

**What is encapsulation in Java?**
**Answer:** Encapsulation is the process of hiding the implementation details of a class and providing a public interface for accessing the class's properties and methods.

**What is polymorphism in Java?**
**Answer:** Polymorphism is the ability of an object to take on many forms, meaning that an object can be used as if it is of many different types.

**What is the difference between a StringBuffer and a StringBuilder in Java?**
**Answer:** A StringBuffer is thread-safe and synchronized, while a StringBuilder is not.

**What is the difference between a checked and an unchecked exception in Java?**
**Answer:** A checked exception is a type of exception that must be declared in a method or caught by a try-catch block, while an unchecked exception is a type of exception that does not need to be declared or caught.

**What is the difference between a stack and a queue in Java?**
**Answer:** A stack is a last-in, first-out (LIFO) data structure, while a queue is a first-in, first-out (FIFO) data structure.

**What is the difference between a HashSet and a TreeSet in Java?**
**Answer:** A HashSet is an unordered collection of unique elements, while a TreeSet is an ordered collection of unique elements.

**What is a lambda expression in Java?**
**Answer:** A lambda expression is a concise way of expressing an anonymous function in Java.

**What is the difference between a stream and a collection in Java?**
**Answer:** A stream is a sequence of elements that can be processed in parallel or sequentially, while a collection is a group of elements that can be accessed and modified.

**What is a thread in Java?**
**Answer:** A thread is a lightweight process that can be executed independently and concurrently with other threads within the same program.

**What is synchronization in Java?**
**Answer:** Synchronization is the process of ensuring that multiple threads do not simultaneously execute a critical section of code, which can lead to race conditions and other issues.

**What is the difference between a private and a protected method in Java?**
**Answer:** A private method can only be accessed within the same class, while a protected method can be accessed within the same class and its subclasses.

**What is the difference between a local variable and an instance variable in Java?**
**Answer:** A local variable is a variable that is declared within a method and has a limited scope, while an instance variable is a variable that is declared within a class and is accessible to all methods of the class.

**What is the difference between a float and a double in Java?**
**Answer:** A float is a single-precision floating-point number that takes up 32 bits of memory, while a double is a double-precision floating-point number that takes up 64 bits of memory.

**What is a package in Java?**
**Answer:** A package is a grouping of related classes and interfaces that provide a namespace to avoid naming conflicts.

**What is a constructor chaining in Java?**
**Answer:** Constructor chaining is the process of calling one constructor from another constructor of the same class using the "this" keyword.
Thanks for reading here.