written 8.4 years ago by |
Java virtual machine (JVM)
- A Java virtual machine (JVM) is an abstract computing machine that enables a computer to run a Java program.
- There are three notions of the JVM: specification, implementation, and instance.
- The specification is a document that formally describes what is required of a JVM implementation. Having a single specification ensures all implementations are interoperable.
- A JVM implementation is a computer program that meets the requirements of the JVM specification. An instance of a JVM is an implementation running in a process that executes a computer program compiled into Java byte code.
Java Runtime Environment (JRE)
- Java virtual machine (JVM) is a software package that contains what is required to run a Java program. It includes a Java Virtual Machine implementation together with an implementation of the Java Class Library.
- The Oracle Corporation, which owns the Java trademark, distributes a Java Runtime environment with their Java Virtual Machine called Hotspot.
Java Development Kit (JDK)
- Java Development Kit (JDK) is a superset of a JRE and contains tools for Java programmers, e.g. a java compiler. Java Development Kit is provided free of charge either by Oracle Corporation directly, or by the Open JDK open source project, which is governed by Oracle.
Java Programming Environment
Java is a recently developed, concurrent, class-based, object-oriented programming and runtime environment, consisting of:
- A programming language
- An API specification
A virtual machine specification
Java has the following characteristics:
Object oriented –
Java provides the basic object technology of C++ with some enhancements and some deletions.
Architecture neutral –
Java source code is compiled into architecture-independent object code. The object code is interpreted by a Java Virtual Machine (JVM) on the target architecture.
Portable
Java implements additional portability standards. For example, ints are always 32-bit, 2's-complemented integers.
User interfaces are built through an abstract window system that is readily implemented in Solaris and other operating environments.
Distributed –
Java contains extensive TCP/IP networking facilities. Library routines support protocols such as HyperText Transfer Protocol (HTTP) and file transfer protocol (FTP).
Robust –
Both the Java compiler and the Java interpreter provide extensive error checking. Java manages all dynamic memory, checks array bounds, and other exceptions.
Secure –
Features of C and C++ that often result in illegal memory accesses are not in the Java language. The interpreter also applies several tests to the compiled code to check for illegal code.
After these tests, the compiled code causes no operand stack over- or underflows, performs no illegal data conversions, performs only legal object field accesses, and all opcode parameter types are verified as legal.
High performance –
Compilation of programs to an architecture independent machine-like language, results in a small efficient interpreter of Java programs. The Java environment also compiles the Java byte code into native machine code at runtime.
Multithreaded –
Multithreading is built into the Java language. It can improve interactive performance by allowing operations, such as loading an image, to be performed while continuing to process user actions.
Dynamic –
Java does not link invoked modules until runtime.
Simple –
Java is similar to C++, but with most of the more complex features of C and C++ removed.
JRE Components
The JRE is the software environment in which programs compiled for a typical JVM implementation can run. The runtime system includes:
Code necessary to run Java programs, dynamically link native methods, manage memory, and handle exceptions
- Implementation of the JVM.
The following figure shows the JRE and its components, including a typical JVM implementation's various modules and its functional position with respect to the JRE and class libraries.
Traditional Compile-Time Environment
Java Compiler
Javac compiles Java programs.
SYNOPSIS
Javac [ options ] filename.java ...
javac_g [ options ] filename.java ...
Description
- The javac command compiles Java source code into Java bytecodes. You then use the Java interpreter - the java command - to interprete the Java bytecodes.
- Java source code must be contained in files whose filenames end with the .java extension. The file name must be constructed from the class name, as classname.java, if the class is public or is referenced from another source file.
- For every class defined in each source file compiled by javac, the compiler stores the resulting byte codes in a class file with a name of the form classname.class. Unless you specify the - doption, the compiler places each class file in the same directory as the corresponding source file.
- When the compiler must refer to your own classes you need to specify their location. Use the -classpath option or CLASSPATH environment variable to do this. The class path is a sequence of directories (or zip files) which javac searches for classes not already defined in any of the files specified directly as command arguments. The compiler looks in the class path for both a source file and a class file, recompiling the source (and regenerating the class file) if it is newer.
- Set the property javac.pipe.output to true to send output messages to System.out. Set javac.pipe.output to false that is, do not set it, to send output messages to System.err.
- javac_g is a non-optimized version of javac suitable for use with debuggers like jdb.
New Portable Java Compile-Time Environment
JIT Compile Process
- When the JIT compiler environment variable is on (the default), the JVM reads the .class file for interpretation and passes it to the JIT compiler. The JIT compiler then compiles the bytecodes into native code for the platform on which it is running. The next figure illustrates the JIT compile process.