Sun Java Solaris Communities My SDN Account Join SDN
 
New to Java Programming Center

New to Java

Programming Center

Java Platform Overview | Getting Started | Step-by-Step Programming
Learning Paths | References & Resources | Certification | Supplements




Contents
BACK<<Application Objects | About Classes | NEXT>>Packages

Do you think there is a limit to how many objects make up an application?

There are no limits on how many objects you can create for an application.

Left Bracket More About Objects

Classes, Objects, and Constructors: What's the Difference?

Object-Oriented Programming Defined

What Is an Object?
Right Bracket

The number of objects an application instantiates, or puts into memory, depends entirely on the requirements of the application.

The point to keep in mind about classes and objects is that the class is the plan, and the object is the plan with all the details filled in and put into memory. In other words, the object is the actual button a user clicks rather than the instructions or class that specifies button size or function.

Classes

The classes that are a part of the Java J2SETM download are complete, predefined classes you can use in your applications. These predefined classes provide features frequently used in creating applications, such as writing to and reading from files, creating graphical components like buttons and menus, and making Web pages interactive.

To create an application, though, you need to define your own classes as well as using predefined classes from the Java library. Your own classes provide the instruction for how you want the application built, and the predefined class you use define many components of the application, premade objects, such as buttons, menus, fonts, colors, and more.

When you define a class, you are planning how the object created from that class is going to appear and behave. A class contains:

  • Fields
    Fields, or variables, store data and are frequently called data members. These variables often differentiate one object from another and define attributes such as amounts, names, titles, and so forth.
  • Methods
    Methods manipulate variables or objects, such as doing math operations, inputting characters or strings, printing text to the screen, adding a button to a menu bar, or simply instantiating an object.
Left Bracket What are Keywords?
Keywords are reserved words that cannot be used as variable, method, or class names because they are used in Java programming syntax.

for, while, public, if, and class are some keywords.
Right Bracket

There'll be more on fields and methods later. For now, look at some kinds of classes you'll write to create objects for the Dive Log.

First, you'll need a frame for the application. Other components of the application are organized into tabbed panes. Each of those tab objects has white text and the background color blue. Later, you'll learn what goes on each pane and how to develop those objects. For now, you'll learn about frame and tab objects.

Frame and Tab Ojbects
Result of creating frame and tab objects

You will start with designing a few objects (the frame and tabs), then build on those classes as you progress through the lessons.

Follow these steps
  1. Take a look at the first class you are going to create: DiveLog.java.
  2. Note the syntax of how the names are written, paying special attention to which words start with uppercase letters and which do not.
  3. Look at positions where the curly braces are placed.
  4. Open your text editor to start your first class.
  5. Copy and paste this line of code into your text editor:

  6. package divelog;
    
  7. Save the file, naming it DiveLog.java

Every class in the Dive Log starts with:

package divelog;
What is the purpose of the keyword package?
   A. Group and store related classes in a container.
   B.  Make the classes in a package accessible to the compiler.
   C.  All of the above.