Natural Order

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.

Answer:

Natural Order

Objects that implement compareTo() can be arranged into a natural order. This order can be visualized as an arrangement of objects from left to right, like on a number line.

If an object A is left of another object B in this ordering, then

objectA.compareTo(objectB)

is negative. For example, X.compareTo("orange") is negative for all the fruit X left of "orange".

QUESTION 3:

What is "grape".compareTo( "banana" );