hts.StevenWood.com

Common Programming Errors

Home ] Up ] How to use Methods in Java ] Methods and Parameters in Java ] Creating User-Defined Methods ] [ Common Programming Errors ] Good Programming Practices ] Lab Exercises ] Labs 1 ] Labs 2 ] Rubric ][ Last Page ]

Common Programming Errors

  1. 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.
  2. Defining a method outside the braces of a class definition is a syntax error.
  3. Omitting the return-value-type in a method definition is a syntax error.
  4. 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.
  5. Returning a value from a method whose return type has been declared void is a syntax error.
  6. 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.
  7. Placing a semicolon after the right parenthesis enclosing the parameter list of a method definition is a syntax error.
  8. Redefining a method parameter as a local variable in a method is a syntax error.
  9. Passing to a method an argument that is not compatible with the corresponding parameter's type is a syntax error.
  10. Defining a method inside another method is a syntax error.
  11. 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() )
  12. 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. 

Home ] Up ] How to use Methods in Java ] Methods and Parameters in Java ] Creating User-Defined Methods ] [ Common Programming Errors ] Good Programming Practices ] Lab Exercises ] Labs 1 ] Labs 2 ] Rubric ][Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+