Fundamentals Interview Questions
Comprehensive fundamentals interview questions and answers for Java. Prepare for your next job interview with expert guidance.
Questions Overview
1. What is the difference between JDK, JRE, and JVM?
BasicJDK (Java Development Kit) is a full-featured software development kit for Java, including the compiler and other tools. JRE (Java Runtime Environment) provides libraries, Java Virtual Machine (JVM), and other components to run Java applications. JVM is an abstract machine that executes Java bytecode.
2. What are Java's key object-oriented principles?
ModerateThe key object-oriented principles in Java are encapsulation, inheritance, polymorphism, and abstraction. Encapsulation bundles data and methods, inheritance allows classes to derive from others, polymorphism enables dynamic method invocation, and abstraction provides simplified interfaces.
3. What is the purpose of the `final` keyword in Java?
ModerateThe `final` keyword in Java is used to declare constants (variables that can't be changed), prevent method overriding (methods can't be overridden in subclasses), and prevent inheritance (classes can't be subclassed).
4. What is the difference between `equals()` and `==` in Java?
Moderate`==` compares object references, checking if both objects point to the same memory location. The `equals()` method compares the actual content of objects, checking for logical equality. By default, `equals()` is inherited from `Object` and behaves like `==` unless overridden.
5. What is a constructor in Java?
BasicA constructor is a special method in Java used to initialize objects. It has the same name as the class and does not return any value. Constructors are called when an instance of the class is created and can be overloaded to provide multiple ways to initialize objects.