Java 7 for Absolute Beginners

(nextflipdebug5) #1

CHAPTER 1 ■ WRITING YOUR FIRST JAVA PROGRAM


About Java Objects


Notice how we had to use two kinds of objects (Date and SimpleDateFormat) to create a nicely formatted
date. Date and SimpleDateFormat are defined by class files, just as your Hello program is defined by a
class file. We told our Java program where to find those classes with the import statement near the top of
the file. Your program cannot run without them, so we have to tell Java where to find them.
For any class or other bit of code that's part of the Java standard libraries, you can learn all about it
from the Javadoc that Oracle maintains for each version of Java. Javadoc is a special document format
that lets Java programmers embed documentation directly into code. That way, you can look at the
documentation for classes you want to use as you program your own classes. As you do more
programming, you'll spend a lot of time reading this documentation. As a good learning exercise, look
up the SimpleDateFormat class and look at all the options you can use when formatting a date.
For Java 7, you can find the API (short for Application Programming Interface) documentation at
http://download.oracle.com/javase/7/docs/api/.

■ Note Eclipse provides the Javadoc information for items in the standard API. Hover your mouse over any
method or object that you're using, and you'll see the Javadoc information for that item. When you see the
Javadoc, press F2 to open a separate window that lets you see more.

Summary


In this chapter, we did the following tasks:


  • Downloaded and installed the Java Development Kit

  • Downloaded and installed Eclipse, which we use to write Java programs

  • Created the code for our first program within Eclipse

  • Ran our first program (“Hello, world!”)

  • Modified the first program to do a bit more (say hello to you specifically)

  • Modified the program still more (to include the date and time)

  • Learned where to find more information about the other code used in future
    programs


Many of these tasks constitute the day-to-day work of full-time software developers. We spend a lot
of time (more than we'd like, usually) setting up tools. We also spend most of our time either writing new
classes or (far more often) rewriting existing classes, either to add new functionality or to correct a
problem. We also certainly spend plenty of time reading documentation or wishing we had more
documentation to read.
Free download pdf