Class platform independent

 Introduction:

The meaning of platform-independent is that the java compiled code(byte code) can run on all operating systems.

A program is written in a language that is a human-readable language. It may contain words, phrases, etc which the machine does not understand. For the source code to be understood by the machine, it needs to be in a language understood by machines, typically a machine-level language. So, here comes the role of a compiler. The compiler converts the high-level language (human language) into a format understood by the machines. Therefore, a compiler is a program that translates the source code for another program from a programming language into executable code.

This executable code may be a sequence of machine instructions that can be executed by the CPU directly, or it may be an intermediate representation that is interpreted by a virtual machine. This intermediate representation in Java is the Java Byte Code.

Step by step Execution of Java Program:


Whenever, a program is written in JAVA, the javac compiles it.

The result of the JAVA compiler is the .class file or the bytecode and not the machine native code (unlike C compiler).

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.

And finally program runs to give the desired output.



In case of C or C++ (language that are not platform independent), the compiler generates an .exe file which is OS dependent. When we try to run this .exe file on another OS it does not run, since it is OS dependent and hence is not compatible with the other OS.


Java is platform-independent but JVM is platform dependent

In Java, the main point here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system. This fact can be verified by trying to download the JVM for your particular machine – when trying to download it, you will be given a list of JVMs corresponding to different operating systems, and you will obviously pick whichever JVM is targeted for the operating system that you are running. So we can conclude that JVM is platform-dependent and it is the reason why Java is able to become “Platform Independent”.


In the case of Java, it is the magic of Bytecode that makes it platform independent.

This adds to an important feature in the JAVA language termed as portability. Every system has its own JVM which gets installed automatically when the jdk software is installed. For every operating system separate JVM is available which is capable to read the .class file or byte code.

An important point to be noted is that while JAVA is platform-independent language, the JVM is platform-dependent. Different JVM is designed for different OS and byte code is able to run on different OS.

JAVA provide independand platform:

Java is one of the most famous and extensively used programming languages. It is a platform-independent programming language. Java doesn’t require the entire code to be rewritten for all the different platforms. It supports platform independence using Java bytecode and Java Virtual Machine. Java compiler javac converts the program code into byte code. This byte code is platform-independent and can run on any JVM operating system. JVM interprets the byte code to machine code, and the program is executed.


Platform Independence and Execution process in Java.

Comparison between compilation processes of C/C++ and that of Java.

Java Virtual Machine(JVM) and important features of Java.

Introduction

Computer programs are very closely related to specific hardware and operating system. For instance, Windows applications cannot run on Mac Operating System. Mac applications cannot run on the Android Operating system, and so on.


Some applications are common to all operating systems, like MS Word, so should that be written separately for all the Operating Systems?


To tackle this diversity of platforms, such applications should be written independently for all platforms. Java provides a way to write applications independent of the hardware and operating systems. Thus, it is called a platform-independent programming language.


What is a Platform, and What is a Platform-Independent Language?

The platform can be defined as a distinct combination of hardware, operating system, and software that provides an environment to run programs.


Java is called Platform Independent because programs written in Java can be run on multiple platforms without re-writing them individually for a particular platform, i.e., Write Once Run Anywhere (WORA).


How Java Provides Platform Independence?

To understand how Java facilitates platform independence, let us differentiate between the compilation process of other programming languages, mainly C/C++, and that of Java.


The program written by the programmer, known as source code, is not understood by the computer. Source code is very similar to human language, consisting of words and phrases. It has to be converted into machine language code, which computers can easily understand and execute.


Machine language code is a set of instructions to be executed by the computer. The compiler does this conversion. The process of converting source code into machine code is called compilation. Machine LaScaler Topics Logo

Free CoursesWhy Java is Platformew

Java is one of the most famous and extensively used programming languages. It is a platform-independent programming language. Java doesn’t require the entire code to be rewritten for all the different platforms. It supports platform independence using Java bytecode and Java Virtual Machine. Java compiler javac converts the program code into byte code. This byte code is platform-independent and can run on any JVM operating system. JVM interprets the byte code to machine code, and the program is executed.


Scope of Article

Platform Independence and Execution process in Java.

Comparison between compilation processes of C/C++ and that of Java.

Java Virtual Machine(JVM) and important features of Java.

Introduction

Computer programs are very closely related to specific hardware and operating system. For instance, Windows applications cannot run on Mac Operating System. Mac applications cannot run on the Android Operating system, and so on.


To tackle this diversity of platforms, such applications should be written independently for all platforms. Java provides a way to write applications independent of the hardware and operating systems. Thus, it is called a platform-independent programming language.


What is a Platform, and What is a Platform-Independent Language?

The platform can be defined as a distinct combination of hardware, operating system, and software that provides an environment to run programs.


Java is called Platform Independent because programs written in Java can be run on multiple platforms without re-writing them individually for a particular platform, i.e., Write Once Run Anywhere (WORA).


How Java Provides Platform Independence?

To understand how Java facilitates platform independence, let us differentiate between the compilation process of other programming languages, mainly C/C++, and that of Java.


The program written by the programmer, known as source code, is not understood by the computer. Source code is very similar to human language, consisting of words and phrases. It has to be converted into machine language code, which computers can easily understand and execute.


Machine language code is a set of instructions to be executed by the computer. The compiler does this conversion. The process of converting source code into machine code is called compilation. Machine Language Code is unique for different platforms.nguage Code is unique for different platforms.


Ordinary compilation  process

The code is first converted into machine-readable language when the C/C++ program is written and compiled in Windows OS. The compilation process will generate natively executable code as a .exe file. This natively generated code runs only on Windows Operating System.



This file cannot run on Mac, Unix, or other Operating Systems as the machine code is different for different Operating Systems. Thus, C/C++ is platform dependent programming language.









Comments

Popular posts from this blog

HOW TO CHECK ON VIRUS IN WINDOWS