How Java is Platform Independent Language?

Spread the love
  • 1

If we look at the programing languages , they can be divided into three different segments.

Low level programming language

  • Machine level programming
  • Assembly level programming.

High level programming language-

  • it is procedural based like c,pascal,Fortran cobol etc. procedural programming manipulate or work with the data with procedures.
  • Functional programming -LISP
  • Logic level programming -Prolog
  • Object Oriented Programming-c++,smalltalk,Java.
Very high level programming language
  • Command language-DCL, Shell programming,
  • Query based-SQL

When low level programming language is very tedious to write code, the high level and very high level programmings are coder friendly. In low and high level coding user need to specify how to solve a problem where as in the very high level coding language,user needs to specify what to solve.  As data is the basic unit block in these languages, they can be called data oriented languages.The microprocessor inside every computer can understand and execute only machine code i.e the binary zero (0) and one (1).So there is a mechanism which converts high and very level code (written in English) to lower level machine code which is relevant to microprocessor.

As machine codes vary  from microprocessor to microprocessor,the same source code should be translated to different microprocessor using different translators.So a source code converted to machine code for Intel chip will differ from Motorola chip or to AMD athlon chip.The problem does not end here. The same problem exists in case of same microprocessor  with different operating system or with same operating system ,same microprocessor with different bit configuration x84,32 bit and x64 or 64 bits.

How does Java get the job done?

A Java application is compiled to Java bytecode which is the instruction set for Java Virtual Equipment (JVM).

Java compiler does not translate Java codes immediately to device code alternatively it first interprets the Java application to BYTECODE which is effectively an item file for a virtual machine that makes use of the extension.class This byte-code is established for a virtual system known as the Java Digital Equipment or JVM.

The bytecode verifier in the JVM then checks the bytecode immediately after which the JVM converts the bytecode to a equipment-welcoming code. To be much more particular it is the Just In Time (JIT) compiler of the JVM which is accountable for this conversion. It also retains the observe of the commonly repeated byte-codes so as not to repeat the compilation of identical codes yet again and yet again.

This is how Java capabilities. As the JVM converts the bytecode to a device unique code, for that reason we have distinctive JVMs for unique Java platforms mainly because JVMs are not system independent, the platform independence that Java demonstrates is a layer of abstraction, less than which dependence on the system in fact exists.

The components used in conversion are:

  • Assembler-Converts High level programming into low level machine language.
  • Compiler- Divides the high level program into small chunk of codes.
The general execution process:
High level code–> compiler—>small chunk of code blocks–>assembler—>equivalent machine code or native code–>processor–>compute–>result

Compiler design is an expensive process and each operating system interprets the command differently. So the compiled code in one machine may not run in other machine or in another operating system.

Java has come up with a new concept called byte code which is third stage in traditional program execution. JVM (Java virtual machine) converts the compiled code to a third stage called byte code. (a class file)
The program execution for Java is done as below:

java source(.java file)–>compiler–>.class file–> JVM–> Native machine code based on the execution environment–>result

Execution environment can be any combination:

  • Intel+windows
  • AMD+Linux
  • Intel+Linux etc
This is why java can be written once and run anywhere,anytime on any machine  configuration (microprocessor,operating system,bit configuration).
JVM (Java virtual machine) is a software program that resides into main memory(RAM) of the corresponding operating system.When we feed the .class file(byte code),it gets activated,detects the target platform and converts the .class file (byte code) to equivalent native or machine code which the processor can understand and execute.Unlike any other language compiler (VB,C etc) java compiler does not produce native executable code for a particular machine.It produces its own format .class file which is nothing but a byte code,then feeds the same into the target JVM(Java virtual machine). JVM(Java virtual machine) converts the byte code from Native executable code.The compiler generated byte code is understood by JVM (Java virtual machine) only.
JRE(Java runtime environment) has a part called JVM(Java virtual machine). JVM has three parts:
  • Class Loader
  • Byte Code Verifier
  • Executable Engine
The JVM architecture is given as:

Class Loader:
It loads a class and perform loading,linking and initialization.
Inside Java Virtual Machine, there are below segments:
Method Area:
Store class structure like metadata.The constants run-time pool and the code for methods.
All objects their related instance variables and arrays are stored inside heap.The memory is common and shared across multiple threads.
JVM Language Stack:
stacks the local variables and partial results.Each thread has its own JVM stack,created simultaneously as the thread is created.The frame is created whenever a method is invoked and the frame is deleted when execution is completed.
PC Register:
It stores the address of the java virtual machine instructions which is currently executing.In java,each thread has its separate PC register.
Native method stack:
It holds instruction of native code depends on the native library.It is written in some other language, other than Java.
Execution Engine:
This is a complete system to test hardware software and the complete system.It never carries any information about the tested products.

JIT is a part of JVM that interprets part of the byte code that has similar functionalities at the same time.


Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1


Please enter your comment!
Please enter your name here