Java Reference
In-Depth Information
1.9 Bugs and the art of debugging
Writing programs that are syntaxically correct straight from the keyboard is
very rare. This seldom happens. This is why whatever textbook on Java one
may read, it will never replace the experience of programming. The experience
of programming consists of getting familiar with the way of thinking about the
architecture of a program and translating these thoughts into corresponding
language instructions. Sometimes a small typographic error in the source code
yields many subsequent listed errors by the compiler. Indeed, Java compiler
javac complains a lot and compiler comments are often verbose to help
programmers get to the point. Consider this program to train yourself to spot
the syntax errors:
class SyntaxBug {
public static void main( String
[ ]
args )
/*
Ask for a value
/
double val, fval;
fval=3*val*Val+2;
System.out.println("f(x)="+val);
}
}
Trying to compile this code will result in the following compiler error message:
prompt%javac SyntaxBug.java
SyntaxBug.java:5: unclosed comment
/*
^
SyntaxBug.java:13: reached end of file while parsing
}?
^
2 errors
Let us correct the multiple-line comment that lacks the closing
/
class SyntaxBug{
public static void main(String [] args)
{
/*
Ask for a value
/
double val, fval;
fval=3*val*Val+2;
System.out.println("f(x)="+val);
 
Search WWH ::




Custom Search