Java Reference
In-Depth Information
indicates the closing brace of method main , and line 11
} // end class Welcome1
indicates the closing brace of class Welcome1 . Each comment indicates the method or class
that the right brace terminates. We'll omit such ending comments after this chapter.
Compiling Your First Java Application
We're now ready to compile and execute our program. We assume you're using the Java
Development Kit's command-line tools, not an IDE. To help you compile and run your
programs in an IDE, we provide online Dive Into ® videos for the popular IDEs Eclipse,
NetBeans and IntelliJ IDEA. These are located on the topic's website:
http://www.deitel.com/books/jhtp10
To prepare to compile the program, open a command window and change to the
directory where the program is stored. Many operating systems use the command cd to
change directories. On Windows, for example,
cd c:\examples\ch02\fig02_01
changes to the fig02_01 directory. On UNIX/Linux/Max OS X, the command
cd ~/examples/ch02/fig02_01
changes to the fig02_01 directory. To compile the program, type
javac Welcome1.java
If the program contains no compilation errors, this command creates a new file called
Welcome1.class (known as the class file for Welcome1 ) containing the platform-indepen-
dent Java bytecodes that represent our application. When we use the java command to
execute the application on a given platform, the JVM will translate these bytecodes into
instructions that are understood by the underlying operating system and hardware.
Common Programming Error 2.4
When using javac , if you receive a message such as “ bad command or filename ,” “ javac:
command not found ” or “ 'javac' is not recognized as an internal or external com-
mand, operable program or batch file ,” then your Java software installation was not
completed properly. This indicates that the system's PATH environment variable was not
set properly. Carefully review the installation instructions in the Before You Begin section
of this topic. On some systems, after correcting the PATH , you may need to reboot your com-
puter or open a new command window for these settings to take effect.
Each syntax-error message contains the filename and line number where the error
occurred. For example, Welcome1.java:6 indicates that an error occurred at line 6 in
Welcome1.java . The rest of the message provides information about the syntax error.
Common Programming Error 2.5
The compiler error message “ class Welcome1 is public, should be declared in a file
named Welcome1.java ” indicates that the filename does not match the name of the pub-
lic class in the file or that you typed the class name incorrectly when compiling the class.
 
Search WWH ::




Custom Search