The document discusses key concepts related to compiling and executing Java programs. It explains that Java source code is compiled into bytecode, which can then run on any Java Virtual Machine (JVM) regardless of the underlying hardware. The bytecode is executed by the JVM. It also defines the Java Development Kit (JDK) as providing tools for developing and running Java applications, while the Java Runtime Environment (JRE) provides the libraries and JVM to run programs but not development tools. The JRE contains the JVM, which is responsible for executing Java programs line by line and provides platform independence.
The document discusses key concepts related to compiling and executing Java programs. It explains that Java source code is compiled into bytecode, which can then run on any Java Virtual Machine (JVM) regardless of the underlying hardware. The bytecode is executed by the JVM. It also defines the Java Development Kit (JDK) as providing tools for developing and running Java applications, while the Java Runtime Environment (JRE) provides the libraries and JVM to run programs but not development tools. The JRE contains the JVM, which is responsible for executing Java programs line by line and provides platform independence.
Introduction to Object Oriented Programming, First example (Hello Java program):
E.g. class HelloJava{ public static void main(String args[]){ System.out.print(“Hello Java”); } }
Process of Compilation and execution of Java Program:
In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native (machine specific) to our processor; it instead contains bytecodes — the machine language of the Java Virtual Machine (Java VM). The byte code is then executed by JVM. The java launcher tool then runs our application with an instance of the Java Virtual Machine. JVM runs when we type java MyMainClass Byte Code and Machine Code: Java code that, once compiled, is run through a virtual machine instead by the computer processor. By using this approach, source code can be run on any platform once it has been compiled and run through the virtual machine. Bytecode is the compiled format for Java programs. Once a Java program has been converted to bytecode, it can be transferred across a network and executed by Java Virtual Machine (JVM). Bytecode files generally have a .class extension.
JDK, JRE, JVM & JIT:
JDK provides environment to developed and run a java application.
The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers i.e. javac, appletviewer. JDK is an implementation of either of Java SE, Java EE or Java ME. Usually, learners start from JDK implementation of Java SE to learn core Java features, which is also known as Java SDK.
JRE provides environment only to run java programs.
The JRE provides the libraries and the JVM where our java programs run on (interpret), and browser plugins to run applets. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications. Java Virtual Machine (JVM): In JRE, JVM is actually responsible to execute java program line by line. So JVM is an interpreter. JVM is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed. JVM is the heart of java programming language and provides platform independence.