Features of Java

Naveen AnamaneniUpdated · 7 min read

Imagine you are building the server for a UPI payment app. It must run for months without crashing, handle thousands of payments at the same time, and never let one bug corrupt someone's account balance. It may also need to move from one cloud server to another without being rewritten.

Each of these needs maps to a Java feature: robustness, multithreading, security and platform independence. "What are the features of Java?" is also one of the most common Java interview questions, so it's worth knowing them well.

The Features at a Glance

Ten features, and what each one gives you
FeatureWhat it means for you
SimpleThe syntax is familiar if you have seen C or C++, but risky parts such as pointer arithmetic were left out.
Object-orientedYou organize code into classes and objects that model real things, such as Account or Payment.
Platform independentjavac produces bytecode, and any computer with a JVM can run it.
PortableThe size of int is always 32 bits, on every computer, so your program behaves the same everywhere.
RobustStrong type checking, automatic memory management and exception handling catch or prevent many bugs.
SecureNo direct memory pointers, array bounds checks, and a bytecode verifier that checks code before the JVM runs it.
MultithreadedOne program can do several tasks at the same time, for example serving many users at once.
High performanceThe JIT compiler turns frequently used bytecode into fast machine code while the program runs.
DistributedThe standard library has built-in support for networking and calling services over the internet.
DynamicClasses are loaded when they are needed, so programs can grow and be extended at runtime.

You'll study most of these in detail later. Here, let's look closely at the three that come up most often.

Platform Independent

Your Java code is compiled into bytecode, not into machine code for one processor. Each operating system has its own JVM that runs that same bytecode. So a program compiled on a Windows laptop runs on a Linux server without being recompiled. You saw this in the lesson "What Is Java".

Object-Oriented

In Java, almost everything you write lives inside a class. A class is a blueprint, and an object is a thing made from that blueprint. For example, an Account class can describe every bank account, and each customer's account is an object. Level 2 of this course covers object-oriented programming in depth.

Java isn't purely object-oriented, because simple values like int and boolean are not objects. Interviewers like to ask about this.

Robust and Secure

Many languages let a program read memory it doesn't own, which can crash the program or leak data. Java doesn't allow that. For example, every time you read from an array, Java checks that the position actually exists.

This program has three scores but tries to read a fourth.

SafeArray.java▶ Try it
public class SafeArray {
    public static void main(String[] args) {
        int[] scores = {78, 92, 85};
        System.out.println("First score: " + scores[0]);
 
        try {
            System.out.println("Fourth score: " + scores[3]);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Stopped safely: " + e.getMessage());
        }
    }
}
Output
First score: 78
Stopped safely: Index 3 out of bounds for length 3

How it works

  1. Line 3 creates an array with three scores. Their positions are 0, 1 and 2.
  2. Line 4 prints the first score, at position 0.
  3. Line 7 asks for position 3, which doesn't exist. Java checks this and throws an ArrayIndexOutOfBoundsException instead of reading random memory.
  4. The try and catch lines catch that exception and print a clear message. You'll learn exceptions properly later in the course.

In a language without this check, the same mistake could silently read whatever happens to be in memory next to the array.

Try it yourself: change scores[3] on line 7 to scores[2]. Which line prints now, and why doesn't the catch part run?

Common Mistakes

Saying Java is 100% object-oriented. Primitive types such as int, double and boolean are not objects, so Java is not purely object-oriented. Say "Java is an object-oriented language" instead.

Thinking "platform independent" means Java needs nothing installed. A Java program still needs a JVM on the computer that runs it. The bytecode is platform independent; the JVM is not.

Thinking Java is slow. Early Java (in the 1990s) was slow because it only interpreted bytecode. Modern JVMs use a JIT compiler, and well-written Java is fast enough for stock exchanges and large payment systems.

Interview Corner

What are the main features of Java?

Simple, object-oriented, platform independent, portable, robust, secure, multithreaded, high performance (thanks to the JIT compiler), distributed and dynamic. If you have time, explain platform independence with bytecode and the JVM, because that is the feature interviewers care about most.

Why is Java called robust?

Because it catches many errors early and prevents others: strict type checking at compile time, array bounds checks at runtime, exception handling, and automatic memory management through the garbage collector, so there are no manual memory bugs.

Is Java a purely object-oriented language?

No. Java has primitive types such as int, char and boolean, which are not objects, and it has static members that belong to a class rather than an object.

How is Java fast if it runs bytecode?

The JVM's JIT (just-in-time) compiler watches which code runs often and compiles it into optimized machine code while the program runs.

Practice

  1. Easy: Pick any three features from the table and explain each one in one sentence, using an example from a food delivery app.
  2. Harder: In SafeArray, add a fourth score to the array so that scores[3] works. Run it and write down the new output.

Quick check: Features of Java

4 questions
1Which feature lets one compiled Java program run on Windows, macOS and Linux?
2What happens when a Java program reads an array position that doesn't exist?
3Why is Java not purely object-oriented?
4Which part of the JVM makes Java fast at runtime?

Key Takeaways

Was this tutorial helpful?

Lesson 3 of 482