Saturday, December 8, 2018

How to Execute a Java Program?

In this post you will understand how to execute a java program in step by step. The following are the step by step process to execution a Java Program.

  1. Whenever, a program is written in JAVA, the javac compiles it.
  2. The result of the JAVA compiler is the .class file or the bytecode and not the machine native code (unlike C compiler).
  3. The bytecode generated is a non-executable code and needs an interpreter to execute on a machine. This interpreter is the JVM and thus the Bytecode is executed by the JVM.
  4. And finally program runs to give the desired output.

Java program execution follows 5 majors steps:

Editor
Compile
Load
Verify
and Execute

1. Editor - Here the programmer uses a simple editor or a notepad application to write the java program and in the end give it a .java extension

2. Compile - In this step the programmer gives the javac command and the .java files are converted into bytecode which is the language understood by the java virtual machine (and this is what makes java platform independent language). Any compile time errors are raised at this step

3. Load - The program is then loaded into memory. This is done by the class loader which takes the .class files containing the bytecode and stores it in the memory. The .class file can be loaded from your hard disk or from the network as well

4. Verify - the bytecode verifies checks if the bytecode loaded are valid and do not breach java's security restrictions

5. Execute - The JVM interprets the program one bytecode at a time and runs the program

No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...