Appendix A. Downloading Java

Here are the steps to download and install the latest free Java compiler.

  1. Go to the website java.sun.com

    Click on the link to “downloads”.

    You want the most up-to-date version of the Java development kit. From time to time, Sun Marketing re-badges the JDK, using ever more silly and awkward names. Most recently, it has been called Java 2 Platform, Standard Edition (J2SE) Software Development Kit (SDK). In summer 2004, the most up-to-date version was 1.5 (yes, “Java 2” is at version 1.5).

  2. You want the SDK (the compiler, tools, and run-time library). The JRE is just the part of the SDK needed to run Java programs, but not the development tools (the JRE is a smaller download intended for users). Click through the license (it says you can use the tools for free, but you're not to use them to build any nuclear reactors).

  3. You reach a page where you choose which platform on which you will be running the compiler. Wherever you choose to compile, your executable programs will run on all platforms.

    Sun distributes compilers for Solaris, Linux, and Windows. Solaris has been a 64-bit operating system since we re-architected the kernel for Solaris 7 in 1998. Almost everyone else is still running 32-bit versions of Linux and Windows so choose one of those, unless you installed 64-bit Linux or Windows.

    If you are running something other than Solaris, Linux, or Windows, go to the home page of the manufacturer and search for their Java download. MacOS X comes with the JDK preinstalled, but new releases of Java may come out after you buy your Apple, so check the Apple website for the latest.

  4. For Windows, Sun offers an “offline” installation and an “online” one. The “offline” installation gives you the entire 50MB release in one download. (It's so big because it also installs the NetBeans IDE, the Java browser plug-in, and Java webstart). Use the offline download if you have a reliable broadband service. The result is a file that you execute to do the installation.

    The “online” download is a small (under 1MB) download of a program. When you run it, it does the real download and installation. It's restartable, if the connection is lost. There's a FAQ of common issues/answers at the download web page.

  5. When the installation wizard runs, accept all defaults and optional features (demos, source code, etc.). If you choose a different installation directory, write down where! You need that pathname (plus “in” added to the end) in step 7. For Windows, the default install is in:

    "c:Program FilesJavaj2sdk1.5.0"

    With jdk142 and later, installing Java on Windows also installs an auto update feature. It's a background program that checks for a newer release at 10pm each night. You can configure this with control panel -> (classic) -> Java -> update.

  6. Read the installation notes (this is currently a link near the top of the download page on Sun's website). Do not omit this step. The notes have information about hardware requirements, limitations, late-breaking news, workarounds, etc. Sun: this should really be popped up as the last step in the install wizard.

  7. Set the path variable on your operating system, so that you don't have to type the full pathname to the java compiler tools. The pathname will be the one you made note of in step 5, with “in” added to the end.

    In older versions of Windows, you might add the pathname to the start of the existing PATH in file autoexec.bat.

    In XP, you will navigate the following panels: start, control panel, (possibly switch to category view), performance and maintenance, system, click “advanced” tab, click “environment variables” down at the bottom of the advanced panel. Then choose “path” on the “System variables” part of the panel. Add the pathname

    “c:Program FilesJavaj2sdk1.5.0in”

    to the start of the path. Note the “in” needed on the end of the pathname. Different pathnames in the Path system variable are separated by “;” so add that too.

  8. Start a new command window, and type “path” to check what you did in step 8. You should see the entire list of directories that are checked for each command you enter, and the pathname to the java bin directory should be on that list.

  9. Type this command, to invoke the java compiler:

    javac -verbose

    You should get back a dozen lines of output, starting like this:

    javac: no source files
    Usage: javac <options> <source files>
    where possible options include:
      -g                         Generate all debugging info
      -g:none                    Generate no debugging info
      -g:{lines,vars,source}     Generate only some debugging info
      -nowarn                    Generate no warnings
      -verbose                   Output messages about the compiler

    Using no source file is even easier than the “hello world” program, and demonstrates just as well that the compiler is installed.

Now it's Hello World

Java programs are made up of code organized into classes. If you are not using an IDE, the classes go into java source files. Important classes should go in a file of the same name as the class. For example, a class called “hello” should go in a file called “hello.java”. Here is the source you can put in such a file:

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

You compile that with the command:

javac hello.java

That compilation will create a file called hello.class. It contains the executable program binary. You can run it with the command:

java hello

Note you use the name of the class, not the name of the file. Try it now. Then, on to the big picture of Java!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.39.144