|
| |
Common Programming Errors
- Forgetting to invoke a Math class method by preceding the method
name with the class name Math and a dot operator (.) results
in a syntax error.
- Defining a method outside the braces of a class definition is a syntax
error.
- Omitting the return-value-type in a method definition is a syntax error.
- Forgetting to return a value from a method that is supposed to return a
value is a syntax error. If a return-value type other than void is
specified, the method must contain a return statement.
- Returning a value from a method whose return type has been declared void
is a syntax error.
- Declaring method parameters of the same type as float x, y instead
of float x, float y is a syntax error because types are required for
each parameter in the parameter list.
- Placing a semicolon after the right parenthesis enclosing the parameter
list of a method definition is a syntax error.
- Redefining a method parameter as a local variable in a method is a syntax
error.
- Passing to a method an argument that is not compatible with the corresponding
parameter's type is a syntax error.
- Defining a method inside another method is a syntax error.
- Attempting to determine the length of a String via length (e.g. s1.length)
is a syntax error. The String method length() must be used.
(e.g. s1.length() )
- Attempting to access a character that is outside the bounds of a String
(i.e., an index less than 0 or an index greater than or equal to the String's
length) results in a StringIndexOutOfBoundsException.
Source: Deitel, H.M. and Deitel P.J. Java: How to Program. 3rd ed. Upper Saddle River, New
Jersey. Prentice Hall.1999.
ISBN 0-13-012507-5, p 252, 505.
|