How to Pass a Java Interview: Top Questions from A to Z

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

How to Pass a Java Interview: Top Questions from A to Z



A Java developer interview is not just a test of syntax knowledge. The employer evaluates your understanding of fundamental principles, your ability to write clean code, and your capacity to solve real-world problems. In this article, we have compiled top Java questions that cover all key topics: from OOP basics to multithreading and frameworks. The article is suitable for both Junior and Middle developers.



We have broken the material into logical blocks so you can prepare systematically. Each question is accompanied by a brief answer and a Java code example. Prepare for your interview with PythonLib!



1. Java Basics and OOP (Object-Oriented Programming)



1.1. What OOP principles are implemented in Java?

Java supports four main OOP principles: inheritance (extends/implements), polymorphism (method overloading and overriding), encapsulation (private fields + getters/setters), and abstraction (abstract class/interface).



// Example of encapsulationpublic class User {    private String name;

public String getName() { return name; }

public void setName(String name) { this.name = name; }}


1.2. How does an abstract class differ from an interface?

Before Java 8: an abstract class can contain implemented methods and fields, an interface — only abstract methods and constants. After Java 8, default and static methods appeared in interfaces. Key difference: a class can implement multiple interfaces but inherit only one abstract class.



1.3. What is method overloading and overriding?

  • Overloading: methods with the same name but different parameters (compile-time).
  • Overriding: a child class changes the implementation of a parent method (runtime).


// Overloadingclass Calculator {    int sum(int a, int b) { return a + b; }    double sum(double a, double b) { return a + b; }}

// Overridingclass Animal { void sound() { System.out.println("Some sound"); }}class Dog extends Animal { @Override void sound() { System.out.println("Bark"); }}


2. Java Collections Framework



2.1. Name the main implementations of List, Set, and Map.

  • List: ArrayList (fast index access), LinkedList (fast insertion/deletion).
  • Set: HashSet (based on HashMap, no order guarantee), TreeSet (sorted), LinkedHashSet (maintains insertion order).
  • Map: HashMap (fast access, null keys), TreeMap (sorted by key), LinkedHashMap (insertion order).


2.2. How does HashMap work?

HashMap uses an array of buckets and a hash function. When inserting a key, its hashCode is calculated, then the bucket index is determined. If the bucket already has elements (collision), a linked list or a red-black tree is used (if elements > 8). The default initial capacity is 16, the load factor is 0.75.



Map<String, Integer> map = new HashMap<>();map.put("Java", 1);map.put("Python", 2);System.out.println(map.get("Java")); // 1


2.3. How does ArrayList differ from LinkedList?

ArrayList is based on a dynamic array, LinkedList is based on a doubly linked list. ArrayList is faster for index access (O(1) vs O(n)), but slower for insertion/deletion in the middle (O(n) vs O(1)). LinkedList requires more memory due to storing references.



3. Multithreading and Concurrency



3.1. What ways to create threads exist in Java?

  • Inheriting from the Thread class and overriding

Blogs

Book Recommendations