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 occur
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.14 The Java program-development process consists of repeatedly creating/modifying source code, compiling,
and executing programs.
F IGURE 1.15
You can create a Java source file using Windows Notepad.
A Java compiler translates a Java source file into a Java bytecode file. The following com-
mand compiles Welcome.java :
compile
javac Welcome.java
Note
You must first install and configure the JDK before you can compile and run programs.
See Supplement I.B, Installing and Configuring JDK 7, for how to install the JDK and set
up the environment to compile and run Java programs. If you have trouble compiling
and running programs, see Supplement I.C, Compiling and Running Java from the
Command Window. This supplement also explains how to use basic DOS commands
and how to use Windows Notepad and WordPad to create and edit files. All the
supplements are accessible from the Companion Website.
If there aren't any syntax errors, the compiler generates a bytecode file with a .class
extension. Thus, the preceding command generates a file named Welcome.class , as shown in
Supplement I.B
Supplement I.C
.class bytecode file
 
 
Search WWH ::




Custom Search