Tino Intro To Java

Last modified: January 07, 2024

Structure of a Java file

A typical Java class has the following structure:

public class MyClass {

    // Class Variables - static fields storing info about the
    //                   state of the class
    // Instance Variables - fields storing info about the state
    //                      of an object (attributes/properties)


    // Constructors - Specialized methods that set an object up
    //                and initialize instance variables


    // Methods - The things an object can do
    //           functions that perform actions and/or return a value

}

A few things to notice:

  1. Class names are capitalized and use UpperCamelCase.

  2. Class names match the filename EXACTLY.
    For example, public class Fish would be in a file named Fish.java

  3. The class begins with an opening brace "{" and ends with a closing brace "}"

  4. When a line of code contains a // everything after the // is considered a comment. Comments are ignored when compiling the code.
  5. Text between /* and */ is also considered a comment. This can be used to comment out multiple lines or just part of a line.

Dark Mode

Outline