Small Java Programs
This chapter discusses naming and coding conventions as well as reserved words in Java. When you go through this chapter, you'll get some hands-on experience with writing in Java.
8. A Capital Mistake
Answer:
The first letter of "Class" is wrong.
A Capital Mistake
The reserved word "class" has been changed to "Class" with a capital "C". So what? This is called a syntax error. A syntax error is a "grammatical error" in using the programming language. Here is what happens when the mistaken program is compiled:
The compiler tried to translate the source code into bytecode but got confused when it got to a capital "C" it did not expect. The error message is not very clear. They never are. But at least it shows where the compiler got confused. The compiler did not create a new bytecode file because it stopped translating when it got to the error.
C:\JavaSource>javac Hello.java compiling: Hello.java Hello.java:1: Class or interface declaration expected. public Class Hello ^ 1 error |
Question 8:
What is the error in the following program?
C:\JavaSource>public class hello
{
public static void main ( string[] args )
{
System.out.println("hello world!");
}
}