Java Interview Questions For Freshers
  1. What are the eight primitive data types in Java?
  2. How do you declare a variable in Java?
  3. How do you declare and use an array in Java?
  4. What is the difference between a class and an object in Java?
  5. How do you declare and use a method in Java?
  6. What is inheritance in Java and how is it used?
  7. What is polymorphism in Java and how is it used?
  8. How do you handle exceptions in Java?
  9. What is the difference between the "==" and ".equals()" operators in Java?
  10. What is the difference between primitive data types and reference types in Java?
  11. What is a method in Java and how is it used to encapsulate behavior and improve code reusability?
  12. What is a variable in Java and how is it used to store data and values?
  13. What are Java operators and how are they used to perform calculations and comparisons?
  14. What is a Java interface and how is it used to define a contract for implementing classes?
  15. What is a Java package and how is it used to organize related classes and interfaces?
  16. What is the difference between a while loop and a do-while loop in Java, and when should you use each one?
  17. What is a for-each loop in Java and how is it used to iterate over collections of data?
  18. What is the "this" keyword in Java, and how is it used to refer to the current object?
  19. What is the difference between a class and an object in Java, and how do you create and use objects in Java programs?
  20. What is a collection in Java?
  21. What is the difference between ArrayList and LinkedList?
  22. What is a generic class in Java? Give an example.
  23. How can you declare a generic method in Java?
  24. What is the difference between length() and charAt() methods in Java Strings?
  25. How do you concatenate two strings in Java?
  26. What is inheritance in Java? Give an example.
  27. What is the difference between extends and implements keywords in Java?
  28. How can you compare two strings in Java? What is the difference between == and .equals() methods?
  29. How can you convert a string to an integer in Java?
  30. What is an abstract class in Java? Give an example.
  31. What is a lambda expression in Java? Give an example.
  32. What is the difference between Predicate and Function functional interfaces in Java?
  33. What is an exception in Java? Give an example.
  34. How can you handle an exception in Java?
  35. What are the benefits of using multiple threads in a Java program?
Java Intermediate Interview Questions
  1. What are access modifiers in Java and how are they used?
  2. How do you declare and use an interface in Java?
  3. What is the difference between composition and inheritance in Java?
  4. What is the difference between method overloading and method overriding in Java?
  5. What is the difference between checked and unchecked exceptions in Java?
  6. How do you implement a generic class in Java?
  7. What is a superclass and subclass in Java inheritance?
  8. What is the difference between public, private, protected, and default access modifiers in Java?
  9. What is the "static" keyword in Java and how is it used?
  10. What is the difference between an abstract class and an interface in Java?
  11. How do you create and use a package in Java?
  12. What is a lambda expression in Java and how is it used?
  13. What is the difference between a thread and a process?
  14. How do you create a new thread in Java?
  15. What is the difference between static and instance variables in Java classes?
  16. What is the difference between composition and aggregation in Java, and how do you choose between them?
  17. What is the difference between interface and abstract class in Java?
  18. What are anonymous classes in Java, and how are they used to implement interfaces or extend classes without defining a new class?
  19. What is a thread in Java, and how is it used to perform concurrent and parallel operations in Java programs?
  20. What are the different types of exceptions in Java, and how do you handle them using try-catch-finally blocks?
  21. What is the difference between a checked and unchecked exception in Java, and how do you choose which one to use?
  22. What is a Java annotation, and how is it used to add metadata or behavior to Java code?
  23. What is the difference between a public, private, and protected field or method in Java, and how do you choose which one to use?
  24. What is the difference between the "==" and ".equals()" operators in Java, and how do you compare objects in Java?
  25. What is the difference between a shallow and a deep copy of an object in Java, and how do you implement each one?
  26. What is the difference between a stack and a queue data structure in Java, and how are they used to store and retrieve data?
  27. What is the difference between bounded and unbounded generics in Java?
  28. How can you use wildcards in Java generics?
  29. How can you use method references with lambda expressions in Java?
  30. How can you write a lambda expression with multiple parameters in Java?
  31. What is the difference between checked and unchecked exceptions in Java?
  32. How can you create a custom exception in Java?
  33. What is the difference between a Set and a List?
  34. How does a TreeMap differ from a HashMap?
  35. What is the difference between an open and a closed module?
  36. How do you use the requires and exports keywords in a module-info.java file?
Java Interview Questions For Experienced
  1. What is a regular expression in Java? Give an example of a regular expression.
  2. How can you efficiently reverse a string in Java?
  3. What is type erasure in Java generics? How can it affect your code?
  4. What is the difference between List<T> and List<?> in Java?
  5. How does the Java memory model work and what are some strategies for optimizing memory usage in Java?
  6. What is method overloading and overriding in Java inheritance? Give an example.
  7. What is diamond problem in Java inheritance? How can you resolve it?
  8. Can you explain the principles of the "Java Virtual Machine (JVM)" and how it executes Java code?
  9. How do you implement a custom Java class loader and what are some use cases for doing so?
  10. How does Java concurrency work and what are some common pitfalls to avoid when working with concurrent code?
  11. Can you explain the Java garbage collector in detail, including the different types of garbage collectors and their trade-offs?
  12. What is the Java Native Interface (JNI) and how can it be used to integrate Java with native code?
  13. Can you explain the differences between a Java "servlet" and a "JSP", and how they are typically used together in a web application?
  14. How can you use Java annotations to customize the behavior of your code, and what are some popular annotations that are commonly used in Java libraries and frameworks?
  15. Can you explain the principles of "dependency injection" and how it is implemented in popular Java frameworks like Spring and Guice?
  16. How do you use reflection in Java to examine and modify code at runtime, and what are some best practices and potential pitfalls to keep in mind when working with reflection?
  17. What is the difference between a thread and a process in Java?
  18. What is reflection in Java, and how is it used to inspect and manipulate Java code at runtime?
  19. What is a Stream in Java? How can you use it with lambda expressions?
  20. What is a Collector in Java? Give an example of how to use it with lambda expressions.
  21. What is the finally block in Java exception handling? Give an example.
  22. What is the difference between throw and throws keywords in Java exceptions?
  23. What is the difference between a synchronized collection and a concurrent collection?
  24. How does a ConcurrentHashMap work, and how is it different from a regular HashMap?
  25. How does the Java module system impact the classpath and reflection?
  26. What is a deadlock in Java, and how do you prevent it?
  27. How does the Java Executor framework work, and what are its benefits?