Intro to Objects - Computer Math

Java Compilation & Basics

  • Java applications require a public static void main(String[] args) method to be runnable.

  • Source code (.java) is translated into bytecode (.class) by the javac compiler, making the code platform-independent so it can run on UNIX, Windows, or Mac.

  • The compiler ignores comments starting with //, while the import keyword is used to make external classes and packages accessible.

Classes, Objects, and Inheritance

  • The new keyword is used to instantiate a new object, which makes the object an instance of a specific class.

  • A base class that defines what objects can do is called a superclass (e.g., Robot), while a class that adds more functionality is a subclass (e.g., Athlete).

  • The greatest advantage of creating a subclass like Athlete is inheritance, which is implemented using the extends keyword.

Default Properties & Instantiation

  • When created with the default constructor, a Robot starts at position (1, 1) facing Display.EAST with 0 beepers.

  • When created with the default constructor, an Athlete starts at position (1, 1) facing Display.NORTH with Display.INFINITY beepers.

  • You can instantiate objects with custom starting data, such as Robot john = new Robot(4, 1, Display.NORTH, 5);.

Syntax and Identifiers

  • The Java class name must perfectly match the filename, and blocks of code are grouped using matching curly braces.

  • Methods are always marked by parentheses, as seen in commands like move(); or putBeeper();.

  • Identifiers (used for naming classes, objects, or methods) are case-sensitive, cannot be keywords, and must only contain letters, numbers, and underscores.