Getting ready for a Java interview? This page is made to help you with that. Here, you’ll find a list of the most common Java interview questions. These questions test your understanding of Java basics like classes and objects, as well as advanced ideas like multithreading, exception handling, and collections.
Each question is explained in simple terms so you can learn faster. Whether you’re new to Java or already have some experience, this guide can help you improve your skills and feel ready for your interview.
Use this time to review key concepts and write your own answers. Practice makes perfect, and going over these questions will help you stay calm and confident in your interview. With effort and the right preparation, you’ll be ready to impress any employer.
- Thread is a class. It is used to create a thread. While, Runnable is a functional interface which is used to create a thread.
- Thread has multiple methods including start() and run(). Whereas, Runnable has only abstract method run().
- Thread requires more memory. In contrast, Runnable interface requires less memory.
- When the objects of the class are still reachable;
- The class object represents that class is still reachable;
- The ClassLoader that has loaded the class is still reachable;
- And when other classes loaded by the ClassLoader are still reachable.
- A factory pattern is a single method, while an abstract factory is an object.
- The level of abstraction for an abstract factory pattern is one step higher than the factory pattern.
- The factory method pattern returns the common parent class, but the abstract factory pattern returns one of several factories.
- Java Sockets are flexible for general communication & easy to implement.
- Java Sockets causes low network traffic, unlike CGI scripts HTML forms that can generate the whole web page for each new request.
- HashMap is non-synchronized, but HashTable is synchronized and slower in performance.
- HashMap uses an iterator to traverse, while the HashTable uses an enumerator to traverse.
- The iterator in HashMap is fail-fast, but an enumerator in HashTable isn’t fail-fast.
- HashMap permits only one null key & null values, while Hashtable doesn’t allow any key or value as null.