Title: StartingOut
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Class Setup

PC at WCC

If you create a DOS window at WCC, you will have a JDK1.3 environment already setup for you.

If you login as CIS278, you will also see in the Novell Application Launcher (NAL), a JDK1.1.8 environment as well as JDK1.3 environment. These clickable DOS windows load JDKs from the network G drive. The JDK1.3 environment on the G drive should be the same as the default JDK1.3 environment on the C drive.

Linux from the internet

If you have internet access, then you can use
gettysburg.wccnet.org

Login to the account given to you by your instructor. Please set your password on the first access using the command:
passwd

Use a telnet program to connect to gettysburg.wccnet.org and login to this Linux Host. In order to setup your Java account, you need to do the following things:

1. Add the following line to the end of the .bash_profile file found in your home directory:
.  ./my_profile
2. Create a file named my_profile in your home directory that contains the following command:


export JAVA_HOME=/usr/local/jdk1.3.1
PATH=/usr/local/jdk1.3.1/bin:$PATH
export CLASSPATH=.:$HOME/classes:/usr/local/jdk1.3.1/classes


3. After saving my_profile, execute the following command:
chmod a+x my_profile
4. An easier way to do this is to ask your instructor to setup his account and give you the commands to copy the appropriate files from him.
5. Logout and log back into gettysburg
6. Testout your Java environment with the following program:


  class hello {
       public static void main(String[] args){
             System.out.println("hello world");
       }
     }


7. If you need some tips on Linux, you can follow the notes:
Linux Tips
8. If you need the pad program, or a telnet client like teraterm, check out the following link:
Tools

Running Java 1.1.8 to get Applets to work

If you want to compile applets with an older version of the compiler so that it has a better chance of working in a browser, create a file called my_profile2 and give it the contents:

export JAVA_HOME=/usr/local/jdk118
PATH=/usr/local/jdk118/bin:/usr/local/bin:/bin:/usr/bin:/usr/sbin
export CLASSPATH=.:$HOME/classes:/usr/local/jdk118/classes


Then issue the command:
. ./my_profile2

If you want to go back to the newer version of java, relogin again.

Useful Links:

Java Documentation in Windows Help Format :
http://www.confluent.fr/javadoc/javadoce.html

Electronic Copy of Thinking in Java: Good book for Java Basics:
http://www.BruceEckel.com- you will have to pick from a lot of options here. By the way the version I have on my T drive account is the first edition. It looks like he now has a second edition available.

Acquire Java2 software (version 1.3 or the 1.4 beta) - From here you can find Downloads and documentation

Setting Up Java on a PC

Getting Started

This document contains the things you need to do to setup your Java environment.

- We will start out using Java 1.3 for this class. The 1.3 version is not directly supported by Netscape 4.xxx, or I.E 4.xx browsers. To run 1.3 applets, you need plugin support. We won't be doing a lot of applet work in this course because this was the emphasis in CIS277. We will use the appletviewer if we have trouble due to browser support. We will be using Java 1.3 on Linux later, but most of this will already be set up for you.
If you want to install the JDK at home, follow the above java2 software link. This link allows you to download the JDK from the Sun corporation.
- The last step to getting your JDK operational, involves setting up your DOS environment. I would recommend create a BAT file that automatically sets everything up for you rather than typing it all in each time you want to run Java. The following link works for me on my Windows 2000 machine. It can be adapted to other Window versions --- read the Comments(REM statements)
jdk1_3.bat
- Once you have set up your path, then the key programs available to you are javac, java, and appletviewer. If you use the WCC Novell T: drive installation, the appletviewer was renamed to appletvi to be within an 8 character limit.
- It's also nice to have the Sun Online documentation for 1.3. You can get this file from:
Sun_Documentation.
I would recommend choosing the ZIP file format version. Double click on the downloaded file to install it.

If you are uncomfortable with DOS and basic Windows commands, please check out the following linke:
Dos_Windows_Help

Normal JDK Operations Using MS-Dos

- Once you have completed this, all you need to do is go to some directory on your PC and start programming. The compiler is javac, the command line virtual machine execution enviornment program is java, and the appletviewer allows you to test out your applets without actually using a web browser. It's also handy to be aware of the DOS edit program. This works well enough that we may use it instead of wordpad or notepad.

Compiling and Execution

Once you are properly setup, you would compile a program named Xyz, by entering the following command:

javac Xyz.java

To execute the compiler output, you issue the command:

java Xyz

PAD Program

Because you will be doing a lot of Text file editting, I would recommend that you also install the Pad Program:

Get the Pad Program

Primitive Debugger -- Normally too painful to use

There is a primitive debugger named jdb which can be used to step through your program. The jdb program is very similar to the standard "C" debugger program called dbx. Often it's easier to debug with the System.out.println capability. However, it's good to know how to use jdb just in case you can't find your problem any other way. For example, suppose you are debugging a class named Factorial(This code exists in the language section of the Java notes). The following steps/commands would be useful to you.
- Compile your program with the "-g" option to put debugging information into your class file. The compilation command would be:
javac -g Factorial.java
- Suppose you want to run your program with 2 parameters of "8" and "aaaaa". Then to run your program in the jdb debugger, issue the following command:
jdb Factorial 8 aaaaa
- At the first prompt in jdb, your Factorial program will be loaded but not started. You first want to set a break point inside your program such as the following:
stop in Factorial.main
Now type the command run. This will start your program and stop at your first break point.
- At this point you can issue commands like help, next, step, step up, cont, print n, locals, stop at Factorial:22, and quit. There are other commands that can be found with the help command. Note that Source file line numbers are needed for specifying break points. You might want to use the Pad program for this.
  1. next - takes you to the next instruction in this routine. In this command we step over function calls.
  2. step - takes you the the next instruction including jumping into function calls if they come up.
  3. step up - takes us out of the routine we are currently in and into the routine that called us.
  4. stop at Factorial:22 - sets a break point at line 22 of the Factorial class.
  5. cont - Continue execution until the next break point occurs
  6. locals - Print out the local variables of this routine.
  7. print n - Print out the value of variable n
  8. quit - exit this debugger