Java Language Basics
Java is a statically and strongly typed object-oriented language. Source is compiled not to native machine code but to portable bytecode that the Java Virtual Machine (JVM) runs on any platform — "write once, run anywhere". The JVM manages memory itself through garbage collection, so there are no raw pointers here, only references.
But Java is not a pure object language: alongside objects live primitives (int, char, boolean) that are not objects. This split between primitives and objects is exactly what produces most beginner traps — autoboxing, the Integer cache, the difference between == and equals(). The layers below take the language from its execution model down to those traps.
Topic map
- Key Java Features — compilation to bytecode, static typing, automatic memory management.
- The main Method — why the entry point is declared
public static void main(String[] args). - static vs Instance — class member vs object member; why a
staticmethod has nothis. - Class Initialization Order — static, then field initializers, then constructor; parent before child.
- Wrapper Classes — how
IntegerandDoublegive a primitive an object form for collections and generics. - Autoboxing — the hidden
valueOfandintValue,NullPointerExceptionwhen unboxingnull. - Integer Cache — why
==on wrappers is only true within the -128..127 range. - final vs finally vs finalize — three similarly spelled but unrelated concepts.
- Why Java Is Not Pure OO — primitives are not objects, and wrappers bridge the gap.
Common traps
| Mistake | Consequence |
|---|---|
| Assuming Java compiles to native machine code | Java compiles to portable bytecode that the JVM runs |
| Calling Java dynamically typed | Types are checked by the compiler before running, not at runtime |
Comparing Integer wrappers with == | Inside -128..127 the cache returns true, outside it false; use equals() |
Unboxing an Integer that is null | The hidden intValue() throws NullPointerException, it does not yield 0 |
Expecting a static block to run on every new | It runs once, when the class is loaded |
Confusing static and final | static is one shared copy, final forbids reassignment; the axes are independent |
Relying on finalize() for cleanup | It is deprecated and may never be called; use try-with-resources / Cleaner |
Interview relevance
Core language basics come up on almost every junior interview — but the check is your mental model, not recall: where data lives and when things run. A candidate who explains autoboxing as "the compiler inserts Integer.valueOf, which caches -128..127" stands out from "well, int becomes Integer".
Typical checks:
- How bytecode differs from machine code and what makes Java platform-independent.
- Why
mainis declaredpublic static voidand whatString[] argsis. - The difference between
staticand instance; why astaticmethod has nothis. - Initialization order: static → field initializers → constructor, parent before child.
- Primitives vs wrappers, autoboxing and its cost, the
Integercache and why==is unreliable.
Common wrong answer: "== compares wrapper values." That opens the discussion that == compares references, and the Integer cache makes the result sometimes-true and otherwise-false for equal numbers — and that wrapper values must be compared with equals().