Java Reference
In-Depth Information
The term “JVM” is used in three contexts:
The JVM specification : It is the specification or standard of an abstract machine for which a
Java compiler can generate bytecode.
The concrete realization of the JVM specification : If you want to run your Java program, you
need to have a real JVM, which is developed using the abstract specification for a JVM. To run
the Java program in previous section you used a command like
C:\javaprograms>java com.jdojo.intro.Welcome
Here, java is a progra m developed fully based on the abstract specification for the JVM.
Therefore, it is the concrete realization of the abstract JVM specification. The java program
(or JVM) has been implemented completely in software. However, a JVM can be
implemented in software or hardware, or a combination of both.
A running JVM instance : You have a running JVM instance when you invoke the java program.
This topic uses the term JVM for all three cases. Its actual meaning should be understood by the context of its use.
One of the jobs a JVM performs is to execute the bytecode and generate a machine-specific instruction set for the
host system. A JVM has a classloader and an execution engine. The classloader reads the content of a class file when
required and loads it into memory. The job of the execution engine is to execute the bytecode.
A JVM is also called a Java Interpreter. Often, the term “Java Interpreter” is misleading, particularly to those
programmers who have just started learning the Java language. By the term “Java Interpreter,” they conclude that
the execution engine of a JVM interprets the bytecodes one at a time, and so Java must be very slow. The name
“Java Interpreter” for a JVM has nothing to do with the technique the execution engine uses to execute the bytecode.
The actual technique, which the execution engine may opt to execute the bytecode, depends on the specific
implementation of the JVM. Some execution engines types are interpreter, just-in-time compiler, and adaptive
optimizer. In its simplest kind, which is interpreter, the execution engine interprets the bytecodes one at a time, and
therefore, it is slower. In its second kind, which is the just-in-time compiler, it compiles the whole code for a method
in the underlying host machine language for the first time that method is called. Then it reuses the compiled code the
next time the same method is called. This kind of execution engine is faster compared with the first kind, but requires
more memory to cache the compiled code. In adaptive optimizer technique, it does not compile and cache the whole
bytecode; rather it does so only for the most heavily used part of the bytecode.
What is an API (application programming interface)? An API is a specific set of methods made available by an
operating system or by an application to the programmers for its direct use. In the previous sections, you created the
Welcome class in the com.jdojo.intro package, which declared a method main , which accepts an array of String as
an argument and returns nothing (indicated by keyword void ). If you expose all these pieces of information about
the created package, class and method, and make it available to other programmers for use, your method main in the
Welcome class is a typical, though trivial, example of an API. Generally, when we use the term “API” we mean a set of
methods that are available to the programmer for use. Now it is easy to understand what the Java API means. The Java
API is the set of all classes and other components that are available to programmers for use while writing Java source
code. In your Welcome class example, you have already used one Java API. You used it inside the body of the main
method to print the message on the console. The code, which used the Java API, is
System.out.println("Welcome to the Java world");
You did not declare any method named println in your code. This method was made available to the JVM
at runtime through Java API, which is the part of Java Platform. Broadly speaking, Java API can be classified in two
categories: Core API and Extension API. Every JDK must support the Core API. Examples of Core Java APIs are Java
runtimes (e.g., Applets, AWT, I/O, etc.), JFC, JDBC, etc. Java Extension APIs are JavaMail, JNDI (Java naming and
Directory Interface), JavaHelp, etc. Java 8 includes JavaFX 8 API as an extension API. The process of compiling and
running a Java program is depicted in Figure 2-19 .
 
Search WWH ::




Custom Search