Interview Questions & Answers

Interview Questions and Answers Fundamental aspects of Java programming, and understanding them well can help you prepare for Java interviews.
  • Home
  • Interview Questions and Answers

Interview Questions and Answers

  1. What is the difference between JDK, JRE, and JVM?

    • JDK (Java Development Kit): It is a software development kit used to develop Java applications. It includes the Java Compiler, Java Runtime Environment (JRE), and other tools needed for Java development.
    • JRE (Java Runtime Environment): It provides the runtime environment for executing Java programs. It includes the Java Virtual Machine (JVM) and core libraries.
    • JVM (Java Virtual Machine): It is an abstract computing machine that provides the runtime environment for Java bytecode. It interprets the bytecode and executes it on the underlying hardware.
  2. What is the difference between == and .equals() in Java?

    • == is used to compare primitive data types or to check if two objects reference the same memory location.
    • .equals() is a method defined in the Object class, which is overridden by classes to provide their own implementation for comparing object contents. It is used to compare the actual contents or attributes of objects.
  3. What is the difference between ArrayList and LinkedList?

    • ArrayList: It internally uses a dynamic array to store elements. It provides fast random access and is suitable for scenarios where retrieval of elements by index is frequent.
    • LinkedList: It internally uses a doubly linked list to store elements. It provides fast insertion and deletion operations, especially at the beginning or end of the list.
  4. What is the difference between HashMap and HashTable?

    • Both are used to store key-value pairs, but HashMap is not synchronized and allows null values and one null key, whereas HashTable is synchronized and does not allow null keys or values.
  5. What is method overloading and method overriding?

    • Method Overloading: It is the ability to define multiple methods in a class with the same name but different parameters. Overloaded methods must have different parameter lists or types.
    • Method Overriding: It occurs when a subclass provides a specific implementation of a method that is already provided by its superclass. The method signatures must be the same, and it allows polymorphism in Java.
  6. What are access modifiers in Java?

    • Access modifiers control the visibility and accessibility of classes, methods, and variables in Java.
    • There are four access modifiers in Java: public, protected, default (no modifier), and private.
    • public: Accessible from any other class.
    • protected: Accessible within the same package or subclasses.
    • default: Accessible within the same package.
    • private: Accessible only within the same class.
  7. What is the static keyword in Java?

    • The static keyword is used to create variables and methods that belong to the class rather than to any instance of the class.
    • Static variables are shared among all instances of the class.
    • Static methods can be called without creating an instance of the class.
  8. What is the final keyword in Java?

    • The final keyword is used to restrict the user from changing the value of a variable, the implementation of a method, or the inheritance of a class.
    • A final variable cannot be reassigned once initialized.
    • A final method cannot be overridden by subclasses.
    • A final class cannot be subclassed.
  9. What is the difference between StringBuilder and StringBuffer?

    • Both StringBuilder and StringBuffer are used to manipulate strings, but StringBuilder is not synchronized and is faster than StringBuffer, which is synchronized.
    • StringBuilder is preferred in scenarios where thread safety is not required.
  10. What are the principles of Object-Oriented Programming (OOP)?

    • Encapsulation: Binding data and methods that operate on the data into a single unit (class).
    • Inheritance: Ability of a class to inherit properties and behavior from another class.
    • Polymorphism: Ability of objects to take on multiple forms, allowing different implementations of methods to be invoked depending on the object’s type.
    • Abstraction: Hiding the complex implementation details and showing only the essential features of the object.