Java Reference
In-Depth Information
Common Error 1: Missing Braces
The braces are used to denote a block in the program. Each opening brace must be matched
by a closing brace. A common error is missing the closing brace. To avoid this error, type a
closing brace whenever an opening brace is typed, as shown in the following example.
public class Welcome {
}
Type this closing brace right away to match the opening brace
If you use an IDE such as NetBeans and Eclipse, the IDE automatically inserts a closing
brace for each opening brace typed.
Common Error 2: Missing Semicolons
Each statement ends with a statement terminator (;). Often, a new programmer forgets to place
a statement terminator for the last statement in a block, as shown in the following example.
public static void main(String[] args) {
System.out.println( "Programming is fun!" );
System.out.println( "Fundamentals First" );
System.out.println( "Problem Driven" )
}
Missing a semicolon
Common Error 3: Missing Quotation Marks
A string must be placed inside the quotation marks. Often, a new programmer forgets to place
a quotation mark at the end of a string, as shown in the following example.
System.out.println( "Problem Driven );
Missing a quotation mark
If you use an IDE such as NetBeans and Eclipse, the IDE automatically inserts a closing
quotation mark for each opening quotation mark typed.
Common Error 4: Misspelling Names
Java is case sensitive. Misspelling names is a common error for new programmers. For exam-
ple, the word main is misspelled as Main and String is misspelled as string in the follow-
ing code.
1 public class Test {
2 public static void Main(string[] args) {
3 System.out.println(( 10.5 + 2 * 3 ) / ( 45 - 3.5 ));
4 }
5 }
1.42
What are syntax errors (compile errors), runtime errors, and logic errors?
Check
1.43
Give examples of syntax errors, runtime errors, and logic errors.
Point
1.44
If you forget to put a closing quotation mark on a string, what kind error will be
raised?
1.45
If your program needs to read integers, but the user entered strings, an error would
occur when running this program. What kind of error is this?
1.46
Suppose you write a program for computing the perimeter of a rectangle and you
mistakenly write your program so that it computes the area of a rectangle. What kind
of error is this?
 
Search WWH ::




Custom Search