How to install the JDK
Microsoft Windows 95
Installing the JDK
- Run the setup program jdk-1_5_0-windows-i586.exe
- Click "Continue" on the warning message.
- Click "Accept Terms in License Agreement" then click on the Next button.
- Select the components to install. If you are low on free space you can leave out the Demos and Source Code.
- The wizard will now install the JDK files on your system. This may take a while.
- Click the Next button to install the J2SE Runtime Environment
- In the next dialog select the browsers to integrate the JRE with, I recommend all. Click the Next button.
- The installation should be complete! Click the Finish button.
Setting the Path Variable
We need to set the path variable so that the system can find the Java compiler.- Open the Windows Explorer and navigate to the C:\ drive. Right-click on the file named Autoexec.bat and select edit from the menu.
WarningAutoexect.bat may not be visible if it is set as a hidden file. You should set folder options to display hidden files by selecting Options from the Folder menu. - The file may be empty, but it will most likely contain some entries. You should add the following entries at the bottom of the file, after the last entries:
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0 set PATH="%PATH%;%JAVA_HOME%\bin"
NoteIf you changed the installation location of java to some other location, you will have to change the location here to. - Save the file, close the text editor and restart your computer.
Microsoft Windows 98
Installing the JDK
- Run the setup program jdk-1_5_0-windows-i586.exe
- If you use Windows 98 First Edition and get the warning message, click "Continue" on the warning message.
- Click "Accept Terms in License Agreement" then click on the Next button.
- Select the components to install. If you are low on free space you can leave out the Demos and Source Code.
- The wizard will now install the JDK files on your system. This may take a while.
- Click the Next button to install the J2SE Runtime Environment
- In the next dialog select the browsers to integrate the JRE with, I recommend all. Click the Next button.
- The installation should be complete! Click the Finish button.
Setting the Path Variable
We need to set the path variable so that the system can find the Java compiler.- Open the Windows Explorer and navigate to the C:\ drive. Right-click on the file named Autoexec.bat and select edit from the menu.
WarningAutoexect.bat may not be visible if it is set as a hidden file. You should set folder options to display hidden files by selecting Options from the Folder menu. - The file may be empty, but it will most likely contain some entries. You should add the following entries at the bottom of the file, after the last entries:
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0 set PATH="%PATH%;%JAVA_HOME%\bin"
NoteIf you changed the installation location of java to some other location, you will have to change the location here to. - Save the file, close the text editor and restart your computer.
Microsoft Windows 2000
Installing the JDK
Note
You should be logged in as Administrator or have Administrative privileges to perform this installation. If not, you should get your System Administrator to do the install for you.
- Run the jdk-1_5_0-windows-i586.exe setup program.
- Select Accept with the Terms in the License Agreement and click the Next button.
- Select the components you wish to install. If you are low on disk space you can leave out the Demos and Source Code. Click the Next button to continue.
- The installer will now copy files to your computer, this may take a while.
- Install the Public Java Runtime Environment by clicking the Next button. You should not have to edit any settings here.
- Select which browsers to integrate the runtime environment with. I recommend all.
- That should take care of the installation. The JDK is now successfully installed on your system.
Setting the Path Variable
We need to set the path variable so that the system can find the Java compiler.Note
We will create the variables in the global system space so that any user on the system can use the java tools. If you don't want this, you can create the variables in the Administrator's user space, but then only the administrator will be able to use the java tools. This might be what you want if there is only one user on the computer.
- Right click on the My Computer icon on the desktop and select Properties from the pop up menu. Click the Environment Variables button.
- Under the System Variables section click the New button to add a new variable.
- Add a variable named JAVA_HOME with the value C:\Program Files\Java\jdk1.5.0 and click the Ok button.
NoteIf you installed Java to a different location, you should change the value here to reflect this. - Lastly edit the variable named PATH, add a semi colon (;) after the last entry in the value field and then add C:\Program Files\Java\jdk1.5.0\bin
Microsoft Windows XP
Installing the JDK
Note
You should be logged in as Administrator or have Administrative privileges to perform this installation. If not, you should get your System Administrator to do the install for you.
- Run the jdk-1_5_0-windows-i586.exe setup program.
- Select Accept with the Terms in the License Agreement and click the Next button.
- Select the components you wish to install. If you are low on disk space you can leave out the Demos and Source Code. Click the Next button to continue.
- The installer will now copy files to your computer, this may take a while.
- Install the Public Java Runtime Environment by clicking the Next button. You should not have to edit any settings here.
- Select which browsers to integrate the runtime environment with. I recommend all.
- That should take care of the installation. The JDK is now successfully installed on your system.
Setting the Path Variable
We need to set the path variable so that the system can find the Java compiler.Note
We will create the variables in the global system space so that any user on the system can use the java tools. If you don't want this, you can create the variables in the Administrator's user space, but then only the administrator will be able to use the java tools. This might be what you want if there is only one user on the computer.
- Right click on the My Computer icon on the desktop and select Properties from the pop up menu. Click the Environment Variables button.
- Under the System Variables section click the New button to add a new variable.
- Add a variable named JAVA_HOME with the value C:\Program Files\Java\jdk1.5.0 and click the Ok button.
NoteIf you installed Java to a different location, you should change the value here to reflect this. - Lastly edit the variable named PATH, add a semi colon (;) after the last entry in the value field and then add C:\Program Files\Java\jdk1.5.0\bin
Linux (Red Hat, Fedora Core & Mandrake)
Installing the JDK
Note
This how-to assumes you have root privileges and that you are to install Java system wide so that all users can use the Java tools.
- Start a shell. Copy the Linux installer to the /usr/local directory.
cp jdk-1_5_0-linux-i586.bin /usr/local
- Now change into the /usr/local directory and run the installer.
cd /usr/local chmod +x jdk-1_5_0-linux-i586.bin ./jdk-1_5_0-linux-i586.bin
- Read through the license agreement and if you agree type yes. This will start the installer.
- If everything goes well you should end up with output that ends with:
Done.
Setting the Path Variable
- Create the file named java.sh in the directory named /etc/profile.d using your favourite text editor. I used Vi.
cd / touch /etc/profile.d/java.sh vi /etc/profile.d/java.sh
- Add the following to the file.
export JAVA_HOME=/usr/local/jdk1.5.0 export PATH=${PATH}:${JAVA_HOME}/bin
- Make the script executable.
chmod +x /etc/profile.d/java.sh
- Log out and then log in again for the changes to take effect.
Sun Solaris
The JDK should be installed and setup by default. For information on upgrading go to Sun's Website and browse through the Solaris documentation.MacOS
Most newer versions of MacOS have the JDK installed and setup by default. For information on upgrading check out the MacOS documentation.Compiling and Running Java Programs
Compiling Java Programs
We will now test our installation by compiling and running a simple Java Program.Microsoft Windows
- Open the Notepad text editor Start > All Programs > Accessories > Notepad and type the following program into it:
class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
- Save the program to the C:\ drive in a file named HelloWorld.java. Make sure to select "All Files" in the Type field of the Save As dialog box.
- To compile the program, open the Dos Prompt Start > All Programs > Accessories > Command Prompt and type:
cd\ javac HelloWorld.java
If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program on the C:\ drive and that it is named HelloWorld.java.
Linux
- Start your favourite text editor and type the following program in it, then save it in a file named HelloWorld.java in your home directory.
class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
- To compile the program, start a shell and use the Java Compiler:
cd ~ javac HelloWorld.java
If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program in your home directory and that it is named HelloWorld.java.
Solaris
- Start a text editor, either vi in the command line or Gedit. Type the following program in it then save it in a file name HelloWorld.java in your home directory.
class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
- To compile the program, start a shell and use the Java Compiler:
cd ~ javac HelloWorld.java
If you don't get any errors then everything went well. If you get errors, check firstly that you saved the program in your home directory and that it is named HelloWorld.java.
Running Java Programs
- To run the program, type:
java HelloWorld
you should get the following output:
Hello World!
Common Errors and Solutions
- Exception in thread "main" java.lang.NoSuchMethodError: main You must define a main method as: public static void main(String[] args) {...}
- HelloWorld.java:3: illegal character: \8220 System.out.println(öHelloWorld!ö); Do not type your code in a word processor application that uses smart quotes!!
- HelloWorld.class Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld/class The correct way to call a program is java HelloWorld without the ".java" or ".class"
No comments:
Post a Comment