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

Fundamentals

Getting Started on Linux:

A version of Java is installed on gettysburg.wccnet.edu which is a Linux processor. Here are the steps to using it:

1. Get your login information from your instructor.
2. Use a telnet program to access gettysburg. On any PC, you should be able to get telnet from the DOS command line
(Start-Button/All Programs/Accessories/Command). Once your are in the DOS command line, enter the command:
telnet gettysburg.wccnet.edu
3. Enter in the userid and password provided by your instructor
4. You probably would like to change this password to something else. You can do this by using the command:
passwd
5. The passwd program will prompt you for your current password. You will then be required to enter in your new password twice. The password needs to be reasonably secure or else Linux will complain. Usually a word + numbers is good enough.
6. To make setup your Linux to have access to the installed Java, issue the following commands:
cp ../c26100/my_profile .
cp ../c26100/.bash_profile .
7. You will then want exit your logged in session and login again to access the initialization files copied in the previous step. So to logoff, issue the command:
exit
8. It's usually good to keep your work organized in directories. Suppose we want to keep all of today's work in a folder with today's date. We might issue a command like:
mkdir 9_3
9. To go to this directory, we will issue the "change directory" command:
cd 9_3
10. We now want to create a java program. There are many editting options here. We will pick one of the easiest by using an editor called pico. So issue the command:
pico Hello.java
11. Enter in the source to your first program:


  class Hello
  {
      public static void main(String args[])
	  {
	      System.out.println("Hello Cruel World");
	  }
  }


12. Compile your program with the command:
javac Hello.java
13. Execute your program with the command:
java Hello
14. That's it. The advantage of the Linux approach is that you don't have to setup anything to make it work. Just use the Linux account any place where you have Internet access. We will use other approaches that will require some setup if you want to do work at home on your own computer.

I would like to edit my files on a PC, and compile on Linux

1. Edit your files any where you want on your PC. I would recommend that you keep the pathname simple so that the next step is easier.
2. Bring up a DOS command line again (Start-Button/All Programs/Accessories/Command)
3. Navigate to the location of your file with a series of "cd" commands. For example, if you have your file is Hello.java in C:\work, then you would enter in the following commands:
cd ..
cd ..
Continue until you are at the C: level
cd work
4. Enter in the command:
ftp gettysburg.wccnet.edu
5. Enter in your userid and password just as you did in telnet.
6. When ftp returns you will be in your home directory on Linux. If you want to deposit a file in a folder like 9_3, then you would enter in an ftp command of:
cd 9_3
7. Now issue the command to send your file up to Linux. The command is:
put Hello.java
8. Now you can go login into Linux and compile and execute your program.
9. If you ever want to pull the file down to your PC from Linux, then the ftp command is:
get Hello.java

Using the PC as your primary environment

Java runs on all platforms. In this section we are going to use a PC.
We will also discuss installation of Java on a PC.

You can acquire the latest Java software from:
Java2 software - From this site you can find Downloads and documentation

You can download the "SE" version and install it on your PC. You can adapt the jdk1.6.bat file described below to use this version of Java. The key thing is to change the "path" statement to point to where your Java is installed. The location with be something like:

C:\Program Files\Java\jdk1.6.0_16\bin

You also have a version of the Java software available on the CD from your textbook. You can use either for this course.

Here at WCC, we will have both versions available in the directory T:\cps161

To startup a Java environment here at WCC:

- Navigate to T:\cps161
- Double click on jdk1.6.bat to run Java version 1.6. This will startup a DOS window. Note that the environment variable named "path" tells DOS where to find programs launched from DOS like the javac or java programs. Once you are in the Java environment, the environment variable named "classpath" tells the Java environment where to locate Java libraries. This will make more sense later.
- You can look at all of your environment variables with the command:
set
Issue this command after executing your bat file and you should see the current value of the path and classpath variables.
- The above DOS bat files take you to a current directory of C:\work. Do your Java work here.

Setting up an evironment at home:

- Get the Java executable for the release of interest. I have 2 releases in C:\CPS161. You can download the latest release from Sun.com from the URL mentioned above. You can copy the executable from the CD from the back of your book.
- Execute the Java executable. You can take all defaults if you want.
- I would recommend creating a jdk.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 contains a BAT file that setup a Java environment on Windows. It can be adapted to other Window versions and other Java versions--- read the Comments(REM statements) in the following:


REM -- the following is a MUST.  Adjust if your JDK has a different pathname.
path=c:\Program Files\Java\jdk1.6.0_03\bin;%path%

REM -- I like to have a default starting directory
cd c:\
mkdir work
cd c:\work

REM -- You don't have to specify a CLASSPATH, but its a good idea
set CLASSPATH=.;c:\Program Files\Java\jdk1.6.0_03\lib;%CLASSPATH%


REM -- Finally launch ourselves into DOS.
REM -- Note that you might have to change this if your DOS executable
REM -- is located somewhere else.
REM -- This is the normal location for Windows.
c:\WINDOWS\system32\cmd.exe




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

You will also need to use an editor:

- You can use wordpad, or notepad. However, if you do use these programs, make sure that the file suffix ends with .java and the file format is text (not RTF).
- You can use the DOS edit program
- You can use the PAD program. This is a free program written by Clem that you can find in many of our CIS labs. It is also available here:
PAD Zip File

Eclipse.org

Alternatively, you can use the Eclipse Development environment. This is installed at WCC, but it can be downloaded from:

http://eclipse.org

The typical steps to using this tool are:

- Create a Project
- Create Class files for each Java Class
- Execute your source.

Eclipse will be demonstrated in class.

Last Modified: August 31, 2009 9:20 AM