We have understood what Java is; now we should learn how Java works as a programming language as well as a framework. Java works in two steps

  • Step 1 – Write code in Java(English-like) language, then compile the code into a platform-independent intermediate language called bytecode
  • Step 2 – During code execution, the JVM interprets the bytecode to machine language

Let’s learn about some terms used in Java

  • JDK – Java Development Kit(JDK) is the tool/software required to compile and execute Java code
  • JVM – Java Virtual Machine(JVM) is system system-specific virtual machine, capable of producing machine code from platform-independent bytecode
  • JRE – Java Runtime Environment(JRE) is the combination of JVM and required libraries to execute a Java program. Kind of provide utensils, spices in the kitchen while cooking
  • javac – javac is the compiler that compiles Java code into bytecode
  • java – This is the Java interpreter responsible for executing bytecode into machine code inside the JVM with the help of other libraries

Let’s understand the process

1

Write code using Java programming language. It need to follow Java programming rules like having main method

2

Compile the code using javac, and as we know the outcome is bytecode. Also we need to understand, compilation is part of JDK

3

Compiled code is ready for execution in JRE using java. Inside JRE, JVM interprets bytecode into machine code with help of some other additional libraries. We need JVM in Development environment to compile Java code, but in for execution JRE is enough

4

So far I have been talking about a single Java file. But a software is made out of hundreds or thousands of classes. Mostly we use smart IDE to write all the required Java code

5

All the classes need to be compiled and packaged into a single file(archive) called Java Archive(jar) or Web Application Archive(war). And the jar or war file is executed to run the software

Once we know how Java works, let’s try writing a simple Java program and see what are different components of a basic Java program.