Introduction: Why Java Doesn't Forgive Sloppiness
\n\nYou sent your resume, passed the HR screening, and here it is — an invitation to a technical interview. If you are reading this article on pythonlib.ru, it means you are either switching from Python to Java, or simply gathering a "knowledge base." In any case — you are on the right track.
\n\nJava is not a language where you can "slide through" on charisma. The enterprise ecosystem requires a clear understanding: from JMM (Java Memory Model) to how the Garbage Collector works. A Java interview is not an exam, it's a dialogue. But a dialogue where your strength will be tested.
\n\nIn this article, I have compiled a real checklist: what to study, how to answer, and — most importantly — how not to embarrass yourself during live coding. No fluff, just practice.
\n\n1. Java Core: The Foundation You Need to Know by Heart
\n\nLet's start with the basics. Without Java Core, no one will even listen to you. Here is a list of topics every candidate must know:
\n\n1.1. OOP (Object-Oriented Programming)
\nYou must be able to explain polymorphism, inheritance, encapsulation, and abstraction simply, with examples.
\n\nTrick question: "What is the difference between an abstract class and an interface?"
\nCorrect answer: In Java 8+, interfaces can have default methods, but an abstract class can contain state (fields), while an interface cannot.
\n\n// Example: abstract class\nabstract class Animal {\n protected String name;\n abstract void makeSound();\n}\n\n// Interface with default method\ninterface Movable {\n default void move() {\n System.out.println("Moving...");\n }\n}\n\n1.2. Collections (Java Collections Framework)
\nThis is a must-have. Knowing HashMap, ArrayList, HashSet, TreeMap is not enough. You need to understand:
\n- \n
- How HashMap works (array + linked list + red-black tree since Java 8) \n
- The difference between fail-fast and fail-safe iterators \n
- When to use LinkedList instead of ArrayList (spoiler: almost never) \n
Tip: During an interview, you might be asked to write your own implementation of HashMap. Practice beforehand.
\n\n1.3. Exceptions
\nChecked vs Unchecked — a classic. Remember: RuntimeException and its subclasses are unchecked, everything else is checked. And never, I mean never, use catch (Exception e) {} — it's an anti-pattern.
2. Multithreading: The Topic Where 80% of Candidates Fail
\n\nJava is one of the few languages where multithreading is built into the language level. During an interview, you will definitely be asked about synchronized, volatile, AtomicInteger, Lock, Semaphore.
\n\n2.1. The volatile Keyword
\nThe main question: "Does volatile guarantee atomicity?" Answer: No. It only guarantees visibility of changes between threads.
\n\npublic class VolatileExample {\n private volatile boolean flag = true;\n\n public void stop() {\n flag = false; // Another thread will see this change immediately\n }\n}\n\n2.2. Deadlock and How to Avoid It
\nYou may be asked to write code that leads to a deadlock, and then fix it.
\n\n// Classic deadlock\npublic class DeadlockExample {\n private final Object lock1 = new Object();\n private final Object lock2 = new Object();\n\n public void method1() {\n synchronized (lock1) {\n synchronized (lock2) { /* ... */ }\n }\n }\n\n public void method2() {\n synchronized (lock2) {\n synchronized (lock1) { /* ... */ }\n }\n }\n}\n\nSolution: always acquire locks in the same order, or use tryLock() from the java.util.concurrent.locks package.