Java Reference
In-Depth Information
Table 2-6
Common Syntax Errors
SYNTAX ERROR
SAMPLE ERROR MESSAGE
METHOD OF CORRECTION
missing semicolon
invalid type expression
Add a semicolon at the end of
invalid declaration
the line.
';' expected
missing punctuation
')' expected
Insert missing ) or }.
incorrect file name
public class must be
Make sure class name and file
defined in a file
name match exactly, both in
spelling and capitalization.
incorrect number of
invalid argument
Add a comma between
arguments
arguments in an argument list.
incorrect use of
missing term
Correct operand error.
mathematical
operators
Semantic Errors
While syntax refers to code structure or grammar, a semantic error is an
error that changes the meaning of the code. To the Java compiler, a semantic
error appears as unrecognizable code. For example, if you misspell the println()
method in code, the Java compiler will return an error message that it cannot
resolve the symbol or that the method was not found (Figure 2-30). If you use
a variable name that has not been declared properly, the compiler will return
an error message that the variable is undefined. Most semantic errors can be
fixed by correcting the spelling of keywords or by properly defining variables and
methods.
semantic error
is displayed
FIGURE 2-30
If TextPad displays error messages when you try to compile a program, click
the file name in the Selector window to display the code in the coding window
and then correct any syntax or semantic errors. Alternately, you can double-click
 
Search WWH ::




Custom Search