🐞 Debugging Errors

Code not working? Follow the steps in the debugging process below before asking a peer or your teacher! Fixing your own errors, no matter how small, is one of the best ways to become a better coder.

β˜• Java Debugging Process

  1. Read the Error Message

    • Focus on the first error, not the dozens that follow β€” one small bug can cause many.
    • Look at the line number and the type of error (e.g., SyntaxError, NullPointerException).
  2. Check for Missing Symbols

    • Every line (except the last in a block) needs a semicolon (;).
    • Make sure parentheses (), braces {}, and brackets [] are all paired.
    • Method headers must have parentheses: public void sayHi()
  3. Check Braces and Indentation

    • Every { must have a matching }.
    • Indent code inside {} to match visually.
    • Don’t forget to close classes and methods!
  4. Check Capitalization

    • Java is case-sensitive: System β‰  system, main β‰  Main
    • Classes must start with capital letters (MyClass), but variables/methods use lowercase (myVariable)
  5. Check Spelling and Naming

    • Watch for typos like Systm.out.print instead of System.out.print
    • Match variable names exactly; Java won’t correct you
  6. Check Data Types and Declarations

    • Make sure all variables are declared with a type (int, String, double, etc.)
    • Strings must be capitalized: String name = "Alice";
  7. Print for Clarity

    • Use System.out.println() to check variable values
    • Print before and after key lines to isolate bugs
  8. Compile (Press RUN) Often

    • Don’t write 50 lines without compiling. Compile frequently so you catch errors early.
  9. Ask Yourself Questions

    • Is this variable initialized?
    • Am I using the correct data type for this operation?
    • Should this be inside the main method?
  10. If All Else Fails…

    • Comment out blocks to isolate the issue
    • Use a visualization tool like PythonTutor.com to β€œstep through” code, which shows what’s happening line-by-line.