Java Reference
In-Depth Information
Create/Modify Source Code
Source code (developed by the programmer)
Saved on the disk
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
Source Code
}
Bytecode (generated by the compiler for JVM
to read and interpret)
Compile Source Code
e.g., javac Welcome.java
Method Welcome()
0 aload_0
If compile errors occu r
Stored on the disk
Bytecode
Method void main(java.lang.String[])
0 getstatic #2 …
3 ldc #3 <String "Welcome to Java!">
5 invokevirtual #4 …
8 return
Run Bytecode
e.g., java Welcome
“Welcome to Java ” is displayed on the console
Welcome to Java!
Result
If runtime errors or incorrect result
F IGURE 1.6
The Java program-development process consists of repeatedly creating/modifying source code, compiling,
and executing programs.
F IGURE 1.7
You can create a Java source file using Windows Notepad.
in Figure 1.8a. The Java language is a high-level language, but Java bytecode is a low-level
language. The bytecode is similar to machine instructions but is architecture neutral and can
run on any platform that has a Java Virtual Machine (JVM) , as shown in Figure 1.8b. Rather
than a physical machine, the virtual machine is a program that interprets Java bytecode. This
is one of Java's primary advantages: Java bytecode can run on a variety of hardware plat-
forms and operating systems. Java source code is compiled into Java bytecode and Java byte-
code is interpreted by the JVM. Your Java code may use the code in the Java library. The JVM
executes your code along with the code in the library.
To execute a Java program is to run the program's bytecode. You can execute the bytecode
on any platform with a JVM, which is an interpreter. It translates the individual instructions
in the bytecode into the target machine language code one at a time rather than the whole pro-
gram as a single unit. Each step is executed immediately after it is translated.
The following command runs the bytecode for Listing 1.1:
bytecode
Java Virtual Machine (JVM)
interpret bytecode
run
java Welcome
 
 
Search WWH ::




Custom Search