Skip to main content

Why java is platform independent?

 Java programming language provides platform independence, what does it mean ? It means same java program can be run on any platform or operating system e.g. Windows, Linux or Solaris without any change. This is the great benefit for some one coming from platform dependent programming language like C or C++ whose code needs to be ported for every single platform because they use native libraries which differ in every platform. Now question comes how Java achieve platform independence, what makes Java programs running on every platform without any change ? This is one of the most basis question java programmer ask when it start learning java programming language. if you read further you will come to know about byte code and Java virtual machine which together provides platform independence to Java.

For those who don't know Java is both compiler and interpreter language. When you compile a Java program it creates .class file which is collection of byte code, these byte code are not machine instruction instead they are instruction which Java virtual machine can understand. Since every Java program runs on Java virtual machine, same byte code can be run on any platform. key is byte code is not machine instruction they are platform independent instruction to JVM. On the other hand JVM or Java virtual machine is platform dependent because it converts byte code into machine level instruction which is platform specific and that's why you have different version of JDK and JRE for windows and Linux because both JDK and JRE comes with Java virtual machine. if you are confused between JVM, JRE and JDK then read my most on difference between JDK, JRE and JVM in java.

Byte code is created when you compile Java program using java compiler "javac" and byte code runs on JVM which is created by running "java" command. In detail when you run "java" command it creates Java virtual machine, loads Main class specified in command line and calls standard main method in java.

In summary combination of byte code and JVM makes Java program platform independent. Write once run everywhere was Java’s mantra when it started ruling programming world in mid and late 90’s.  



Comments

Popular posts from this blog

What is the difference between Selenium and QTP?

Feature QTP(UFT) Selenium Language Support VB Script Java, C#, Ruby, Python, Perl, PHP Windows (Non-browser) based Application support Yes No Browser support Google Chrome (uptill ver 23) Internet Explorer , Firefox ( ver 21) Google Chrome , Internet Explorer , Firefox , Opera , HtmlUnit, Safari Environment Support Only Windows Windows , Linux , Solaris OS X , iOS, Android, Others (If brower & JVM or Javascript support exists) Mobile (Phones & Tablets) Support Different commercial product i.e. HP UFT Mobile (formerly known as MobileCloud for QTP) Android , iPhone & iPad , Blackberry , Headless WebKit Framework Easily integrated with HP Quality Center or HP ALM (separate commercial products) Selenium + Eclipse + Maven / ANT + Jenkins...

How to create package inside a project?

What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages. -> Right click on the Project (Make sure you should right click on project, because you are creating package inside the project). -> Go to New. -> Click on Package. -> In New Java Package window, enter package name in Name text box. -> Now click on Finish . -> Now you can see the package inside the project at Project Explorer area. Now your package is ready.