Java Programming & Object-Oriented Design Complete Study Notes

Java Programming Fundamentals & Language Constructs

  • Identifiers & Naming Conventions

    • An identifier is a sequence of characters used to name variables, methods, classes, and other program constructs.

    • Allowed Characters: Identifiers consist of uppercase and lowercase letters, digits (0−90-9), underscores (_), and dollar signs (</code>).</p></li><li><p><strong>FirstCharacterRules</strong>:Anidentifiermuststartwithaletter,anunderscore(<code></code>),oradollarsign(<code></code>).</p></li><li><p><strong>First Character Rules</strong>: An identifier must start with a letter, an underscore (<code>_</code>), or a dollar sign (<code>). It cannot start with a digit (e.g., 2ndScore is invalid).

    • Reserved Words & Restricted Tokens: An identifier cannot be a Java reserved keyword (e.g., class, static, public, void). It also cannot be true, false, or null.

    • Length: Identifiers can be of any length.

    • Identifier Practice Examples:

      • studentName: Valid (starts with letter).

      • 2ndScore: Invalid (starts with digit).

      • _count: Valid (starts with underscore).

      • class: Invalid (reserved keyword).

      • total$: Valid (contains dollar sign).

      • null: Invalid (reserved literal).

Valid Java Identifiers Overview
  • Variables, Primitive Data Types & Memory

    • A variable declaration specifies two essential attributes: the data type (what kind of value it can hold) and the variable name (how to refer to the stored value in code).

    • General declaration syntax: DataType variableName; (e.g., int count;, double radius;, char grade;).

    • Primitive Variables vs. Reference Variables:

      • Primitive Variables: Directly store the actual primitive value assigned to them in memory (e.g., int number = 25; stores the value 25 inside number).

      • Reference Variables: Store the memory address of an object rather than the object itself. Objects are referenced by variables (e.g., `String cityName =