Saturday, March 18, 2017

How Java Program Works

In this post we will discuss and learn the process for steps involved in running a java program and also we learn about what is compiler and what is interpreter and difference between them. Lets start to know about what is compiler?

Compiler: A compiler translates the entire source code into a machine code or  intermediate code and that file is executed.

The following diagrams represents how compiler works:




In the above diagram high level source program represents any high level programming language such as C,C++,JAVA or any other programming language. We used to write programs(source code) human readable code only. After writing high level source program and then we use Compiler  to translate  that code into machine level code or intermediate form and then we use executor ,the responsibility of executor is to execute the compiled code and then generates output. The compiler reads entire source code and it can be converted into machined code and then intermediate code will be executed by executor software and then generate output.

Interpreter:

An interpreter reads one statement at a time from source code,and translates into machine code or virtual machine code and then execute.




In the above diagram  from the source program written in high level source program, that program will be translate by using interpreter. If we use interpreter,then the source program compiled line by line and then convert into machine level form and then execute that machine level code.

How to execute programs:

In any Programming languages such as C,C++,JAVA or any other programming languages written Source code in High level language only but computers can only executes the code in binary form which is 0's and 1's. A program which is written in the high level language is called source program or source code.Since computer can not understand source code, so a source program must be translated into a machine code for execution. So translators can be used to convert from high level language to machine understanding form is called compiler or interpreter.


How java program works:

Now lets see how java program works or the steps involved to run a java program.




Step 1: First we write a java program nothing but Java source code in any text editor and then we need to save with .Java extension.

Step 2: After saving the file with .java extension we need to compile that saved file by using java compiler.After successfully compiled java file we can get java byte code(.class) file.

Step 3: After generated .class file we have to pass this byte code into JVM which is interpreter which can read statements one by one and then converted into machine level code and then generates output to the end user.

All java programmers knows java is platform independent feature, that means you can write java code only once and we can execute and  run different operating system such as windows,linux,Mac..So java provides platform specific Java Virtual Machine. That means if you use Windows platform then you use windows JVM,if you use Mac platform you use Mac JVM. So all specific JVM are capable of executing java code in the same way.

Let me know your comments on this topic and keep follow me for latest updates and don't forget for subscribe in the blog or google plus to receive latest updates.

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...