Macintosh


This section will walk you through downloading and installing Java on Macintosh-based computers.

You download Java for Macintosh directly from Apple Computers. You will need three separate pieces:

  • Mac OSX Developer Tools

  • Java 1.4.1 Developer Tools Update

  • Java 1.41. for Mac OS X and QTJava

First you will need to register as an Apple developer. This is free (as are the downloads), but you must do it before you can access the download sites. Just type this into your browser:

http://connect.apple.com

This will take you to the Apple Developer Connection site. From here, you can log in and download the software you want. If you are not yet a member, you must become one. Click the Join ADC button on the left side of the page, and answer the questions on the form. You're granted a user name and password to log in to the download site.

Once you've obtained your membership, go ahead and log in (same site as above). On the resulting page, click the Download Software link. You see a list of software packages along the left side of the page. Click on the Mac OS X link, and you see a list of possible items for download. Click the Download button immediately to the right of Dec 2002 Mac OS X Developer Tools. Downloading commences immediately. This file, Dec2002DevToolsCD.dmg, is 301.2MB and takes a little over an hour to download over a DSL line. Make a note of where you store the file on your local hard drive.

Now you need to update your Developer Tools. Use the Back button on your browser to return to the list of downloadable items. This time, choose Java. Click the Download button immediately to the right of Java 1.4.1 Developer Tools Update. Downloading commences immediately. This file, Java141Developer, is 48.6MB and takes about 20 minutes to download over a DSL line. Again, make a note of where you store the file on your local hard drive.

Lastly, you need to get the most recent version of Java for the Mac (1.4.1). Use the Back button to return to the list of downloadable items. Choose Java again. Click the Download button immediately to the right of Java 1.4.1 Update DP102. Downloading commences immediately. This file, Java141Update1DP102.dmg, is 37.4MB and takes about 15 minutes to download over a DSL line. Make a note of where you store the file on your local hard drive.

Now it's time to unpack and install the three files you've downloaded. First, the developer tools. Use Finder to navigate to the folder where you've placed the downloads. Locate the file Dec2002DevToolsCD.dmg, and double-click on its icon. You still need to be connected to the network during this process, because the .dmg file will attempt to mount the disk image of the Developer's Tools package for subsequent installation. You also need administrator-level permission to complete the installation. If all goes well, a small window labeled December 2002 Dev Tools appears. Double-click on the Developer icon and proceed with the installation as directed. When the installer asks you for a destination, select the default, Normal. When the installation has finished, you must reboot your computer before proceeding to the next installation.

Next it's time to unpack and install the Java update. Use Finder to navigate to the folder where you've placed the downloads. Locate the file Java141Update1DP102.dmg and double-click on its icon. A small window labeled Java 1.4.1 Update 1 appears. Double-click on the Java1.4.1Update1.pkg icon and proceed with the installation as directed. When the installer asks you for a destination, select the default, Normal. When the update has been unpacked and installed, you're directed to restart your computer.

Now it's time to unpack and install the Developer Tools update. Use Finder to navigate to the folder where you've placed the downloads. Locate the file Java141Developer.dmg and double-click on its icon. A small window labeled Java1.4.1 Developer Update appears. Double-click on the Java1.4.1Developer.mpkg icon and proceed with the installation as directed. When the installer asks you for a destination, select the default, Normal.

Now all the Java files are in place. Create a directory where you will write Java programs. You can call it whatever you want and put it wherever you like, but simpler is better. Here we'll assume your programming directory is called ~\MyJavaCode.

The next step is to add two lines to your .login or .cshrc file for setting your path:

set path=(lib:/usr/local/bin:/usr/ucb:/bin:/sbin:/usr/bin:/usr/sbin:/usr/etc:/  Developer/Tools) setenv CLASSPATH .:/AnimatedIllustrations alias gotoJava 'cd ~/MyJavaCode'

The first line tells the operating system where to look for executable files when you run a program from the command line of a terminal window. That's how you will run the animated illustrations, and compile and execute your own programs.

The second line sets the CLASSPATH environment variable to the current directory, plus the directory on this book's CD-ROM where the animated illustration programs are stored. The script assumes you have copied the entire CD-ROM to a directory on your hard drive called /AnimatedIllustrations. Doing so will make life simpler, because you can run the illustrations without the CD-ROM. If you don't want to copy the CD-ROM to your hard drive, or if you want to copy it to a different directory, modify the script accordingly.

The third line of the script is an alias that will take you to your Java work directory.

To test your work, log out and then log in again so that the script will execute. Open a terminal window (Applications/Utilities/Terminal in the Finder). To make sure your script ran properly, type java -version. You get a message that tells you which version of Java is running, along with some other obscure, cryptic information that probably means something important to someone. If you get this message, you have installed Java and your PATH variable is set correctly. If the command doesn't work, make sure the full pathname of the bin directory in your script is spelled correctly, and that the directory contains java.

Now type java welcome.Welcome. You should see a simple welcoming screen. This means that your CLASSPATH variable is set correctly. If you don't see the welcoming screen, make sure the value assigned to CLASSPATH in your script is spelled correctly, and that the directory is the AnimatedIllustrations directory from the CD-ROM. If you are running the animated illustrations directly from the CD-ROM (that is, if you didn't copy the files to your hard drive), make sure the CD-ROM is in the correct drive.

That takes care of the Java program files. They are all you need until Chapter 12, where you will also need the API pages. These are a huge number of HTML pages to be viewed with the Web browser of your choice. You download them as a single zip file that you will have to extract.

You begin the download at http://java.sun.com/j2se/1.4.1/download.html. The page contains a list of several dozen products that you can download. Near the end of the list is J2SE 1.4.1 Documentation. Click on this item's Download link. After accepting another license agreement, you come to a page with a link for downloading j2sdk-1_4_1-doc.zip. Click on the link. You are prompted to specify where you want to put the zip file. Put it in a directory where you can find it easily. We recommend ~/MyJavaFiles.

To extract, use jar to unzip the documents in the j2sdk-1_4_1-doc.zip file. If you haven't done so already, run your batch file script by typing gotoJava. Unless you have done your own thing, the command to unzip the file is

jar xvf j2sdk-1_4_1-doc.zip

The jar command is one of the useful Java executables. It became usable when you ran the script and added C:\j2sdk1.4.1_02\bin to your path. Jar stands for JavaArchive. It is like Stuffit-Expander, but you run it from the command line. Fortunately, the jar file format is compatible with the .zip format, so you can use jar to extract any .zip archive.

Creating Program Files

Congratulations! You are ready to go. Right now you can run any animated illustration in the book. And please do... they are an essential part of your Ground-Up Java experience.

The other essential part of your experience is writing your own Java programs. You will do this when you work on the "write-a-program" questions at the end of the chapters, and of course you can write programs that implement your own ideas. We have already recommended that you do this in a directory called \MyJavaCode, and have your script "cd" in that directory. But now the question is, how do you create Java code? You will see in Chapter 2 that writing a Java program means creating one or more files, called source files, in plain text format, with names that end with .java.

There are two ways to create Java source files:

  • Use a general-purpose editor.

  • Use an Integrated Development Environment.

You have several general-purpose editors installed on your system, including Notepad and Wordpad. It's a good idea to start with one of these. They are good enough for small programs. Use a fixed-width font like Courier to make your code line up nicely.

As you will learn from experience, you don't just write a program. The development process is an ongoing cycle of writing, testing, and modifying. So when you think you have finished writing your program, don't close your editing window. Leave it around, because in all likelihood you will want to make modifications or fix bugs. (Yes, this could even happen to you.)

After a while, you might get a vague sense that life could be better somehow. You might be ready for an IDE, or Integrated Development Environment. IDEs are products that help you create, maintain, debug, and keep track of Java programs. Many common operations (such as compiling) are achieved with a single button click. There are lots of IDEs on the market, ranging in price from free to expensive. It would be inappropriate to recommend one here, but if you type "Java + IDE" into your favorite Web search engine, you will get plenty of information.

A good IDE is a good thing, and a great IDE will greatly enhance your productivity. But a word of warning: Your goal right now is not to create large Java programs efficiently. Your goal is to learn as much as possible about Java. IDEs shield you from repetitive tasks. Before you use them, it's a good idea to spend some time learning all the ins and outs and details of Java, so that you'll know what the IDE is shielding you from. Spend some time with a general-purpose editor before you move on to an IDE.




Ground-Up Java
Ground-Up Java
ISBN: 0782141900
EAN: 2147483647
Year: 2005
Pages: 157
Authors: Philip Heller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net