Introduction To Java - MFC 158 G

 Fall 2000

 

The Java Development Environment

 

 

Because developing Java on Windows or Unix typically requires that you be familiar with command line syntax (and the fact that some students may have not had experience in this area) this document should provide enough information to allow you to “easily” develop programs. 

 

Installing Java From the “Java How to Program” CD (for Windows 95/98/NT):           

 

Check to see if you have at least 200MB of space on your hard drive.  You can go to “My Computer” and right click the C or D drive (then select properties)

 

When you get to the “where do you want to install the JDK portion” of the installation, make sure that your write down the Drive letter and full directory path of where you installed the Sun JDK 1.2 (i.e. C:\JDK1.2)  We need this for a future step.

 

-          insert the CD

-          Click “My Computer”

-          Click “Welcome.html”

-          Scroll to near the bottom of the page and select “Install Win32Version”

-          Select “Run this program from current location” and click OK

-          Select yes to “Do you want to install?”

-          Click next

-          Click Yes

-          Click next

-          Click next

-          After installation, reboot.

 

Setting up your work area (directory) and sample code from the book:

 

-          from the MS-DOS prompt (or Command Prompt), you can select various hard drives on your system (if you have more than one) by typing the drive letter followed by a colon 

o          > C:

o          > D:

 

-          from the MS-DOS prompt (or Command Prompt), get to the root directory of your disk by:

o        >   cd  \    {note a BACK-slash \  instead of Unix’s FORWARD-slash  /  }

o        >   mkdir mfc158

o        >   cd mfc158

o        >   mkdir examples  (for the book samples)

o        copy the  examples directory contents into your hard drive examples directory.  This can be done EASILY using Windows Explorer.

o        You might want to create other subdirectories off of your mfc158 directory for things like  homework1, homework2, etc. as opposed to simply putting all assignments in the same directory.  That’s up to you!

-           

 

 

 

 

 

 

The Java Development Environment 

 

Setting up a “Dos” batch file for updating your path.  This allows you to easily access the Java compiler and other Java tools.  These commands could be typed in manually, but the batch file allows us to enter the commands in a file, then simply type the filename to execute all the commands.

 

 

-          Make sure you’re in the mfc158 directory and start up notepad as follows:

o        >  notepad jdk12.bat

o        We need to modify the DOS search path so that when you type “javac”, the system can find the file in the JDK install directory.  The contents of the file should look something like (copy and paste if you like).

 

REM -------- JDK12.bat - for MFC158 ---------

REM --- Setting up the PATH so the Java commands can be found.

REM --- If you installed Java elsewhere, substitute "c:\jdk1.2\bin" with

REM --- "________\bin" where "________" is the installation location

path=%path%;c:\jdk1.2\bin

REM --- Calling the program DOSKEY so that previous commands can be recalled

REM --- Using the Uparrow/Downarrow Keys

Doskey

 

Note that REM is a comment command, so only 2 commands are actually being executed in this Batch file.

 

-          save the file as jdk12.bat  (or whatever other name you choose)

 

 

Testing your installation

-          execute the batch file by typing the name of the file  (the .bat isn’t necessary, but it will also work)

o        >  jdk12  (or jdk12.bat)

o        >  java  -version     (you should see something like):  

java version "1.2"

Classic VM (build JDK-1.2-V, native threads)

-          Now test an example program. 

o        >  cd examples  (you must of course be in the mfc158 directory)

o        >  cd ch02

o        >  cd fig02_01  (this is where the book’s example Figure 1 from Chapter 2 is (pg 36)

o        >  javac Welcome1.java  (Case sensitivity is critical)

o        You should have created a Welcome1.class file

o        >  java Welcome1      (recall that you don’t specify the .class file)

You should see: 

Welcome to Java Programming!

 

-          If all worked well, you are ready to start developing Java


 

Dos and Unix Commands Comparison Quick Reference

 

DOS command

Unix command

Function

 

 

 

Directory manipulation

 

 

cd  directoryname

{note \ - back slash}

cd directoryname

{note / - forward slash }

Change directory – into a directory below the current

cd ..

cd ..

Change directory – up one level

cd \

cd /

Change directory to the root directory

***no equivalent***

cd ~username

Change directory to a user’s home directory

dir

ls – l (or ls)

List contents of a directory

dir | more

ls – l | more

List directory contents (page at a time)

mkdir directoryname

mkdir directoryname

Create a directory

 

 

 

File manipulation

 

 

copy oldfile newfile

cp oldfile newfile

Copy a file

rename oldname newname

mv oldname newname

Rename a file

move filename  directory

mv filename directory

Move a file to another directory

delete filename

rm filename

Deletes a file

type filename | more

More filename

View a file contents – page at a time

Notepad filename

xemacs filename

pico filename

Invoke a text editor

 

 

 

Command recall

 

 

doskey

No command needed

program for recalling previous commands

Up-arrow / down-arrow

Up-arrow / down-arrow

Recall previous commands that were entered

 

 

 

Java development commands

 

 

javac someprogram.java

javac someprogram.java

Compile a java program

java someprogram

java someprogram

Execute a java application (.class file)

appletviewer someprogram.html

appletviewer someprogram.html

Execute a java applet, through the reference of an HTML document

 

 

 

Miscellaneous commands

 

 

exit

exit

Exit out of environment

 

 

 

 

Getting HELP:  For more information on a command, you can do the following:

 

DOS:   command/?  {Where command is a valid command like copy, type, etc.}

UNIX:   man command {Where command is a valid command like ls, more, less, etc.}