Download Installing Java Basic Instructions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Installing Java
Basic Instructions
Windows Assumption
In these instructions, I assume that you are using one of the
Microsoft Windows operating systems.

This covers more than 90% of you.
If using OS X or other Apple operating system, basically the
same.

But Java is usually pre-installed. So replace what you have with the
latest release.
• You won‟t have to set a path variable.


You‟ll use the Terminal application (in your Utilities folder) whenever I
say “Command Prompt” application.
Follow Sun‟s online instructions, if uncertain.
If using Unix or Linux, then you already know what you are
doing ;-)

Follow Sun‟s online instructions, if uncertain.
What You Need
To write and run Java you need
1.
The Java Development Kit (JDK)
 Lets you write code
2.
The Java Runtime Environment (JRE)
 Runs the code
You can get both of these simultaneously


download the Java Development Kit (JDK)
Always get the latest version


this is JDK 6.0 in fall 2009
will be JDK 6.1 or 6.x or 7.x in the future
What Site to Download
The website may change with time.


It is owned by Sun, the inventor of Java.
So I‟ll tell you where to go, but you may have to be flexible and
try a different page.
Go to http://java.sun.com/javase/downloads/index.jsp

I give installation details on the following slides. But for more
installation instructions, also see
http://java.sun.com/downloads/faq.html and
http://java.sun.com/j2se/1.5.0/install-windows.html
What to Download
Get the JDK (the Java Development Kit).


If you only get the JRE, you won‟t be able to write Java.
Aren‟t you tired of acronyms yet? (AYTOAY)
Don’t get NetBeans or EE (Enterprise Edition)
or JavaFX.

…unless you‟ve done this before and know how to
handle installation problems that will crop up.
You will want to download the line that I point
to on the next page.
What to Download (Picture)
Download this.
What to Download (Which
Operating System)
After you click on the download button, you
will get a choice that depends on your
operating system.

Windows, Solaris, Linux, etc.
Assuming you have Windows, select
“Windows”. (Duh.)
The rest of the process is equally easy. Just
follow the directions and download!
What to Download (Warning)
The Sun website changes rapidly.
My description of what to download
may be obsolete in the next few
minutes.

Aurgh.    
Doesn‟t matter. Just find and
download the latest version of the
JDK.

Try to get the latest version of the JDK that
doesn‟t come with extras like JavaFX, etc.
Registering
You may need to register to download.


Don‟t worry, there is no cost.
And if you don‟t want to be spammed, just click the
buttons that say “Don‟t send me stuff”.
When you register it may take you away from
the download page.

Annoying, but don‟t panic. Just go back to
http://java.sun.com/javase/downloads/index.jsp
Installing 1
To complete the installation, one of two
things will happen.
1.
Either an installer will automatically pop up.

2.
Just click the “run” button, and follow the directions.
Or, you will need to double click the newly downloaded
file.




So remember where you downloaded it.
Go to it (it will be something like 123456789integrated.jnlp).
Double click it.
Now follow the directions.
After it has Downloaded
Now you will need to find the file you
downloaded and double-click it.

It is probably called “jre-6u16-windows-i586” or
something similar.
Most likely, it put file in the “Program Files/Java” folder.

But also look in the following locations.




C drive
Program Files
My Documents
After double clicking, a window will pop up.
Follow the directions. See the next slide!
Installing 2
Use the default options.

e.g., just install the default Development Tools as shown.
Change this!
See next page.
When you get to a page that says what folder it will
install, see next page.
Where To Put Installation 1
If you‟ve never done this before, I recommend placing on your C
drive.




simplest choice
i.e., put on your local disk (C:)
Pay attention, or you might miss the screen where you can specify
the location where you want it saved!
Note: you will have to click through a couple of screens to actually
download.
Where To Put Installation 2
If you are very comfortable downloading
apps and changing system paths, then
feel free to put the download in the
suggested Program Files.
Program Files is a better place for it.
 You will need to adjust the following directions
that I give for setting the path. Just change the
folder as necessary.

Let it Download!
This may take some time.
You will have to click several buttons
along the way before it is done.
Relax. Get a snack.
Setting The Path 1
Must tell computer where the Java lives
(the path).
For Windows XP and Vista see next slides
 If you have Windows 7, it will be very similar

Setting The Path 2
Open the Control
Panel and select the
“System” tool.

Note: the System tool
may be buried in a
another folder
depending on your
operating system. Do
a search to find it.
Setting The Path 3
Select the
“Advanced” tab and
click “Environment
Variables”.
Setting The Path 4
Select (highlight) the
“Path” variable and
choose “Edit”.
Setting The Path 5
WARNING!

Do not erase anything that is already in
your path.


The stuff that is already there is necessary so that
other programs will run.
Just insert the following text.
Setting The Path 6
Add “C:\jdk1.6.0_16\bin;”
This may be placed
anywhere in the list, but I‟d
recommend near the
beginning.
Change 1.6.0_16 to the
version you downloaded
(if you got something
else).

e.g., C:\j2sdk1.6.2_17\bin;

Also change the path if you
installed it somewhere other
than the C: drive. e.g.,
C:\Program Files\Java\jdk1.6.0_16\bin;
Notice the semicolons that
separate each value. If you
forget to put one before and after,
you’ll be most unhappy. They tell
the computer where one path ends
another path begins. Many of
your applications have a path
(e.g., the Microsoft Visual Studio
applications).
Test Your Java Installation 1
1.
Using a text editor make a file called HelloProgram.java




2.
Use Notepad
Microsoft Word
WordPerfect
Whatever
Inside this file put
public class HelloProgram
{
public static void main(String[] args)
{
System.out.println(“Hi there!");
}
}
Watch the upper case!
Java is case sensitive.
Test Your Java Installation 2
1.
Save this file to your C: drive

2.
i.e. the Local Disk (C:)
Be sure it is saved as HelloProgram.java,
not .doc, .txt or anything else.

in some cases, like MSWord and WordPerfect, you will
need to save it as a text file (.txt) and then manually
change it to .java.
•
Why not save it as a .doc and then manually change
to .java? Because programs like MSWord add lots
of extra formatting. Lots of junk is saved in your file
in addition to the simple code that you wrote. Try it,
and you‟ll see what I mean.
Test Your Java Installation 3
Start the “Command Prompt” tool.
Test Your Java Installation 4
Make sure that you are in the
C:\ directory (as shown at
right).

If in any other directory
type “cd C:\”

that will put you in the C:\
directory
Type
“javac HelloProgram.java”

compiles the code
Test Your Java Installation 5
Now type
“java HelloProgram”
Should say “Hi
there!”
Common Mistakes: Read This!
Here are the most common mistakes.

You have a typo in your path.
• It has to be exactly correct. Capitalization, spelling, etc.
Computers are stupid that way.

You specify a path that is to the wrong directory.
• Your path must exactly match the directory where you
installed Java.

You forgot to put a “.;” in your path.

You downloaded the incorrect version of Java.

You did not create a “HelloProgram.java” file for testing. You
actually created a “HelloProgram.java.txt” file.
• Get rid of the “.txt”! Change the name of the file by erasing
the “.txt”.
Troubleshooting 1:
NoClassDefFound
NoClassDefFound pops up when you
try to run your program.
This means there is a mistake with your path.
 Check that the path is exactly correct.

• Spelling.
• Backslashes are not forward slashes.
• You are specifying the full path to the directory
where java is installed.
• Etc.

If that‟s all ok, then go to the next page.
Troubleshooting 2: Wrong File
Name
Improperly named java files.


“I think I saved my program as „HelloProgram.java‟, but
I‟m not sure.”
Ok, then find the file and look at the name.


If you just see “HelloProgram” followed by nothing, then
your “file extensions” are hidden.
• Turn on file extensions by selecting the “Tools” menu
of the folder. Then select “Folder Options…”. Then
select the “View” tab. Then uncheck the box that says
“Hide extensions for known file types”.
Now, if it says “HelloProgram.java.txt”, then that is wrong.
Erase the “.txt” part of the name.
Troubleshooting 3: Two Paths
You might have two paths.
There are “user” and “system” environment
variables.
 The path should already exist as one of the
system environment variables.
 But if path (or even PATH) is also defined as a
user variable, then this can cause a conflict.
 So if path is defined in both places, then add
your java path to both!

Troubleshooting 4: classpath
The classpath.





You might also have a variable called classpath.
If so, add your java path to this.
Also, your classpath should always begin with “.;” which
stands for “current directory”.
So check that “.;” is the first thing listed in the classpath.
If not, add “.;” to the beginning of your classpath.
• E.g., my classpath looks like
•
.;C:\Program Files\Java\jdk1.5.0_04\bin";C:\CA_Explorer\CA_Explorer.jar;
Troubleshooting 5: Windows
Vista Warning
Windows Vista may default to a setting that does not allow you
to run java from the C: drive (and other folders).


In other words, you do not have administrator privileges on your own
computer!
Ouch!
How will you know? When testing your installation, it will claim
that you “don‟t have permission” or that “access is denied”.
Solutions:

Make yourself an administrator.



You may need to create a whole new profile to do this.
Or you may be able to change your access privileges for the C: drive.
Or (as a temporary fix) try moving your document to your Documents
folder. Then change directories (i.e., “cd”) to that directory on the
command prompt. Then try using java in that folder.
Stumped?
Check the install guide

http://java.sun.com/j2se/1.5.0/install-windows.html
Ask a department tutor
Ask me!
Documentation
Highly recommend that you download the API

Is a nice list of all the Java commands

download the “J2SE 5.0 documentation” section on
http://java.sun.com/j2se/1.5.0/download.jsp
Can also get this online (without
downloading) at

http://java.sun.com/j2se/1.5.0/docs/api/index.html