Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Object Oriented Programming: Installation Notes for Java/BlueJ/javabook

Object Oriented Programming: Installation Notes for Java/BlueJ/javabook

These notes are for use in conjunction with the CD supplied by McGrawHill. These notes assume you are familiar with using Windows Explorer(not Internet Explorer). If you lose your hardcopy of these notes, a"soft" copy is available, from a link on the subject web page.

This installation is suitable for all Microsoft "Win 32"operating systems. That is, it is suitablefor Windows 95 or any laterMicrosoft operating system. This installation is *NOT* suitable forApple computers!

1. Installing Java (SDK, version 1.3.1)
Load the CD and "point" Explorer at the CD. Go down into the foldercalled "pc", and again go down into the folder called"sun_jdk". Double Click on j2sdk-1_3_1-win.exe Eventually, a largewindow will pop up, taking up most of the screen. (Actually, this isanalogous to the MainWindow class in the "javabook" package from thetextbook author, Wu. This large window will be the backdrop upon whicha series of dialog boxes will now appear.) This window will contain alongish message which begins with "Welcome to the Java Development KitSetup Program". Click on "Next".

A licence agreement will pop up. Don't worry too much! You qualify touse this version of Java. Read the licence agreement, then click on"Yes". (If you don't want to agree to the licence agreement, thenclick on "No", and start planning to spend a lot of time at UTS workingon computers which do have Java and BlueJ.)

The next box that pops up contains a message that begins "Setup willinstall Java Development Kit in the following folder". Further downthe screen (past most of the message) will appear the path to thatfolder:

C:\jdk1.3.1

We will assume that your hard drive is the "C" drive as it is on mostPCs. (If not, then be aware that the rest of these notes make thatassumption and you will have to adapt the notes accordingly.)

Click on "Next". (Unless you want to install Java on a drive other than"C", in which case click on "Browse". This is the last time in thesenotes where special mention will be made for people installing on adrive other than "C".)

From this point on in the installation of Java, if something goes wrongand you need to abort the Java installation, you can start from thebeginning again. But before you do, delete the folder "C:\jdk1.3.1".

The next box that pops up contains a message that begins "Select thecomponents you want to install". All the components should already beselected. If that's the case, just click on "Next".

The installer will now go to work. Eventually, a box will pop up withthe message "The Java delopment Kit Setup is now complete". Just clickon "Finish".

You have successfully installed Java!

2. Installing BlueJ, version 1.1.4
BlueJ is a software tool that helpsus write (and run) Java programs, just like Microsoft Wordis a software tool that helps us write documents. BlueJ andJava are not the same thing. In common IT slang, BlueJ runs"on top of" Java.

Using Explorer to browse the CD again, go down into the foldercalled "pc" again, and then find the file called "bluej-114".(By the way, iyo might notice that the type of this file is "ExecutableJAR file", where "JAR" stands for "Java ARchive. Such "dot jar"files are a common way of storing java programs. BlueJ is actuallya program written in Java.) Double click on "bluej-114".

As with the Java installation, we will assume that you are installingonto the "C" drive. A window will pop up with a picture of a"Blue Jay" in it, and the title "BlueJ Installer". (A "Blue Jay" is aNorth American bird. In the Java community, it is common to attacha J-for-Java to the name of Java related softare products. Forexample, some of you may have heard of the software tool "JBuilder".)

Unless you are installing on a drive other than "C", check that:

"Directory to install to" is c:\bluej1.1.4

and

"Java (JDK) directory" is c:\jdk1.3.1

If necessary, change the information shown so that Directory toinstall to" and "Java (JDK) directory" are what is given above.Then click "Install".

When the installation is finished, click "Done".

2.1 Installation Problems with BlueJ
If you have problems installing BlueJ, first check out the BlueJFrequently Asked Questions (FAQ) web page ...

See section 2 "Technical Problems", subsection 1 "InstallationProblems". A very common problem on older machines (e.g. Windows 95)will be "Out of Environment Space". There is an FAQ entry forthat problem.

If you still can't get things working, talk to the OOP lecturer.BUT BE WARNED! (1) "Talk" means face-to-face. It does not meanemail. Any email on BlueJ installation problems will not receivean answer. (2) The lecturer's first question to you will be, "Have youread the FAQ?". In a university environment, we are happy tohelp you, but only if you demonstrate that you have firsttried to help yourself. Its not that we don't want to help, itsjust there are many students to help, and so we concentrateon helping those students who have tried to help themself.

2.2 Checking the Installation by Running "Shapes"
You should now run BlueJ to check that the installation hasworked correctly. To do that, "point" Explorer into C:\bluej1.1.4.You will see a file called "bluej". Right click on it. A windowwill pop up, and you should select "Open". BlueJ should start up.

You should then be able to open the "Shapes" project, and run it,just as you did in the first lab exercise at University, but with oneminor difference. When the various classicons for this project appear ("Square", "Circle", "Triangle") noticethe diagonal lines in the bottom half of each icon. These diagonallines were not present when you ran this project at university. Theselines mean that the Java source code (ie human readable code) for thisproject has been loaded, but that source code has not yet been compiledto produce the machine exeecutable "Java Byte Code". To compile thisproject, just click on the "Compile" button. The compilation processis not instant. It will take a few seconds. When compilation iscompleted, you should be able to run "Shapes", and verify that yourJava and BlueJ installations have succeeded.

2.3 Runtime Problems with BlueJ
If you had a problem running BlueJ, first check out the BlueJFrequently Asked Questions (FAQ) web page ...

See section 2 "Technical Problems", subsection 2 "RuntimeProblems". If that doesn't help, see the lecturer face-to-face.

2.4 Running BlueJ via a short cut icon
(This section is an optional part of the installation, regarding somecosmetic issues in running BlueJ. If you can't perform this part ofthe installation, you might try asking a fellow student to show you.The lecturer won't be taking the time to show you, since its onlya cosmetic issue, and there are more important things for him to talkabout with you and other students!)

Right clicking on "bluej" in c:\bluej1.1.4 and selecting "open" is one way thatyou can start BlueJ in the future.

Another way to start BlueJ is to create a short cut, ifyou know how. After dragging the short cut icon to the desktop, right clickon the icon, select "properties", and go to the "Program" tab. In the"Run" field, select "Minimized" and then "OK". This small (andnot terribly important) change will mean that the MS-DOS windowassociated with BlueJ will not appear on the screen, but merely as aminimized icon on the toolbar.

If you have created a "short cut" icon, it will appear as a generic"MSDOS" logo followed by "Shortcut to bluej". That's a workableicon, but not a very pretty icon. You can change to appearance ofthe icon to the BlueJ "bird" icon, as follows. Right click on theicon and select "properties" again. Go to the "Program" tab, andselect "Change Icon". Another window will pop up. Select "Browse"and select the file "C:\bluej1.1.4\lib\bluej.ico". Hit open, then"OK". the window will disappear, and you should then select "OK"on the main "Shortcut to bluej Properties" window. After amoment, the icon should change to show the "bird" picture.

3. Installing "javabook"
The "javabook" is not part of standard Java or BlueJ.It is a set if "library" classes supplied by Thomas Wu,the author of your textbook.In many java programs given in Wu's book, there is a line of code thus:

import javabook.*;

This line tells the java compiler to bring into that program ALLthe classes available in the "javabook" library. (That's what theasterisk means, "all".) So, if you are going to run, on yourhome PC, any program from Wu that contains that "import" line, youwill need to load Wu's "javabook" class library onto your PC.

The current CD does not have "javabook" on it. Instead, you need todownload it from the McGraw-Hill web site for Wu's book ...In the table on that web page, on the second row, immediately below "To download click the link below...", you will see a hyperlink "javabook". Leftclick on that link and save it to C:\bluej1.1.4

Make sure that the copied "javabook" folder on your C drive startswith the lower case letter "j", not the upper case "J".

3.1 Editing bluej to change the "Classpath" variable
When the Java compiler encounters an "import" statement, from whereon your computer does it import the files? The Java system searchesthe "class path". The class path is a series of folders. The Javasystem looks in the first folder, then the second,and so on until it either (1) finds the class that it has been askedto import, or (2) exhausts all the folders listed on the class path.

The classpath information is specified to the Java system in the"bluej" file. Using Explorer, right click on "bluej" andselect "Edit" (NOT "Open").A Notepad window will pop up, showing you the contentsof "bluej". (These note assume you know how to edit and save inNotepad.)

3.1.1 First Change: Changing the Application Base
On about the third line of "bluej", you will see a line that BEGINS ...

set APPBASE=

If the complete line is NOT ...

set APPBASE=c:\bluej1.1.4

Then change that line so it does.This line is saying "Every time you see APPBASE in the rest of this file,surrounded by percentage signs, substitute for it C:\\bluej1.1.4". The word"APPBASE" is short for "Application Base". BlueJ is our applicationprogram. All files associated with BlueJ are stored in its base folder.

3.1.2 Second Change: Adding %APPBASE%\javabook to the Class Path
In "bluej", you will find the line that specifies theclasspath. Its the line beginning ...

set CLASSPATH=%APPBASE%\lib\bluej.jar;%APPBASE%\lib\antlr.jar

Let's take a closer look at the part after the "=" sign and before the semicolon ";" ...

%APPBASE%\lib\bluej.jar

You've already been told that "%APPBASE%" should be substituted, to give ...

C:\\bluej1.1.4\lib\bluej.jar

This is the first file of the class path. That is, its the first placewhere the java system will look for any files that need to be imported. (The "jar" stands for "Java Archive File".)

Now look at what's between the first and second semicolon ...

%APPBASE%\lib\antlr.jar

Once again, substituting for %APPBASE" gives ...

C:\\bluej1.1.4\lib\antlr.jar

That's the second place where the java system will look for any filesthat need to be imported. There are more files on the classpath,but you get the idea.

Now, here's the change. Immediately after the "=", insert the following ...

%APPBASE%;

Don't forget the semicolon! The modified line now commences ...

set CLASSPATH=%APPBASE%;%APPBASE%\lib\bluej.jar;%APPBASE%\lib\antlr.jar

We are now telling the Java system to firstlook in the application base "C:\\bluej1.1.4" before it looks anywhere else. That is the place to where we copied "javabook" off the CD.

If you are running BlueJ while you make this change, you will need torestart BlueJ before this change to the class path wil take effect.

3.1.3 Verifying the Changes
Now do the "FunTime" and "DisplayMessage" exercises from your first set oflab notes. If these exercises compile and run correctly, then yourinstallation of "javabook" is working.

If you cannot make javabook work, then naturally talk to your lecturer.But remember, "talk" means face-to-face, not email. Email on installationproblems will be ignored. Also, be very clear that it is javabook thatis causing problems. Don't wait to be asked "Did you get the Shapes exercise working?" Start by saying to the lecturer, "I got Shapes working,but I have a problem with javabook, because I can't get FunTime to work."This may seem silly, until you remember that you are probably the 50th personto speak to the lecturer about an installation problem.

The best way to get help from the lecturer with fixing up your javabookinstallation will be to print off acopy of "bluej" and show that to the lecturer. Until he has seen that,there is not much he can do to help.