Wednesday 25 July 2012

How java(J2SE) compiler works?

J2SE Programming

Here am going to tell you how java compiler works i.e. what is the actual working of java compiler.

If you write a program in java then it is both compiled and interpreted. The aim of the both compilation and interpretion is just to make program made by you more secure and making it portable i.e. platform independent.

Java Compiler Working

Now What actually happen when you compile a java program:-
  1. Firstly it is compiled for any error like Syntax error,etc.
  2. Once it is compiled, code is generated by the compiler known as BYTE Code which is some binary code can't be understandable by the Humans.The file generated by compiler has a extension of .class
  3. Like if you compile a file named First.java, then compiler generates a file named First.class which can be viewed using notepad but can't be understanded.
  4. Once the byte code is generated, it can be run on any platform.Here run means Interpreting the byte code and providing the appropriate output.
  5. There is one another thing in java which makes it more efficient i.e JIT(Just In Time Compiler) which is a part of JVM( Java Virtual Machine) which converts only necessary code to executable code              e.g. if then is an if condition which is already known that else part will be executed then JIT converts only that else part to the executable code but not the if part. JIT Comes in action during Run Time.
  6. After that the appropriate output is shown on the screen.

0 comments:

Post a Comment