Java Reference
In-Depth Information
If there are compiler errors, they will be displayed on the command prompt
with a description of what the compiler did not understand. For example, Fig-
ure 1.8 shows the compiler error that occurs if the word String in Figure 1.6
was not capitalized.
Be sure to read your compiler errors closely. Many of my students simply
glance at a compiler error and quickly jump back to their code to look for the
error. However, if you read the error carefully, you will notice that the compiler
tells you the name of the file and the line number where the error occurred. In
the case of Figure 1.8, line 3 of HelloWorld.java has a problem.
Upon closer examination of the compiler error, it appears that the compiler
“cannot resolve symbol,” which happens to be my most common compiler
error. The compiler does not know what “string” means. That was my fault, of
course, because I changed String to string. The compiler doesn't know what I
meant; all it knows is that it cannot figure what a string is.
Step 3: Run the Program
After you have successfully compiled HelloWorld.java and created the Hello-
World.class file, you can now run the program using the java tool. The java
tool requires the name of the bytecode file that you want to execute. (The class
being executed must contain the main() method within it, or an error will
occur.)
Figure 1.9 shows the proper use of the java tool to run the HelloWorld pro-
gram. Keep in mind that Java is case sensitive, even though Windows and
DOS are not. You need to type in the name of the class using proper case, such
as HelloWorld, as shown in Figure 1.9.
Notice also in Figure 1.9 that you do not use the .class extension when run-
ning Java programs with the java tool. The JVM only interprets bytecode in
.class files, so the .class extension is not needed. An error occurs if you include
the extension.
Figure 1.8
The compiler does not know what a string is, as stated by the compiler error.
Search WWH ::




Custom Search