Understand Java Environment

Java programs normally go through five phases to be executed are: edit,
compile, load, verify and execute as given in the figure below.

Phase 1 consists of editing a file. The programmer types a Java program, using the editor and saves the program in hard disk with “ filename.java ” extension.

In Phase 2 programmer gives the command javac to compile the program. The Java compiler translates the Java program into byte codes—the language understood by the Java interpreter.
E.g. Program is saved as Hello.java “
It should be compiled as ” javac Hello.java ” .
If the program compiles correctly, the compiler produces a file called ” Hello.class “.

Phase 3 is called loading. The program must first be placed in memory before it can be
executed. This is done by the class loader, which takes the .class file (or files) containing
the bytecodes and transfers it to memory. There are two types of programs for which the class loader loads .class files— applications and applets.

Applications are loaded into memory and executed by using the Java interpreter via
the command java. When executing a Java application called Hello, the command
” java Hello “ invokes the interpreter for the Hello application and causes the class loader to load information used in the Hello program.

The class loader also executes when a World Wide Web browser such as Netscape
Navigator or Microsoft Internet Explorer loads a Java applet.HTML describes the format of a document in a manner that is understood by the browser application. An HTML document may refer to a Java applet.When the browser sees an applet referenced in an HTML document, the browser launches the Java class loader to load the applet.

After the applet loads, the browser’s Java interpreter executes the applet. Like Mozilla Firefox and Microsoft Internet Explorer, the appletviewer requires an HTML document to invoke an applet. For example, if the Hello.html file refers to the Hello applet, the appletviewer
command is used as follows: appletviewer Hello.html
This causes the class loader to load the information used in the Hello applet. The appletviewer
is a minimal browser—it knows only how to interpret references to appletsand ignores all other HTML in a document.

Phase 4 – Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions.

Finally, in Phase 5, the computer, under the control of its CPU, interprets the program one bytecode at a time, thus performing the actions specified by the program.

Advertisements

What do you think? Please reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s