Properties of Java

Java compiles to bytecode that any JVM can run, which is why one program travels to every machine: write once, run anywhere, plus the classic exam list of Java's properties.

9 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

The program that would not travel

In BCA104 you compiled a C program in the college lab. It ran perfectly there. You copied it to your friend's laptop and it refused to start: the compiled file spoke the lab machine's language, not the laptop's.

This semester you build BookBridge, a small library app. The librarian has an old Windows PC, your external examiner may run Linux, and you test on your own laptop. Rewriting or recompiling for every machine is exactly the pain Java was invented to remove.

Theory

The half-cooked meal kit

A C compiler serves a fully cooked dish: perfect for one specific table, useless anywhere else.

Java instead packs a meal kit: the recipe is pre-processed into a standard, half-finished form (bytecode), and every kitchen keeps a local chef (the JVM) who finishes it for that kitchen. Same kit, any kitchen. That is Java's famous promise: write once, run anywhere.

Theory

How the promise works

Java is platform-independent because compilation happens in 2 stages:

  • javac compiles your .java source into bytecode (a .class file), a standard instruction set that belongs to no real machine.
  • The JVM (Java Virtual Machine) on each computer reads that bytecode and executes it, translating to the local machine's instructions.

So one BookBridge.class file runs on Windows, Linux and macOS, as long as each has its own JVM installed.

At a glance

Properties of Java (the exam list)

PropertyWhat it means
SimpleC-family syntax minus pointers, operator overloading and other sharp edges
Object-orientedAll code lives inside classes; objects model the real world
Platform-independentBytecode + JVM give write once, run anywhere
PortableNo machine-dependent sizes: an int is 4 bytes everywhere
RobustGarbage collection, exception handling, strict compile-time checks
SecureNo direct memory access; the JVM verifies bytecode before running it
MultithreadedOne program can do several tasks at once (Unit 4)
High-performanceThe JIT compiler turns hot bytecode into native code while running

Quiz

Why exactly is Java called platform-independent?

  1. javac compiles source into bytecode, and any platform's JVM can execute that same bytecode
  2. The compiler produces a separate native .exe for each operating system
  3. Java programs run directly from source code without any compilation
  4. Java has no pointers, so programs cannot depend on the machine
Show the answer

javac compiles source into bytecode, and any platform's JVM can execute that same bytecode

The whole trick is the 2-stage design: one universal bytecode file, executed by a per-platform JVM. Option B describes cross-compiling in languages like C, the opposite approach. Option C describes a purely interpreted language, but Java IS compiled (to bytecode). Option D is a true fact about Java yet has nothing to do with platform independence; exams love this true-fact-wrong-reason trap.

Theory

Robust and secure, concretely

Two properties deserve more than one line in an answer.

Robust: in C, a stray pointer can silently corrupt memory. Java removes pointers, frees memory automatically (garbage collection), and forces you to face errors through exceptions (Unit 3). Programs fail loudly and early instead of mysteriously.

Secure: bytecode passes through a verifier before the JVM runs it, and code cannot touch raw memory addresses. That is why banks and Android apps trusted Java for decades.

Think first

Compare it with C

In BCA104, compiling marks.c produced a file only that machine type could run. Before tapping: what does compiling BookBridge.java produce, and what runs it?

Show the answer

It produces BookBridge.class, a bytecode file tied to no real machine. A JVM runs it: the Windows JVM on the librarian's PC, the Linux JVM on the examiner's laptop, each translating the same bytecode for its own hardware. C's output was the finished native program; Java's output is the universal middle step.

Watch out

The mark-losing sentence

Students write "the JVM is platform-independent". Wrong, and it costs the mark.

The bytecode is platform-independent; the JVM is platform-specific (there is a separate JVM build for Windows, Linux, macOS). Write it as: Java achieves platform independence because platform-independent bytecode runs on a platform-specific JVM. That one sentence shows the examiner you understand the machinery.

Theory

You have already met Java

In BCA305-02 you wrote Java to build Android screens, so the syntax is not new. This subject goes underneath: WHY the language behaves that way, proper OOP (Unit 2), Strings and exceptions (Unit 3), threads (Unit 4) and hand-built linked lists (Unit 5), all inside BookBridge. And keep BCA304's C++ in mind: half the exam comparisons are Java vs C++.

Summary

Key takeaways

  • Java compiles in 2 stages: javac turns source into bytecode (.class), and a JVM executes the bytecode on each machine.
  • Write once, run anywhere: one bytecode file runs wherever a JVM exists.
  • Bytecode is platform-independent; the JVM is platform-specific. Never swap those.
  • Exam list of properties: simple, object-oriented, platform-independent, portable, robust, secure, multithreaded, high-performance (JIT).
  • Robust = garbage collection + exceptions + strict checks; secure = bytecode verifier + no raw memory access.
  • Memory hook: the meal kit travels, the chef stays home.

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to Java

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Properties of Java · Java Programming Language · Gri-Learn