AlgoInsight

Free lesson · Java Basic To Advance

Features of Java

Easy7 min readjava

The Features That Define Java

Every Java textbook lists "features of Java" — a checklist of buzzwords like "platform-independent," "object-oriented," "robust." The checklist is correct but unhelpful unless you understand what each feature actually means and why it matters.

This Topic goes through the major features of Java with real explanations. By the end, you should be able to answer the interview question "what are Java's main features?" with substance rather than a memorized list.

Platform Independence

Interactive animation: Platform independence in two numbers - one compile step, then zero recompiles when the code moves to another platform.

We've touched on this in Topics 1.1 and 1.2. The mechanism: Java source compiles to bytecode, and that bytecode runs on any JVM. The same .class file works on Windows, macOS, Linux, embedded systems, cloud containers — anywhere a compatible JVM exists.

The practical implication: a Java application built on a developer's macOS laptop can be deployed to Linux servers in production without recompilation. The same JAR file works in both places. This is a real advantage for cross-platform development teams and for cloud deployments where the production OS may differ from development.

The trade-off: there's a runtime layer (the JVM) between your code and the hardware. This adds startup time and some memory overhead compared to natively compiled languages like Go or Rust. For long-running server applications, the trade-off is usually worth it. For short-lived command-line tools, native compilation is often preferred.

Object-Oriented

Java is one of the most consistently object-oriented languages in mainstream use. Almost everything in Java is an object — strings, collections, threads, even type information at runtime. The exceptions are the eight primitive types (int, long, double, boolean, char, byte, short, float), which exist for performance reasons but have corresponding object wrapper classes (Integer, Long, etc.).

The object-oriented model includes:

We cover each of these in depth in Modules 7-11. The key point at this stage: Java's OO model is conservative and predictable. There's no multiple inheritance of classes (unlike C++). There's no operator overloading (unlike C++ or Python). There are no "friend" relationships between classes. These restrictions make Java code easier to read but require more boilerplate than less-restrictive languages.

Interactive animation: What Java's object model has beside what it refuses - multiple inheritance of classes, operator overloading and friend access.

Strong Static Typing

Every variable in Java has a type, declared explicitly or inferred via var. Types are checked at compile time. Code that tries to use a value as the wrong type fails to compile.

String name = "Olena";
int count = name;  // Compile error: incompatible types

List<Integer> numbers = new ArrayList<>();
numbers.add("hello");  // Compile error: requires Integer

This catches a huge class of bugs before the program runs. Dynamic languages like Python or JavaScript would let the equivalent code compile and only fail at runtime — possibly only on a specific input that exercises the buggy code path.

Java's type system also supports generics (covered in Module 15) for parameterized types. List<Integer> means "a list whose elements are integers." The compiler enforces this throughout the code.

Modern Java (since Java 10) supports var for local type inference:

var users = new ArrayList<User>();  // type is inferred as ArrayList<User>
var name = "Olena";                  // type is inferred as String

This reduces boilerplate without sacrificing type safety. The compiler still knows the exact type; you just don't have to write it.

Interactive animation: Two lines that never run - a String into an int, and into a List<Integer>, both fail to compile.

Automatic Memory Management (Garbage Collection)

Java was one of the first mainstream languages with automatic memory management. You don't malloc and free, you don't new and delete — you just create objects, and the garbage collector reclaims them when they're no longer reachable.

public void example() {
    List<String> temp = new ArrayList<>();
    temp.add("hello");
    // 'temp' goes out of scope when method returns
    // The garbage collector will eventually reclaim its memory
}

The benefits:

The trade-offs:

We cover memory management in detail in Module 19. The key point now: Java's GC makes development faster and safer at the cost of some performance predictability.

graph TD
    A[New object created] --> B[Lives in heap]
    B -->|still referenced| C[Survives GC cycles]
    B -->|no references| D[Garbage]
    D --> E[GC reclaims memory]
    C -->|long-lived| F[Promoted to old generation]
    F -->|eventually unreferenced| D

    style B fill:#10b981,color:#fff
    style D fill:#dc2626,color:#fff
    style E fill:#3b82f6,color:#fff
This diagram shows the lifecycle of a Java object in memory. When you create a new object, it's allocated on the heap. If something references it, it survives garbage collection cycles. If nothing references it, it becomes garbage — the GC eventually identifies it and reclaims its memory. Long-lived objects that survive many GC cycles get promoted to the "old generation" of the heap, where collection happens less frequently. Eventually even old-generation objects become unreachable and are reclaimed. You never explicitly free memory in Java; the GC handles it.

Multithreading and Concurrency

Java has built-in support for multithreaded programming. The language defines a memory model that specifies how threads interact through shared memory. The standard library provides extensive concurrency primitives:

Few mainstream languages have concurrency as built-in to the platform as Java. C++ added comparable primitives later. Python's concurrency story is famously complicated (GIL). Go's concurrency model is elegant but different. JavaScript is single-threaded.

This is a real differentiator: Java is a strong choice for backend services that need to handle many concurrent requests. We cover concurrency comprehensively in Module 18.

Security

Java was designed with security as a first-class concern, originally to safely run "applets" — untrusted code downloaded from websites — in the browser. While applets are long dead, the security mechanisms remain.

Key security features:

Bytecode verification. Before executing bytecode, the JVM verifies it doesn't violate type safety, doesn't access memory it shouldn't, doesn't underflow or overflow the stack. Malformed bytecode is rejected.

No pointer arithmetic. Java doesn't have C-style pointers. You can't index into memory, calculate addresses, or escape array bounds. Buffer overflow attacks — common in C/C++ — are essentially impossible in pure Java.

Sandboxing capability. The JVM supports running untrusted code with restricted permissions. This is rarely used today (since applets are dead) but the capability exists.

Strong cryptography support. The standard library includes JCA (Java Cryptography Architecture) and JCE (Java Cryptography Extension) with widely-used implementations of standard algorithms.

For interview purposes: Java's security model is mostly relevant historically and as background. Modern enterprise security usually comes from frameworks (Spring Security) rather than the language itself.

Backwards Compatibility

We covered this in Topic 1.2. The summary: Java's commitment to backwards compatibility is unusually strong. Code from 1996 still mostly works on Java 21. This is a real advantage for enterprises and a real constraint on language evolution.

Comprehensive Standard Library

Java's standard library is unusually comprehensive. Most languages require third-party libraries for common tasks. In Java, you often don't:

The standard library is what makes Java productive without dependency hell. Production codebases still use frameworks (Spring, Hibernate, etc.) for ergonomics and structure, but the foundation underneath is solid and stable.

Performance

Java's performance reputation has improved dramatically since the 1990s when "Java is slow" was a common refrain. Modern JVMs with JIT compilation produce code that's competitive with native-compiled languages for most workloads.

Specifically:

For server applications running for hours or days, Java performance is excellent. For short-lived CLI tools, the JVM startup overhead matters more than peak performance.

GraalVM Native Image can compile Java to native binaries with fast startup, at the cost of losing JIT optimization for long runs. This is increasingly popular for serverless deployments and CLI tools.

Interactive animation: Performance, honestly - JIT-compiled hot code runs within 1.5-2x of C++, while startup still dominates short-lived tools.

Common Pitfalls

Warning: Treating "features of Java" as a memorized list. Interviews probe whether you understand what features mean, not whether you can recite them. "Platform independence" means bytecode + JVM, not just "Java works everywhere."

Confusing Java's features with JVM features. Some "Java features" (JIT compilation, garbage collection) are JVM features that apply to any JVM language. Others (generics, lambdas) are language features specific to Java. Knowing which is which signals depth.

Overestimating "write once, run anywhere." The slogan is mostly true but has edge cases: file system paths differ between OSes, native libraries are platform-specific, and some features (POSIX file operations) only work on Unix-like systems. Pure Java code is portable; code that interacts with the OS may not be.

Why This Matters in Interviews

Interview: "What are the main features of Java?" is the most common follow-up to "What is Java?" The senior answer goes beyond the buzzword list. Pick three or four features and explain them at depth: platform independence (the bytecode/JVM mechanism), strong static typing (compile-time safety, generics), automatic memory management (GC trade-offs), and either concurrency or backwards compatibility. Quality over quantity.

Topic 26.12 has the full senior-candidate answer with example phrasing.

Try It

Exercise: Write down, without looking, three features of Java and one sentence explaining each. Then check your explanations against this Topic.

Do this exercise again in a week, after Module 1 is complete. The features you struggle to explain are the ones to study harder before interviewing.

Back to Java Basic To Advance