JOOPs Through Java
All lessons

Unit 1 · Starting From Zero · 6 min

Comments, keywords and identifiers

Comments are notes for humans that Java ignores. Keywords are reserved words with special meaning. Identifiers are the names you choose for classes, variables and methods.

Why this matters

Good names and helpful comments are what separate readable code from code nobody (including future you) can understand.

Example

Java
// single line comment

/* multi line
   comment */

public class Student {          // Student is an identifier
    int rollNumber = 12;        // rollNumber is an identifier, int is a keyword
    // int class = 5;           // ERROR: 'class' is a reserved keyword
}

Step by step

  1. 1Anything after `//` on a line is ignored by the compiler.
  2. 2Anything between `/*` and `*/` is ignored, even across many lines.
  3. 3`public`, `class`, `int`, `static` are keywords — you cannot use them as names.
  4. 4Identifiers may contain letters, digits, `_` and `$`, but cannot start with a digit.

Key points

  • Class names use PascalCase: BankAccount
  • Variable and method names use camelCase: accountBalance
  • Constants use UPPER_CASE: MAX_MARKS
  • Comments never affect how the program runs

Common mistakes

  • Naming a variable `2ndMark` — identifiers cannot start with a digit
  • Using a keyword such as `new` or `class` as a variable name
  • Writing comments that repeat the code instead of explaining the reason

Try it yourself

  • Rename badly named variables a, b, c in a program to meaningful names.
  • Add a comment above main explaining what your program does.
Open the practice notebook