Skip to content

How Java Program Run | How Java Works & Compiler work

If you completed your First Java Hello world program then you must have to know how java work or How Java Program Runs internally? In this tutorial you will get detail about How java Program work and what are process step involved internally.

How Java Program Run, Java Works & Compiler work

The process Steps:

We are assuming, You completed a program and click on compile & run in IDE (if using an IDE), and output will show in the terminal. But this process from compile to show output process has gone through internally, you don’t have actually How in Java Environment its works? There are several steps involved let’s see, here we are sharing a How Java Program Run step by step.

  • Source Code – A file contains your programming code.
  • Compiler – Source code goes through the compiler.
  • Output – compiled the code with the class extension file name.
  • Virtual machine -A electronic gadget, execute bytecodes.

Java program execution flow diagram

How java program run

Start the exploration of every step – How Java works

Source Code

A program or application is coded in a file with extension .java is called source code. For example, writing a simple java hello world program in java.

The source file name is – Hello.java

public class Hello {
    public static void main(String[] args) {
 
        String str = "Hello World";
        System.out.println(str);
    }
}

Compiler 

A special kind of program read code statement and convert in machine language (bytecode). The compiler checks the error and shows it in the console until there zero errors in the program. If pass the error step then it’s built a file with dot class extension.

To test error (compile) in terminal use the command “javac Hello.java

For upper program source file, a new file will be Hello.class.

Output

As upper mentioned a bytecode file will be created which is our program output to ready a run in Virtual Machine

For run and see output hit this commend – Java Hello

Java Virtual machine

The Virtual machine read and run the bytecodes. A short form of it is JVM, which translates your Hello.class bytecode to purpose output and runs your program.

You don’t need to worry about JVM, it’s already in an electronic gadget which supports it.

This is how java internally work with compiler and executes, leave a comment if you have any doubt and suggestions.

Note: This example (Project) is developed in IntelliJ IDEA 2018.2.5 (Community Edition)
JRE: 11.0.1
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.1

Java version 11

Example of How Java Program Run are in Java 11, so it may change its different from Java 9 or 10 or upgraded versions.

1 thought on “How Java Program Run | How Java Works & Compiler work”

Leave a Reply

Your email address will not be published. Required fields are marked *