Document Sample
Installing Powered By Docstoc
					Getting, installing and testing the
            Java SDK

           Java Programming: Installing the   1
                       Installing SDK
   Make sure you have room! (150MB).
   Download the appropriate file from
     – Get the JDK Standard Edition 1.4.1
         » Java version one is Java 1 and Java 1.1
         » Java version two is Java 1.2, Java 1.3 and Java 1.4 (Do not be confused by
           these numbers)
   Run the file (start the installation). Install somewhere easy to access, I
    like c:\jdk1.4
   Download and install documentation
     – Java 2 SDK Standard Edition documentation.
     – HTML files.

                             Java Programming: Installing the                           2
    PATH Environment Variable
   To run the tools (compiler, JVM, etc) from
    the DOS command line you need to add the
    location of the tools to your PATH.

                 Java Programming: Installing the   3
      What is a DOS search path ?
   The concept of a search path came from DOS, which inherited from UNIX, etc
   The search path is a list of directories that DOS/Windows will search for
    executable files
   You can view the current search path by creating a DOS Prompt (Start |
    Programs | MS-DOS Prompt). You will see a DOS prompt that looks
    something like :
     – C:\WINDOWS>
   At this prompt, type the command „PATH‟, and you will see output similar to
    the following:
    We need to place one of the directories that the JDK installation created on
    the search path, specify the bin directory. We do this with the command:

                             Java Programming: Installing the                       4
       CLASSPATH environment
   The Java compiler and VM use the CLASSPATH environment variable to
    decide where to look for class definitions (Java code).
   Very similar to the PATH environment variable in DOS
   It is set in a similar fashion.
     The CLASSPATH is kept as a DOS environment variable, and can be viewed
    with the „SET‟ command. The SET command will display a list of all the DOS
    environment variables and their values. The one we‟re interested in is the
    CLASSPATH variable:
     – C:\WINDOWS> SET
       CLASSPATH=.;C:\j2sdk1.4.0;C:\j2sdk1.4.0\bin ("." is the current directory ).
   This CLASSPATH setting has 3 directories: ‘.’ which represents the current
    directory (whichever directory you‟re working in right now); C:\jdk1.2, and

                              Java Programming: Installing the                        5
         Batch files to source your
          environment variables
   You can use your favorite editor to create a txt file in the
    root directory called “SETUP4JAVA.bat”
   Insert the following lines into this file:
     @ECHO OFF
     PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\j2sdk1.4.0\bin
     SET CLASSPATH=.;C:\j2sdk1.4.0;C:\j2sdk1.4.0\bin
   Now, each time you start an MS-DOS Prompt, you only need to type
    the single command:
   There are several techniques for setting the search path and class path
    permanently. However, these require several steps and can be very
    confusing if you don‟t already know how to modify your environment,
    so they are not included here. Books on Windows can help you in this

                           Java Programming: Installing the               6
             Testing things
 Typically you need to reboot to have any
  changes to the PATH take effect.
 Open a MS-DOS prompt window
  (command prompt for Win2K and up).
 Type "java –version". If you get
  "unknown command" or something like
  that, your PATH is not right…

               Java Programming: Installing the   7
           Organizing your work
   In general, you do the following:
    – create a folder to hold the java code.
        » Recommended is creating a directory such as
          C:\JAVAPROGS, and then additional directories for each
          homework assignment, e.g. C:\JAVAPROGS\HW1, so your
          directory structure would look like:


            Windows     j2sdk1.4.0             JAVAPROGS

                                         HW1               HW2

                      Java Programming: Installing the             8
General process in writing Java
– use an editor (notepad will work, but other editors will
  work better – check out editplus at
  to create a Java program. You may use commerial
  packages like Visual Café, Jbuilder, and CodeWarrior
  is a few to mention. But most of these add in
  unnecessary complexity and may introduce a new
  source of error which you will not be able to detect.
– compile the program (using javac)
– run the program (using java)

                 Java Programming: Installing the            9
    Example directory Structure of a
        Windows installation
   The bin directory contains the
    java complier and the java                                       \

    virtual machine
   The includes directory has c                                                   j2sdk1.4.0

    header file for native code
   jre (java runtime) has                      Command       bin        include         jre    lib

    executeable for the runtime
    and also the Class libraries                      javac   java          appletviewer

   Lib contains some of the
    class libraries used by the run
    time executables

                        Java Programming: Installing the                                  10
    Sun "first cup of Java" tutorial
   on the web at:

Goes through all the steps, explains how to
 resolve common problems

                 Java Programming: Installing the   11

Shared By: