What is Java?
Java is one of the most used programming languages across developers. Java was initially developed by Sun Microsystems and called OAK in the 1990s. Later in 1995, its name changed to Java. Java is a class-based, object-oriented programming language developed for having lesser implementation dependencies. It is a computing platform for application development. The objective of Sun Microsystems was to develop an open software development platform and promote Java as an application programming language.
Java is an acronym for “Java programming language.” The language is a statically typed language based on the idea of “packages.” Java is a fast, secure, and reliable programming language. It is popular among programmers and software developers and has become a staple of enterprise software.
Java is an object-oriented programming language, i.e. it has many characteristics similar to procedural and object-oriented programming languages. Java introduced the concept of class and object, where programmers can create objects that are class instances and pass those instances to other methods or classes. The programming language creates desktop, web, server, and mobile applications. Java is popular due to its cross-platform feature that enables a Java program to run on multiple operating systems, including Windows, macOS, Linux, and more.
How is a program executed in Java?
In contrast to other compilers, the Java compiler does not create native executable files or platform-specific code. Instead, the Java compilation process creates a unique format known as Bytecode. This generated file is also known as a class file. The Java Byte Code is a set of machine instructions for the Java Virtual Machine processor chip, also called Java Virtual Machine. Java Byte Code has similar characteristics to machine language, but unlike machine language, Java byte code is the same on every platform. No platform can directly execute the byte code. Regardless of the platform on which the byte code was created, a natively executable code can be produced utilizing byte code using a JVM interpreter. The platform still requires an interpreter to run Java code that has been converted to bytes. Java is a language that can be both compiled and interpreted.
Step-by-step execution of a Java program:
- Whenever a java code is written, javac compiles it.
- Instead of machine-native code, the JAVA compiler results in a .class file or the Bytecode.
- The Bytecode generated is not machine-executable and needs an interpreter to run on a computer. The JVM serves as the interpreter; thus, the Bytecode is executed by the JVM.
- And finally, the program runs to produce the intended output.
What does platform independence mean?
A platform is a piece of hardware or software that a program frequently uses to execute. A platform is a particular set of hardware, an operating system, and software that creates a setting where applications can execute. Java Runtime Environment is the platform to run Java programs. Platform independence means how the program executes independently from the system’s operating system. The “Write Once Run Anywhere (WORA)” approach is used. It indicates that applications can be run on various platforms. If our application is platform-dependent, in that case, the application will not run on other platforms.
Platform independence reduces planning, execution, and translation efforts during the application process. In simple words, it is not dependent on other platforms. In Java, programs are compiled into bytecode, which is platform-independent and can run on all operating systems. Java programs can be run on various systems without having to be manually rewritten for each platform or “Write Once, Run Everywhere” (WORA). This aspect makes the Java platform independent.
Why is the java platform independent?
The Java package comes with JDK and JRE. JRE consists of a set of libraries and other files that JVM uses at runtime. JDK contains development tools helpful in developing and compiling java code. After compilation, it results in a .class file. This class file can run using JRE. JVM will also be installed automatically if JRE is already on the system. Java Virtual Machine(JVM) makes the Java platform independent.
Languages like C and C++ directly generate the machine code specific to one platform. Only the operating system in which it was compiled can understand and run this compiled code. In the case of Java, the java program is compiled into bytecode. This bytecode can run on a virtual machine that is JVM.
In-Demand Software Development Skills
|Python Courses||Core Java Courses||Data Science Courses|
|Data Analytics Courses||Digital Marketing Course||Full stack development Courses|
|Software Testing Training||React Js Courses||US IT Recruiter Training|
This Java virtual machine provides the same environment for the byte code to execute on whatever operating systems are present. Thus, the java code or the byte code can run anywhere, irrespective of the platform, because of JVM. There are various JVMs available for each kind of platform. JVM can read .class files or byte code. These bytes are machine-native codes because they allow us to write java code, compile it here, and run it on any system. But, there is only one requirement: the JVM needs to be installed on the system where the byte code will be run.
The main aim of developing Java is its platform independence feature. Although Java can be used on any platform, JVM must first be installed. JAVA is a platform-independent language, whereas the JVM is platform-dependent. The important point about Java is that the JVM depends on the operating system. Mac OS will have a different JVM, while Windows or some other operating system will have a different one. So we can conclude that JVM is platform-dependent, which is why Java is a platform-independent language.
Why is Java not completely platform-independent?
Java is not entirely platform-independent. The javac compiler first compiles the programmer’s High-Level program code into byte code. Although this bytecode is platform-independent, a Just In Time (JIT) interpreter/compiler is necessary. JVM runs the program by interpreting and compiling the byte code into machine code, JVM, which features JIT, runs the program.
The Java Virtual Machine interpreter is platform-specific. Various JVMs are found on various systems. For instance, the JVMs for Windows and MAC OS differ. This JVM can read the .class file or byte code.
So, Java is independent of the platform used by Java Byte Code, as can be inferred. Yet, the Java Virtual Machine, which is platform-specific, is necessary for the execution of Byte Code on any platform.