Review of the Object class

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
Historical topic: Java appletsModern web browsers do not run Java applets. The Applet API was deprecated for removal before Java 25 and was removed in Java 26. Treat applet examples on this page as historical object-oriented/GUI examples; for new desktop interfaces use Swing where appropriate or JavaFX/OpenJFX.

Answer:

  • Is this code correct?
    • Yes.
  • What did it do?
    • It exchanged the objects in the first two slots of the array.

Review of the Object class

This sort of activity is very common in programming. You will see it a lot in the future. Notice that no new objects were created; but different reference variables were used for already-existing objects.

In Java, there is a pre-defined class that is the ultimate ancestor of all other classes. This class is called Object. When you define a class of your own like this:

class MyNewClass
{

}

You are actually defining a child of the Object class. The following is the exact equivalent of the above:

class MyNewClass extends Object
{

}

Every class in Java — your own and every class in every library — descends from Object. This will be important to remember when you get to graphical user interfaces.

QUESTION 15:

  • Is a String an Object?
  • Is a Card an Object?
  • Is a Applet an Object?