Comments & Friendly Bugs
Leave notes in code and learn to read Java's error messages.
Comments & Friendly Bugs 🐛
Comments: notes for humans
Anything after // is a comment. Java ignores it completely. It's a note for people reading your code (including future you!).
public class Main {
public static void main(String[] args) {
// This robot greets the team
System.out.println("Hi team!"); // says hi
// System.out.println("This line is switched off");
}
}Only Hi team! is printed. The last line is "commented out", a handy way to switch code off without deleting it.
Java is picky about capitals
Java is case-sensitive: System and system are different words to Java.
system.out.println("Hi"); // ❌ Java doesn't know "system"
System.out.println("Hi"); // ✅Bugs are normal (really!)
When Java finds a mistake, it stops and shows an error message before running anything. That isn't Java being mean; it's Java being a helpful robot inspector. 🔍
The most common beginner bugs:
| Bug | Example |
|---|---|
| Missing semicolon | System.out.println("Hi") |
| Missing quote | System.out.println("Hi); |
| Wrong capitals | system.out.Println("Hi"); |
| Missing brace | forgetting a } at the end |
💡💡 Bug-hunting tip: read the error, look at the line number it mentions, then check the line just above it too.
🐞 Fun fact
In 1947, engineers found a real moth stuck inside a computer, causing problems. They taped it into their logbook as the "first actual case of bug being found". Computer bugs have been called bugs ever since!
Want to run it yourself?
Predict what the code prints first, then check! Copy an example above, paste it into the free online Java editor, and press Run. Keep the first line as public class Main.
Opens Programiz, a free site that isn't run by First Coding Path and may show ads. Grown-ups, you might like to take a look first.