Programming Concepts in Java - With CD

Programming Concepts in Java - With CD

by Hume
     
 

Product Details

ISBN-13:
9780921598305
Publisher:
Holt Software Associates Inc.
Publication date:
09/28/1998
Edition description:
Older Edition

Read an Excerpt


Chapter 2: The VisualAge for Java Environment

In the first chapter a number of technical terms were introduced and some of the elements of the Java programming language were presented. There were enough details to show the basic structure of a Java standalone application program. Java programs can run in many computer platforms. Although Java programs themselves are independent of the environment used, this book shows how they can be run on a PC using Microsoft Windows 95, 98 or Windows NT under the VisualAge for Java, Professional Edition for Windows, Version 2.0 Environment. The user may require an alternative reference if another environment is used.

2.1 Beginning to Use VisualAge for Java

Most students these days have had experience running computer applications such as word processing programs or spread sheets. The basic notions of menu bars, POP-UP menus, selecting items, clicking or dragging a mouse, entering information in a dialog box, selecting a radio button, and so on are reasonably understood.

Many will already be familiar with the Windows 95, 98, or NT operating system. So we will be using these terms freely.

To begin, after any local login, click the Start button in the lower-left corner.

Now select Programs from the menu by dragging up to it and then select IBM VisualAge for Java for Windows from the sub-menu. Again select IBM VisualAge for Java from the sub-sub-menu (see Figure 2.1).

Now release the mouse button. At this stage, after a splash screen, the Workbench window appears with a dialog box labelled Welcome to VisualAge above it (see Figure 2.2). Select the button Go to the Workbench radio button and click the OK button. The Workbench window is now visible (see Figure 2.3).

The Workbench has a sub-window, the lower pane at the bottom, in which programs can be typed. Under the word Workbench is a menu bar with the labels:

File Edit Workspace Selected Window Help

These labels allow you to select the commands necessary to enter, edit, and save your Java program.

Below the menu bar is a row of icon buttons, called the tool bar. Each of these buttons can be clicked. When you place the mouse over any button, a message describing the function of the button appears. For example, clicking the first button from the left (the runner) will run the program.

Below the icon buttons is a set of tabs that says:

Projects Packages Classes Interfaces All Problems

These tabs are different ways of organizing the elements in the workspace. We will always use the Project organization. The Project tab should always be selected. At startup time the upper pane of the Workbench window will have a list of all current projects. This list also includes a large collection of ready-made classes known as the Java class libraries.

Organization of VisualAge for Java

Java programs are all classes. But not all classes are programs. Classes contain methods. If a class contains a main method it is a Java standalone application program. A standalone program may use other classes that are not programs. Classes can be grouped together in a package. Classes in the same package can use each other. They do not need to be imported.

Programs that were shown in Chapter 1 imported classes in the Java abstract windowing toolkit (awt) package by including the statement:

import java.awt.

The asterisk indicates that all the classes in the awt package could be used. The Console class of Holt Software Associates (hsa) was imported by the statement:

import hsa.Console;

In order to avoid having to import any classes that you create, it is best to keep them all in a package called the default package.

The top level for organizing Java programs is the project. Any number of packages or classes may be placed in a project. On a multi-user system, it is best if each user has a single project whose name is the user's name. This simplifies what must be done when a user starts (logs in) and stops (logs out) using the computer.

VisualAge for Java provides a number of projects. These are the class libraries that are part of the Java specification.

The projects are called:

IBM Java Implementation
Java class libraries
JFC class libraries
Sun class libraries PM Win32

In the top pane of the Workbench window, any project, package, or class with contents has a small plus or minus sign to the left of it. When the contents are hidden, the sign is a plus. When the contents are displayed, the sign is a minus sign. In. Figure 2.4, the method circle of the RedCircle class of the project JNP Hume's default package has been selected and is displayed in the lower pane of the Workbench window.

To display the packages in a project, click on the plus sign beside the project icon. The packages are displayed underneath the project. To hide them, click on the minus sign beside the project.

To display the classes in a package, click on the plus sign beside the package. To display the methods in a class, click on the plus sign beside the class. When a single class or method is highlighted in the upper pane, the lower pane displays the text of the class header or method.

Starting a Project

It is time now to start a project. As mentioned above, all of your programs should be placed in a single project. This not only prevents work from being lost, but ensures that you only have to go through the work of setting up a project once.

To start a project, click on the Project icon button (the fourth from the right) on the top of the Workbench window, selecting

Add New or Existing Project to Workspace.

A window labelled

SmartGuide -Add Project

appears (see Figure 2.5). In this window, the radio button labelled Create a new Project named: is already selected. Type in a name. It is probably best to use your own name. When this is done, click the Finish button. Your project is thus added to the list of projects in alphabetical order among the other projects in the list....

Meet the Author

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >