Computer Science
Developing code: error messages, debugging, comment statements, writing, saving and retrieving program files

Learning Objectives

Developing code: error messages, debugging, comment statements, writing, saving and retrieving program files

Lesson readings,Website links:
Sample code link:

Error Messages and Debugging software

As you have already discovered, BlueJ provides some very detailed information in its error messages when you compile. Sometimes that detail is a little overwhelming as you just start programming; however, the information provided allows you to rapidly find the error (be they syntax or programming itself) in your programs.

BlueJ Compiler error message

This error message tells you that the line with the red block to the left has an error. The squiggly line points out the error (well, not quite). Looking closely, you will see what is one of the most common Java coding errors: forgetting that the System object starts with a capital (upper case) "S". Correct that typo, the red block goes away, the "Error(s) found in class" message is removed, and when compiling, you should see the "Class compiled -- no syntax errors" will display.

When you write code, you should be documenting the code as you go, using one of the two comment delineators: either // for a single line comment or /* comment */ for multiple line comments. As a bare minimum, you should identify in a comment EVERY variable, constant, and literal in the code; Identify by type, purpose, arguments, return type and purpose all classes and methods; comments in the header and read-me file when you make changes for different versions to either add functionality or document troubleshooting; and any other comments you find you will need as you code. I will frequently build skeleton classes and methods, and then put comments within the structure to help me remember what I intended to accomplish with a snippet of code.

Debugging depends on your being able to 1) read the error message, 2) properly comment and document, 3) think logically as you continue.

Writing, Saving, and Retrieving code

Here are a few standards you need to remember when you write your programs for class.

  1. File naming convention
    1. DO NOT USE SPACE CHARACTERS in any file name, class name, or method name.
    2. Normal convention for classes and methods: first letter of the name is lower case, if there are multiple words in the name, then each subsequent word has the first letter capitalized (called "camelback" or "humpback" capitalization).
    3. Hyphens (-) are generally not allowed as part of a class name (although they are allowed in file names)
    4. Underscore (_) characters are allowed as part of class name.
    5. For class assignments, your file name must include your last name (and if there are two in a class with the same last name, then lastname and first initial with no space); the assignment number; and the date in this format:
  2. 170509_walrath_U01L05_Program01

    where the date is 17 (2017) 05 (May) 09 (9th of May 2017), my name, Unit 01 Lesson 05 Program 01.

  3. Variables
    1. May start with lower case, generally use camelback capitalization
    2. Do not start with a numeral (however, may end with one)
    3. Should be logical. In other words, if you are calculating salary, the variable that is loaded with the salary should be easily understood (hint: use the word "salary") rather than a mysterious single character "x".
  1. Constants
    1. Are generally all UPPERCASE.
    2. If you need to use multiple words to make sense, use the underscore character to separate words (_).
  2. Comments
    1. Are REQUIRED and graded/evaluated
    2. Must be proceeded by the single line comment ( // ) or multiple line comment ( /* */ ) delineators
    3. identify variables, constants, literals
    4. identify classes, arguments passed to the class and arguments returned from the class.
    5. ANY OTHER SITUATION TO HELP YOU REMEMBER WHAT YOU ARE DOING IN THE PROGRAM!

 

Breadcrumbs HomeCSUnit 1 1-4-1 1-5-1 1-6-1