Skip to content
VJ Classes

One place to learn science, commerce, arts, computers and life skills

How can one program run on a Windows laptop, a Linux server and an Android phone without being rewritten? Java was designed to answer that question, and its answer, bytecode running on a virtual machine, is still the heart of the language.

One program, many machines

A program written in C is compiled into machine code for one kind of processor and one operating system. To run it somewhere else you compile it again, and often change the code too. In the early 1990s engineers at Sun Microsystems met this problem on a large scale. They wanted software for many kinds of devices, each with a different chip.

How Java solves it

Java adds a middle step. The Java compiler, javac, does not produce machine code. It produces bytecode, the instructions of an imaginary computer called the Java Virtual Machine (JVM). Every platform has its own JVM, a program that reads bytecode and carries it out on the real hardware. The same bytecode therefore runs wherever a JVM exists. Sun’s slogan for this was “write once, run anywhere”.

The journey is: Hello.java (source code) → javac → Hello.class (bytecode) → java → the JVM runs it.

Two more ideas help beginners. A just-in-time (JIT) compiler inside the JVM turns frequently used bytecode into machine code while the program runs, so Java is fast enough for large servers. A garbage collector frees memory that is no longer in use, so you never release memory by hand as you do with C’s free.

Three names are easy to confuse.

NameWhat it is
JVMThe virtual machine that runs bytecode
JREThe JVM plus the standard libraries needed to run programs
JDKThe JRE plus the developer tools, such as javac

You install the JDK, because you are a developer.

A short history

In 1991 a small team at Sun Microsystems, led by James Gosling, began work on a language for consumer electronics. It was first called Oak. Sun renamed it Java and introduced it in 1995, and the first full release, JDK 1.0, followed in early 1996. Web browsers of that time could run small Java programs called applets, which made the language famous. Later Java became a standard choice for server-side business software, and the first Android apps were written in it. Oracle Corporation bought Sun in 2010. Today Java is developed openly as OpenJDK, and a new version arrives every six months. Some versions, such as 17 and 21, are marked for long-term support (LTS).

Why learn Java

Java is strongly typed, so the compiler catches many mistakes before the program runs. It is object-oriented, which teaches you to organise large programs. It has a huge standard library, and unlike C it checks array limits while the program runs.

Following Hello.java through the system

  1. You write Hello.java in a text editor.
  2. javac Hello.java checks the code and writes Hello.class.
  3. java Hello starts a JVM, which loads Hello.class.
  4. The JVM runs the bytecode of main. Four instructions are enough for our first program: getstatic fetches System.out, ldc loads the text, invokevirtual calls println, and return ends the method.

You can see these instructions yourself by running javap -c Hello after compiling.

Java in Indian classrooms and careers

Java is a core subject in many BCA, MCA, B.Sc. IT and B.Tech courses in India. Many IT services companies, and the banks and insurers they serve, use Java for server-side software, so Java questions are common in campus placement tests and interviews.

Key points

  • Sun Microsystems introduced Java in 1995, and Oracle bought Sun in 2010.
  • javac compiles source code into bytecode, and a JVM on each platform runs it: “write once, run anywhere”.
  • The JIT compiler gives speed, and the garbage collector manages memory.
  • Install the JDK to develop; it contains the JRE and the JVM.
  • Java is strongly typed and object-oriented.