O'Reilly logo

Just Java™ 2 by Peter van der Linden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Digital Clock Program

Here's the rest of the code that makes up the digital clock. The program is made up of three classes:

  • TheTimestamp class that can give you the current hours, minutes, and seconds.

  • A class called “ClockView”. This holds everything related to the visual appearance of the clock on screen.

  • A class called “clock” that has overall control, and is where execution starts.

For a small example like this, we could merge everything into one class, and make it a dozen lines shorter. By keeping the design elements in separate classes, you can form a better idea of how classes should be used in bigger programs and systems.

The main() routine where execution starts

We'll start with the class that has overall control, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required