O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

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

Watching the Clock

The next project gives you another look at each of the conditional tests you can use in your programs. For this project, you use Java’s built-in timekeeping feature, which keeps track of the current date and time, and present this information in sentence form.

Run NetBeans (or another program to create Java programs) and give a new class the name Clock. This program is long, but most of it consists of long conditional statements. Type the full text of Listing 7.3 into the source code editor, and save the file.

Listing 7.3. The Clock Program

 1: import java.util.*; 2: 3: class Clock { 4:     public static void main(String[] arguments) { 5:         // get current time and date 6:         Calendar now = Calendar.getInstance(); ...

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