Java Reference
In-Depth Information
understand the same Java bytecode. If a Java program were compiled to native code, then
different versions of the same program would have to exist for each type of CPU connected
to the Internet. This is, of course, not a feasible solution. Thus, the execution of bytecode
by the JVM is the easiest way to create truly portable programs.
The fact that a Java program is executed by the JVM also helps to make it secure. Be-
cause the JVM is in control, it can contain the program and prevent it from generating side
effects outside of the system. Safety is also enhanced by certain restrictions that exist in the
Java language.
When a program is interpreted, it generally runs slower than the same program would
run if compiled to executable code. However, with Java, the differential between the two is
not so great. Because bytecode has been highly optimized, the use of bytecode enables the
JVM to execute programs much faster than you might expect.
Although Java was designed as an interpreted language, there is nothing about Java that
prevents on-the-fly compilation of bytecode into native code in order to boost perform-
ance. For this reason, the HotSpot technology was introduced not long after Java's initial
release. HotSpot provides a just-in-time (JIT) compiler for bytecode. When a JIT compiler
is part of the JVM, selected portions of bytecode are compiled into executable code in real
time on a piece-by-piece, demand basis. It is important to understand that it is not practical
to compile an entire Java program into executable code all at once because Java performs
various run-time checks that can be done only at run time. Instead, a JIT compiler com-
piles code as it is needed, during execution. Furthermore, not all sequences of bytecode are
compiled—only those that will benefit from compilation. The remaining code is simply in-
terpreted. However, the just-in-time approach still yields a significant performance boost.
Even when dynamic compilation is applied to bytecode, the portability and safety features
still apply because the JVM is still in charge of the execution environment.
Ask the Expert
Q :
I have heard about a special type of Java program called a servlet. What is it?
A : A servlet is a small program that executes on a server. Just as applets dynamically
extend the functionality of a web browser, servlets dynamically extend the function-
ality of a web server. It is helpful to understand that as useful as applets can be, they
are just one half of the client/server equation. Not long after the initial release of
Java, it became obvious that Java would also be useful on the server side. The result
was the servlet. Thus, with the advent of the servlet, Java spanned both sides of the
Search WWH ::




Custom Search