Software Installation for CS121 1 Installation of Java J2SE by msz78385


									                              Software Installation for CS121

                                         Dr. Lixin Tao
                                 Computer Science Department
                                        Pace University

                                         August 26, 2005

1   Installation of Java J2SE 5 SDK
    1. Visit “Start|Settings|Control Panel|Add/Remove Programs” to remove any of existing
       installations of Java SDK or JRE (Java runtime environment). Make sure you reboot the
       system before you install any new software. After rebooting, delete the installation
       directories for those removed installations. Let a PC have multiple Java installations may
       lead to confusion.
    2. Visit with a Web browser. Click on hyperlink
       “Download JDK 5.0 Update 4” to get to the J2SE 5 SDK download page. Check the
       checkbox for accepting license agreement. In the section for “Windows Platform – J2SE
       (TM) Development Kit 5.0 Update 4” section, click on the hyperlink “Windows Offline
       Installation, Multi-language” to download the installation file “jdk-1_5_04-windows-
       i586-p.exe” to your PC. The file has 56.71 MB.
    3. In a Windows Explorer, click on the downloaded file “jdk-1_5_04-windows-i586-p.exe”
       to start its installation. Accept the license agreement, and take all default values. By
       default, your J2SE 5 installation directory will be “C:\Program Files\Java\jdk1.5.0_04”.
       The installation of J2SE 5 will take about 120 MB of disk space. You only need the
       installation of JDK 1.5, which includes JRE (Java Runtime Environment) 1.5. After the
       JDK 1.5 is installed, you will be prompt for installing an external version of JRE, and you
       can just cancel it.
    4. To run Java compiler javac and interpreter java on the command-line, you need to add
       the bin directory of your J2SE 5 on the environment variable PATH. An environment
       variable is a memory location where the operating system keeps some values for
       programs to access. When you type a command “javac” and then ENTER in a Command
       Prompt window, for example, the operating system will try to find whether there is an
       executable file named “javac.exe”, “java.bat”, or “” on your PATH. The value
       of PATH is a sequence of directories separated by semicolon “;” in DOS and colon “:” in
       Unix/Linux. Period (.) is used to represent the current working directory (the directory in
       which the command “jacac” is typed). The operating system will sequentially try to find
       an executable file for “javac” in the directories on the PATH, from left to right. The first
       executable file with file stem name “javac” will be executed. If the operating system
       completed the search” in all directories on the PATH and none of the executable files for
       “javac” could be found, the operating system will declare that “`javac’ is not recognized
       as an internal or external command, operable program or batch file.”

       Right-click on “My Computer” and choose “Properties” from the popup menu. In the
       “System Properties” window, click on the “Advanced” tab. Click on the “Environment

   Variables” button. In the bottom “System variables” area of the “Environment Variables”
   pane, click on button New to launch the “New System Variable” pane. Enter value
   “JAVA_HOME” for variable name, and value “C:\Program Files\Java\jdk1.5.0_04” for
   “Variable value”, as shown below. (If you use a Java SDK installation at another
   directory, you should update the variable value accordingly.)

   Click on the OK button to compete the definition. Now click to highlight the line for
   “Path” in the “System variables” area, and then click on the “Edit” button. In the
   “Variable value” textbox, move the cursor to the left end, and insert
   “%JAVA_HOME%\bin;” at the beginning, as shown below. Here “%JAVA_HOME%”
   is to be replaced with the current value of environment variable “JAVA_HOME” by the
   operating system.

   Click on the OK button to complete the modification.

5. Now you also need to set up the value of environment variable CLASSPATH, which is
   used by “java” and “javac” to find needed Java classes. When you type “java Hello”, the
   command “java.exe” will follow the value of environment variable CLASSPATH, from
   left to right, to search for the first file “Hello.class” to execute. The value of
   CLASSPATH is a sequence of directories for storing Java class files. Period (.)
   represents the current directory in which you typed “java Hello”. If there are multiple
   instances of file “Hello.class” in different directories on the CLASSPATH, only the first
   one will be executed. If there is no file “Hello.class” in any of the directories on the
   CLASSPATH, command “java” will declare that “Exception in thread "main"
   java.lang.NoClassDefFoundError: Hello”.

   In Windows Explorer, create a new directory “C:\classes”. This will be the directory
   where we keep all Java class files. In the bottom “System variables” area of the
   “Environment Variables” pane, click on button New to launch the “New System

       Variable” pane. Enter value “CLASSPATH” for variable name, and value “.;C:\classes”
       for “Variable value”, as shown below. The value of CLASSPATH is a list of semicolon-
       separated directories. The first period (.) represents the current directory.

       Click on the OK button to compete the definition. Click on the OK button of the
       “Environment Variables” pane to shut it down. Click on the OK button of the “System
       Properties” window to shut it down.

    6. To test whether you have done correctly, click on “Start|Run…”, type “cmd” in the Open
       box, and click on the OK button to start a Command Prompt window. Type “javac” and
       the ENTER key in the window. If you see usage information of “javac”, you have
       completed this step successfully. Otherwise you need to carefully redo this step.

2   Customizing Properties of Windows Explorer
For software developers, Windows Explorer should show detailed view of files, and file
extensions of known types should be displayed all the time. This section introduces some useful
customizations to your Windows Explorer for better supporting Java programming.

    1. Click on “Start|All Programs|Accessories|Windows Explorer” to launch an instance of
       Windows Explorer.
    2. Click on “View|Details” to turn on the detailed view. In the right pane, each file or
       directory will be represented by a line specifying its name, size, type, and date modified.
    3. Click on “Tools|Folder Options…” to launch the Folder Options pane. In the Folders
       Options pane, click on tab “View”. Make sure that you have checked on options “Display
       the full path in the address bar”, and unchecked options “Hide extensions for known file
       types” and “Remember each folder’s view settings”, as shown in the following screen

   Click on button “Apply to All Folders” so all Window Explorer instances will have the
   same folder options as this one.
4. Click on tab “File Types”. In the “Registered file types” list, click on the line for
   “(NONE) Folder”, as shown below:

5. Click on the “Advanced” button to launch the “Edit File Type” window. Click on the
   “New…” button in the “Edit File Type” window to launch the following “New Action”
   window. In this “New Action” window, type “Command Prompt” in the “Action” field,
   and “cmd.exe %1” in the “Application used to perform action” field, as shown below:

6. Click on the “OK” button to shut down the “New Action” window. Click “OK” button
   again to shut down the “Edit File Type” window. Click on “OK” button again to shut
   down the “Folder Options” window.
7. From now on, if you need to open a Command Prompt window in a directory shown as a
   folder in the left pane of the Windows Explorer, you just need to right-click on that folder
   in the left pane of Windows Explorer, and then click on the “Command Prompt” item in
   the popup menu. The following example shows how I opened a Command Prompt
   window in “C:\cs389\inheritance”.

   and a new instance of Command Prompt window popped up as below:

3   Installation of EditPad
Visit to download and install the free Editpad Lite
text editor.

4   EditPad: Customizing Tab Size and Replacing Tab with Spaces
Start EditPad. Click on “Options|Preferences…” Click on “File Types” in the new Preferences
window. In the left upper scroll pane, scroll and choose “Java source code”. In the lower right
side of the window, set Tab size to 2, Block indent to 2, and check the checkbox for “Pressing
Tab inserts spaces instead of tab characters”. Then click on the bottom Apply button.

5   Typical Process for Creating and Running a Java Program
    1. Use a text editor, like EditPad, to create a Java source file which must have a file
       extension of “.java”. For example, you could create a new Java source file
       “C:\cs121\” that has contents as follows:

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

    2. Open a Command Prompt window and change directory to “C:\cs121” (see the next
       section for some tutorial on using DOS commands). If you have followed my
       customization of the Windows Explorer, you could achieve this by right-clicking on
       folder “C:\cs121” in the left pane of a Window Explorer, and then click on the Command
       Prompt item of the popup menu.
    3. In the Command Prompt window, type “javac -d C:\classes” to compile the
       source file “” into a Java class file “Hello.class” in folder “C:\classes”. The
       command-line switch “-d” of “javac” command is used to specify the destination of the
       class files as a result of the compilation. Learn to use switch “-d” will save your time
       when you need to declare Java classes in Java packages, as we will explain during the
    4. In any Command Prompt window, type “java Hello” to run file “Hello.class”. Since file
       “Hello.class” is in “C:\classes” and the latter is on our CLASSPATH, the “java”
       command can find it and run it.

The following is the screen capture of my session of running the above steps 2 and 3.

6   A Basic Tutorial on DOS Commands

If you are serious in a programming career or using Unix/Linux, some experience in command-
line operation is necessary.

To start a Command Prompt window, you can either use “Start|Run …” and then run “cmd”, or
click on “Start|All Programs|Accessories|Command Prompt”. If you have customized your
Window Explorer as I explained earlier, you can also right-click on a directory in the left pane of
a Window Explorer and then click on the Command Prompt item of the popup menu, which will
lead you directly to the directory for working on.

You can change your working directory by using changing directory (cd) command, as in the
following examples:
    • To work on drive C: (suppose you are not on drive C: now), type “C:” and ENTER.
    • To move up to the top level of your drive C:, type “cd \” and ENTER.
    • Suppose you are now at “C:\”. To change directory to “C:\cs121”, type “cd cs121”.
    • To move up working directory by one level, type “cd ..”

To create a new directory named “src” in the current directory, type “md src”. Here “md”
means Make Directory.

To delete a directory named “src”, you first need to make sure that directory “src” is empty.
Then you type “rd src”. Here “rd” means Remove Directory.

To delete a file “Hello.class” in the current directory, type “del Hello.class”. To delete all Java
class files in the current directory, type “del *.class”.

Normally, Windows Explorer is easier for creating/renaming/deleting directories and files.

To duplicate a Command Prompt window, type “start” and ENTER in the current Command
Prompt window.

To check the definitions of the environment variables on your PC, type “set” and ENTER.

To check the definition of environment variable “PATH”, just type “path” and ENTER.

To temporarily change the definition of environment variable CLASSPATH to “.;A:\classes”,
type “set CLASSPATH=.;A:\classes”. This change of value for CLASSPATH will only have
effect in this current Command Prompt window. This could be useful if you want to put your
floppy disk’s directory “classes” on the CLASSPATH.

If you need to type a long name of a file in the current directory, you can type its initial letters
and then type TAB for auto-completion. For example, for compiling the “” file in my
previous screen capture, I could have typed “javac –d C:\classes H” and then TAB, the command
will automatically completed as “javac –d C:\classes”.

7   A Note for Storing Programs on Lab PCs

During lectures and lab sessions we will use lab PCs to work on Java programs. Your files can
be stored on drive C: for better performance. But the files on lab PCs will not survive PC reboot.
It is highly recommended that you copy your source files and folder “classes” from your floppy
disk or USB memory stick to the drive C: of your working lab PC at the start of a lab session,
work through the lab session on the drive C: of your working lab PC, and copy your “C:\classes”
and other new source files created during the lab session to your floppy disk or memory stick for
keeping them and porting them back to your home PC.


To top