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

Top 50 Java Interview Questions

The document presents a comprehensive list of the top 50 Java interview questions and answers, covering fundamental concepts such as Java's features, JVM, JRE, JDK, and key programming principles like inheritance, polymorphism, and encapsulation. It also addresses advanced topics including lambda expressions, the Stream API, and design patterns like dependency injection and SOLID principles. This resource serves as a valuable guide for candidates preparing for Java-related interviews.

Uploaded by

keerthireddykv32
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Top 50 Java Interview Questions

The document presents a comprehensive list of the top 50 Java interview questions and answers, covering fundamental concepts such as Java's features, JVM, JRE, JDK, and key programming principles like inheritance, polymorphism, and encapsulation. It also addresses advanced topics including lambda expressions, the Stream API, and design patterns like dependency injection and SOLID principles. This resource serves as a valuable guide for candidates preparing for Java-related interviews.

Uploaded by

keerthireddykv32
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Top 50 Java Interview Questions and Answers

1. What is Java?
Java is a high-level, object-oriented programming language developed by Sun Microsystems, now
owned by Oracle. It is platform-independent and runs on the Java Virtual Machine (JVM).

2. What are the main features of Java?


Key features include object-oriented, platform independence (WORA - Write Once, Run Anywhere),
automatic memory management (Garbage Collection), multithreading, and security.

3. What is JVM, JRE, and JDK?


JVM (Java Virtual Machine) executes Java bytecode. JRE (Java Runtime Environment) includes
JVM and libraries. JDK (Java Development Kit) contains JRE, compiler, and development tools.

4. What is the difference between JDK 8 and JDK 11?


JDK 8 introduced features like Lambda expressions and Stream API, whereas JDK 11 removed
Java EE modules and included new HTTP client APIs.

5. What is the difference between a class and an object?


A class is a blueprint for creating objects. An object is an instance of a class with its own state and
behavior.

6. What are access modifiers in Java?


Access modifiers control the visibility of classes, methods, and variables. They include public,
private, protected, and default.

7. What is the difference between == and .equals()?


== compares object references, while .equals() compares the actual values of objects.

8. What is inheritance in Java?


Inheritance allows a class to inherit properties and methods from another class using 'extends'.

9. What is method overloading and overriding?


Method overloading is defining multiple methods with the same name but different parameters.
Overriding is redefining a method in a subclass to provide a specific implementation.

10. What is the difference between an abstract class and an interface?


An abstract class can have method implementations, while an interface only contains method
signatures (until Java 8, which introduced default methods).
11. What are static methods in Java?
Static methods belong to the class rather than instances and can be called without creating an
object.

12. What is the difference between final, finally, and finalize?


final is a keyword to declare constants or prevent inheritance. finally is a block used in exception
handling. finalize() is a method invoked before garbage collection.

13. What is a constructor?


A constructor is a special method used to initialize objects.

14. What is encapsulation?


Encapsulation is the practice of keeping fields private and providing public getter and setter
methods.

15. What is polymorphism?


Polymorphism allows methods to take different forms, such as method overloading and method
overriding.

16. What is an exception in Java?


An exception is an event that disrupts the normal flow of execution.

17. What are checked and unchecked exceptions?


Checked exceptions are checked at compile-time, while unchecked exceptions occur at runtime.

18. What is a thread in Java?


A thread is a lightweight process that enables concurrent execution.

19. How does Java handle memory management?


Java uses Garbage Collection to manage memory automatically.

20. What is the difference between ArrayList and LinkedList?


ArrayList is faster for accessing elements, while LinkedList is better for insertions and deletions.

21. What is the difference between HashMap and HashTable?


HashMap is not synchronized and allows one null key, whereas HashTable is synchronized and
does not allow null keys.

22. What is the difference between Comparable and Comparator?


Comparable is used for natural ordering and implemented using the compareTo() method, while
Comparator is used for custom ordering via the compare() method.
23. What is the difference between String, StringBuilder, and StringBuffer?
String is immutable, StringBuilder is mutable and not thread-safe, and StringBuffer is mutable and
thread-safe.

24. What is an enum in Java?


An enum is a special data type used to define collections of constants.

25. What are lambda expressions?


Lambda expressions provide a clear and concise way to implement functional interfaces in Java 8.

26. What is the Stream API?


Stream API allows functional-style operations on collections using methods like filter(), map(), and
reduce().

27. What is the Optional class in Java?


Optional is a container object used to handle null values more effectively.

28. What are functional interfaces?


A functional interface is an interface with a single abstract method, e.g., Runnable, Callable, and
Predicate.

29. What is the difference between deep copy and shallow copy?
A shallow copy copies references, whereas a deep copy creates a new object with copied values.

30. What is a singleton class?


A singleton class ensures only one instance exists throughout the JVM.

31. What is dependency injection?


Dependency Injection (DI) is a design pattern used to manage dependencies and achieve loose
coupling.

32. What is the SOLID principle?


SOLID stands for Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation,
and Dependency Inversion.

33. What is reflection in Java?


Reflection allows runtime access to classes, methods, and fields.

34. What are Java annotations?


Annotations provide metadata about code and are used for configurations like @Override,
@FunctionalInterface, etc.
35. What is the volatile keyword?
volatile ensures visibility of variable changes across threads.

36. What is a deadlock?


A deadlock occurs when two or more threads are blocked forever, each waiting for the other to
release resources.

37. What is the difference between synchronized and concurrent collections?


Synchronized collections are thread-safe but slower, while concurrent collections provide better
performance for multithreading.

38. What is a soft reference in Java?


A soft reference allows an object to be garbage collected only when memory is low.

39. What is a WeakHashMap?


WeakHashMap stores keys as weak references, allowing them to be garbage collected.

40. What is a fork/join framework?


The fork/join framework in Java is used for parallel processing by splitting tasks into subtasks.

41. What is the default size of a Java thread stack?


It depends on the JVM but is typically around 512KB to 1MB.

42. What is the difference between Callable and Runnable?


Runnable does not return a result, whereas Callable returns a value and can throw checked
exceptions.

43. What is the Executor framework?


The Executor framework provides a higher-level replacement for managing threads efficiently.

44. What is method reference in Java?


A method reference is a shorthand notation for calling methods using :: operator.

45. What is the diamond operator?


The diamond operator (<>) allows type inference for generic instance creation.

46. What are record classes in Java?


Introduced in Java 14, records are immutable data classes with compact syntax.

47. What is a modular system in Java?


Java 9 introduced modules to encapsulate packages and manage dependencies better.
48. What is a var keyword?
Introduced in Java 10, var allows local variable type inference.

49. What is GraalVM?


GraalVM is a high-performance runtime for executing Java applications efficiently.

50. What is the difference between Spring and Hibernate?


Spring is a framework for enterprise applications, while Hibernate is an ORM tool for database
interaction.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy