Updated Java interview questions 2022
Java interview questions for freshers as well as experienced
This is a well-written companion for your interview. This contains various topics in Java Technology such as exception handling, String Handling, OOPS Concepts
Topic
Questions
1. What is the current version of java?
2. What is the difference between interface and abstract class in Java?
3. What is method overriding and method overloading in Java
4. What is the Exception handling mechanism available in Java
5. What is meant by the OOPS Concepts?
6. What is meant by inheritance
8. Can we inherit a final method from super class in Java
9. How to prevent the subclass getting inherited the superclass methods?
10. What is a UML diagram? Which one are you familiar with?
11. What are the new features provided by Java8?
12. Do you know collection classes in Java?
13. What is difference between String Buffer and String Builder?
14. What are the collection libraries you are familiar with?
15. How to print contents of an Array List using Stream API?
16. How to retrieve the contents of an Array List?
18. What is the superclass of any class?
19. What are the methods available in the Object class?
20. How to retrieve a value from a HashMap?
21. What is meant by design pattern?
22. What is a Singleton Design Pattern?
23. What are the design patterns you are familiar with?
24. What is meant by Null Pointer Exception? How you avoid them?
25. How can you avoid unchecked exceptions?
26. Can you write a code to print the content of the Array list using steam API
27. Can you write a code to declare a HashMap and print its contents?
28. How do you inherit class A to class B, which keyword do you use?
All Questions
1. What is the current version of java?
Topic: core-java
Answer:
Java 19
Java has the following version and history
Java 8
Java 11
Java 17
Java 18
Java 19
Complexity: beginner
2. What is the difference between interface and abstract class in Java?
Topic: core-java
Answer:
Complexity: beginner
3. What is method overriding and method overloading in Java
Topic: core-java
Answer:
Complexity: beginner
4. What is the Exception handling mechanism available in Java
Topic: core-java
Answer:
Complexity: beginner
5. What is meant by the OOPS Concepts?
Topic: core-java
Answer:
Complexity: beginner
6. What is meant by inheritance
Topic: core-java
Answer:
Complexity: beginner
7. What is a final class?
Topic: core-java
Answer:
Complexity: beginner
8. Can we inherit a final method from super class in Java
Topic: core-java
Answer:
Complexity: beginner
9. How to prevent the subclass getting inherited the superclass methods?
Topic: core-java
Answer:
Complexity: beginner
10. What is a UML diagram? Which one are you familiar with?
Topic: core-java
Answer:
Complexity: beginner
11. What are the new features provided by Java8?
Topic: core-java
Answer:
Complexity: beginner
12. Do you know collection classes in Java?
Topic: core-java
Answer:
Collection is the way to store multiple items in a single unit.
Complexity: beginner
13. What is difference between String Buffer and String Builder?
Topic: core-java
Answer:
Complexity: beginner
14. What are the collection libraries you are familiar with?
Topic: core-java
Answer:
Complexity: beginner
15. How to print contents of an Array List using Stream API?
Topic: programming
Answer:
We can print the contents of an ArrayList, See the code below
import java.io.*; import java.util.*; public class TestClass { public static void main(String[] args) { ArrayList<String> arrList= new ArrayList(); arrList.add("India"); arrList.add("Brazil");
arrList.add("Peru");
arrList.stream().forEach(System.out::println); } }
Complexity: beginner
16. How to retrieve the contents of an Array List?
Topic: core-java
Answer:
Complexity: beginner
17. What is a HashMap?
Topic: core-java
Answer:
Complexity: beginner
18. What is the superclass of any class?
Topic: oops-concepts
Answer:
Object class is the superclass of all classes in Java.
Complexity: beginner
19. What are the methods available in the Object class?
Topic: core-java
Answer:
Complexity: beginner
20. How to retrieve a value from a HashMap?
Topic: core-java
Answer:
Complexity: beginner
21. What is meant by design pattern?
Topic: core-java
Answer:
Complexity: beginner
22. What is a Singleton Design Pattern?
Topic: core-java
Answer:
Complexity: beginner
23. What are the design patterns you are familiar with?
Topic: core-java
Answer:
Complexity: beginner
24. What is meant by Null Pointer Exception? How you avoid them?
Topic: core-java
Answer:
Complexity: beginner
25. How can you avoid unchecked exceptions?
Topic: core-java
Answer:
Complexity: beginner
26. Can you write a code to print the content of the Array list using steam API
Topic: core-java
Answer:
Complexity: beginner
27. Can you write a code to declare a HashMap and print its contents?
Topic: core-java
Answer:
Complexity: beginner
28. How do you inherit class A to class B, which keyword do you use?
Topic: core-java
Answer:
Complexity: beginner
29. What are the differences between Checked Exception Vs Unchecked Exception?
Topic: exception-handling
Answer:
Complexity: beginner
30. Can you write a code to declare an array list and print its contents?
Topic: programming
Answer:
Complexity: beginner
31. What is the difference between List and Set in Java
Topic: collection
Answer:
Complexity: beginner
32. Which one is faster List or Set
Topic: collection
Answer:
Complexity: intermediate
33. How to sort an array list with stream.sorted() in Java 8
Topic: collection
Answer:
In this post, we will discuss how to sort a ArrayList
with steam API. We consider normal List<String> and List of the custom object in the example.
Complexity: intermediate
34. How to sort an array list of custom object with stream.sorted() in Java 8
Topic: collection
Answer:
Sorting using stream required very less coding. see the sample below
List<CompanyTableEntity> companyTableEntities = companies.stream().sorted(Comparator.comparing(CompanyTableEntity::getName)).collect(Collectors.toList());
If you watch closely the sorted method in the stream API does the task, and The stream is running on the first list. There is a comparator defined inside the sorted method that defines on what basis the Company object needs to sort. Once sorted it is collected as a list and passed back to a new list
Complexity: intermediate