Home > DeveloperSection > Articles > Phases of Java Program Execution (Part-1)

Phases of Java Program Execution (Part-1)

Java Java  Software Development 
1 Comment(s)
 515  View(s)
Rate this:

Phases of Java Program Execution (Part-1) 

A simple Java Program normally undergoes following five key steps:

·         Create and Edit

·         Compile

·         Load

·         Verify

·         Execute

Let’s examine these phase (in detail) in the context of the Java SE Development Kit (JDK).

Phase 1: Create and Edit

In Phase 1, we create and edit a file with the help of an editor program, normally known simply as an editor, or a text editor will also work. We type a Java program (typically referred to as source code) using the editor, make all necessary corrections and  we save this program/code on a secondary storage device, such as our hard drive. A file name ending with the .java extension indicates that the file contains Java source code.

Two editors widely used on Linux systems are vi and emacs. On Windows platform, Notepad will suffice. For organizations that develop substantial information systems, professionals prefer integrated development environments (IDEs), which are available from various major software vendors. IDEs provide tools that makes the work easy for us by supporting the software development process, including editors for writing and editing programs and debuggers for  debugging and locating logic errors—errors that cause programs to execute incorrectly. Popular Java based IDEs include Eclipse,InteliJ and NetBeans.

Phase 2: Compiling a Java Program into Bytecodes

In Phase 2, we use the command javac (the Java compiler) to compile a program. For example, to compile a program called MindStick.java, we would type:

javac MindStick.java

in the command window of our system (i.e., the Command Prompt cmd in Windows, the shell prompt in Linux or the Terminal application in Mac OS X). If this program compiles, the compiler produces a .class file called MindStick.class that contains the compiled version of this program.

The Java compiler translates Java source code into bytecodes that represent the tasks to execute in the execution step (Phase 5). Bytecodes are executed on the Java Virtual Machine (JVM)—a  crucial part of the JDK which lays the foundation of the Java platform. A virtual machine (VM) is a software application that simulates a computer system but hides the underlying operating system (OS) and hardware from the programs that interact with it. If the same VM is implemented on several computer platforms, same applications that it executes can be used on all those platforms. The JVM is one of the most widely used virtual machines. Even, Microsoft’s .NET uses similar virtual-machine architecture.

Unlike machine language, that is dependent on a particular computer hardware, these bytecodes are platform independent—they do not depend on a particular hardware platform.

So that’s why, Java’s bytecodes are portable—without recompiling the source code, the same bytecodes can be execute on any platform containing a JVM that understands the version of Java in which the bytecodes were compiled. The JVM is invoked by the java command. For instance, to execute a Java application called MindStick, we would type the command

java MindStick

in a command window to invoke the JVM  which would then initiate the processes necessary to execute the application. This begins Phase 3.

Phase 3: Loading a Program into Memory

In Phase 3, the JVM places the program in memory to execute it—this is known as loading. The JVM’s class loader takes the .class files containing the program’s bytecodes and transfers them to primary memory. The class loader also loads any of the .class files provided by Java that our program uses. The .class files can be loaded from a disk on our system or over a network (e.g., our local college or company network, or the Internet).Now this phase  led us to verification phase, which we will see in the next part.

Great post

By Sunil Singh on   2 months ago
Thanks man a great post,loved it.

Don't want to miss updates? Please click the below button!

Follow MindStick