Lab Manual for CS 46A, Using Java 2

by Nimi Berman and Cay Horstmann with contributions from numerous others

Preface

This manual was developed to accompany CS 46A, Introduction to Programming. It covers topics that are important to know but that CS 46A professors don't want to talk about in the lecture part of the course. It reinforces a number of topics and concepts in the course, and is recommended reading for transfer students who already know Java but are not familiar with the computing environment at SJSU.
Beginning with the Fall semester of 2004 the course instructor is also the lab instructor.

Table of Contents

Lab 1: Windows Shell Tutorial

Lab 2: Editing, Compiling, and Running Java Programs

Lab 3: HTML and Java Applets

Lab 4: Javadoc

Lab 5: Packages and Archives

Lab 6: Debugging

Lab 7: Advanced Windows Shell Tutorial

Setting Up Your Home Computer

Downloading the Java SDK for your Home Computer

DownLoading TextPad

A Free Integrated Development Environment

A Java Tutorial

Setting Up Your Home Computer

You do not need to own a computer to take this lab or CS 46A, but since many of you do have one and will want to have one at home, we tell you where and how to go about setting up a Java programming environment at home. The textbook for CS 46A comes with a CD containing a version of the Java SDK and a text editor named TextPad. If you install these two pieces of software on your computer you will have a Java programming environment that is recommended for use in the course. If you bought a used copy of the text and there is no CD, then these two pieces of software can also be downloaded off the internet. The next two sections tell you how to do this.

Downloading the Java SDK for your Home Computer

Java was developed at Sun Microsystems Inc and there is a big web site devoted to Java. It contains news, tutorials, and the software needed to develop and run Java program:

http://java.sun.com/

If you want to set up your computer with the software needed to compile and run Java programs go the java.sun.com site and click on the J2SE 1.5 SDK link in the Popular Downloads box on the right of the screen. Don't worry if the numbers are different. That just means it is a newer version.

Question: What do all those letters mean?

Answer: Java 2 Standard Edition (version) 1.5 Software Development Kit.

From here on we just call it the Java 2 SDK or simply the SDK. The SDK consists of a compiler, virtual machine, applet viewer, a large library of useful predefined classes, and a few other tools.

Back to downloading the SDK. You should be at the following web site:

http://java.sun.com/j2se/1.5.0/download.jsp

Now look at the heading, Download J2SE v 1.4.1_03 (the numbers may be different), find the version appropriate for you (probably: Windows (all languages, including English)) and click on the download link in the SDK column. That will take you to a page that gathers some optional information. Click on the download link again and you will go to another page with a license agreement. If you click on ACCEPT button and then click on Download j2sdk-1_4_1_03-windows-i586.exe an executable file will be delivered to your computer. This file about 38 MB in size and takes 15-20 minutes to download on a fast internet connection. To install the Java JDK, simply click on the j2sdk-1_4_1_03- icon to install the Java JDK.

DownLoading TextPad

The other thing you need to develop programs at home is a text editor. Any text editor will do but there is one in particular, called TextPadä , that can also be used to compile and run Java programs assuming that you have installed a Java SDK. It is shareware and can be downloaded from the following site:

http://www.textpad.com

Shareware is not free. You can download it and test-drive it. If you decide to keep it hen you need to send them a license fee. In the case of TextPad, the single license fee is $27.

A Free Integrated Development Environment

Later in your programming career, you will want an Integrated Development Environment (IDE). There are many commercial products available as well as a number of freebies. One such freebie, called Eclipse, is described in Lab 6. It can be downloaded from the following site, but you do not need it until you begin working with lab 6:

http://www.eclipse.org/

A Java Tutorial

An additional aid in learning the Java programming language is the Java tutorial located at:

http://java.sun.com/docs/books/tutorial/index.html