Basic Advanced Java Interview Questions and Answers

1. What is Java?

Java is a High-level, platform-independent, object-oriented programming language used for developing various applications.

2. What are JVM, JRE and JDK?

  • JVM: Runs Java bytecode.
  • JRE: Provides runtime environment.
  • JDK: Includes tools to compile and run Java code.

3. What are the features of Java?

Key features include Platform Independence, Object-Oriented, Robustness, Multithreading, and Security.

4. What is Inheritance in Java?

Inheritance allows one class to inherit the properties and methods of another using the extends keyword.

5. What is Polymorphism?

Polymorphism allows a method to have different behaviors, achieved using method overloading and method overriding.

6. What are Java access modifiers?

Access modifiers control visibility:

  • Public: Accessible everywhere.
  • Protected: Accessible within package and subclasses.
  • Private: Accessible only within the class.

7. What is the Final keyword?

  • Final class: Cannot be inherited.
  • Final method: Cannot be overridden.
  • Final variable: Value cannot be changed.

8. What is an Interface in Java?

An interface defines a contract with only abstract methods and constants. Java 8 added default and static methods.

9. Explain the difference between Abstract class and Interface.

Abstract class: Can have implemented methods.
Interface: Contains only abstract methods (prior to Java 8

10. What is Java Collections Framework?

The Collections Framework provides data structures like ArrayList, HashMap, and HashSet to store and manipulate objects.

11. What is Exception handling in Java?

Exception handling manages runtime errors using try, catch, finally, throw, and throws.

12. Differentiate between Checked and Unchecked exceptions.

Checked exceptions: Compile-time exceptions (e.g., IOException).
Unchecked exceptions: Runtime exceptions (e.g., NullPointerException).

13. What is the purpose of the this keyword?

The this keyword refers to the current object of a class and resolves variable-shadowing conflicts.

14. What is the difference between and equals?

  • == compares references.
  • equals() compares object values.

15. What is Garbage Collection in Java?

Garbage Collection automatically reclaims unused memory, managed by the JVM.

16. What is Multithreading in Java?

Multithreading enables concurrent execution of threads, improving application performance.


17. What is the synchronized keyword?

The synchronized keyword ensures thread-safe access to shared resources in multithreaded programs.

18. What is a Lambda Expression?

A Lambda Expression simplifies writing anonymous functions, introduced in Java 8 for functional programming.

19. What is the difference between String, Stringbuilder and Stringbuffer?

  • String: Immutable.
  • StringBuilder: Mutable, not thread-safe.
  • StringBuffer: Mutable, thread-safe.

20. What are Java Streams?

Streams process data collections in a functional style, enabling operations like filter, map, and reduce.

21. What is the use of the final keyword in Multithreading?

A final variable ensures immutability, aiding thread safety.

22. What are functional interfaces?

A functional interface has exactly one abstract meth

23. What is the difference between an Arraylist and a LinkedList?

  • ArrayList: Fast random access, slow insertion/removal.
  • LinkedList: Fast insertion/removal, slow random access.

24. What is the purpose of the super keyword?

The super keyword accesses parent class members, including constructors and methods.

25. What are Java Annotations?

Annotations provide metadata to Java code, commonly used in frameworks like Spring and Hibernate.
line

Copyrights © 2024 letsupdateskills All rights reserved