Thursday, June 18, 2026

Phases of a Java Program

 

  Phase 1: Creating/editing a program

        The editing phase is the stage where the programmer writes the Java source code with editor.

        The following are some Java Integrated Development Environments (IDEs).

       Jbuilder, NetBeans , Sun ONE Studio, Eclipse, jEdit, Jcreator, BlueJ, jGRASP, etc.

       Most of this editors  can be downloaded for free.

       Any text editor can also be used for creating Java programs.

       The filename must match the public class name.

       Programs written on IDEs  or any other editors are known as Source Code.

       Java source code file names end with .java extension

Phase 2: Compiling Java Programs into Bytecodes

        Since a computer cannot understand a source program, program called a compiler is used to translate the source program into a machine language program called an object program.

        With Java, you write the program once, and compile the source program into a special type of object code, known as bytecode.

o   The Java compiler (javac) checks the code.

o   It detects syntax errors.

o   It converts .java file into .class file.

        To compile Java Program

o   Javac welcome.java

        To execute java programs

o   Java welcome

  • This .class file contains bytecode, not machine code.
  • If there are syntax errors, compilation fails.

 Phase 3: Loading a program

        A program must be placed in memory before it can execute : a process known as loading.

        The class loader takes/locates  the .class file (produced during compilation process) containing  the program’s bytecodes and  transform them to primary memory.

        The class loader also loads any of the .class files provided by java that your program uses.

        It prepares them for execution.;

        The .class files can be loaded from a disk on your system or over a network.

Phase 4 : Bytecode Verification

        Involves examining bytecodes to ensure that they are valid and do not violate Java’s security restriction.

        Java enforces strong security, to make sure that Java programs arriving over the network do not damage your files or your system (as computer viruses and worms might).

Phase 5: Execution: the program actually runs.

        The JVM executes the program’s bytecodes, thus performing the actions specified by the program.

        .class file is not final machine code yet. It is virtual machine code. JVM need a second compilation to convert virtual machine code to real machine code. We call it just-in-time compiler (JIT).

        This greatly affects the speed of the execution.

        Traditionally, our C/C++ program can finish all the compilation before execution. The generated machine code could run directly on OS or hardware.

 


No comments:

Post a Comment

2. 0 java Class

}   Class can be defined in multiple ways Ê   A class is a blueprint for an object. Ê   A class is a user-defined data type. Ê   A cla...