How To Install Java
On This Page
- Introduction
- Installation Instructions
- Compiling and Running Applications
- Running CheckStyle from the Command Line
Introduction
Here are some instruction for setting up the Java Software Development Kit (JDK or Java SDK) at home. Java is already installed on CTC and lab machines. If you need more help with the installation, you can consult the Platform Installation notes or the tutorial: Lesson: The "Hello World!" Application. Or better yet, ask a class mate if they were able to get it set up.
For Mac users, go to Mac OSX Updates and search for Java to verify you have the most recent update for the Mac. You need Java version 6 or later.
For Linux users, see the Platform Installation instructions and follow the link to 32 bit or 64 bit Linux. You need the full JDK version as the JRE does not have all the software tools needed for developing programs.
Installation Instructions for Windows
- Uninstall any prior version of Java
If you have previously installed another version of Java, uninstall it. From the Control Panel use the Add/Remove Programs utility on XP (or earlier) or the Programs and Features utility on Vista or later.
- Uninstall any version of QuickTime.
Apparently, if you install QuickTime without first installing Java, QuickTime installs an older version of Java. However, if you install Java before installing QuickTime, then QuickTime uses the more up-to-date version you are now installing. By NOT following this step, QuickTime sets a classpath to the older version of Java that will interfere with the operation of a newer version of Java.
- Download the JDK files
Click on the download link to open another browser window. Download the Java Platform (JDK) (not the JRE) for your operating system. You should install the latest version of the Java Platform (JDK). Do NOT install the bundles, NetBeans or Java EE. Save the installer program, making note of the name and location. If you are installing to Windows, I recommend using the "Windows Offline Installation" version of the installer.
- Run the installer, using default settings.
For Windows, at the time of this writing, the name of the installer file for windows is jdk-6u21-windows-i586.exe.
- Update the PATH variable so the operating system can find the JDK
The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window. For instructions, see How do I set or change the PATH system variable?.
Compiling and Running Applications
After installing the Java SDK, you should compile and run a sample program to verify the installation. One simple program you can compile and run is the
HelloWorld.javaprogram shown below:import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world!"); } }Copy this file into a text editor (e.g. Notepad or TextPad) and save it in a convenient location. Then follow these instructions:
Compiling a Program
- Open a window with a command prompt
Start => Run- Type:
commandon Win98/ME orcmdon Windows NT/2000/XP/Vista- For more information: How To Use a Windows Console
- Go to the directory where program source code is stored
- Type:
javac HelloWorld.java
- If the operating system reports that it does not recognize the
javaccommand, then you need to set the path.- If the source code has no errors,
javaccreatesHelloWorld.class
- Type
dirto list the filesRunning a Program
- Type:
java HelloWorld
- The Java Virtual Machine (JVM) loads the
.classfile forHelloWorld- Note that
.classsuffix is not typed- The JVM calls the
main()method- You should see the program output:
Hello, World!More Information
Use a Windows Console: instructions on using a DOS console on Windows. Lesson: Your First Cup of Java: detailed instructions for compiling and running your first program Java(TM) SE 6 Release Notes: Sun's notes for various operating systems. Mac OSX Updates: search for Java to verify you have the most recent update for the Mac. Running CheckStyle from the Command Line
CheckStyle is a program to check the style of your Java documentation. Here are some instructions for running CheckStyle at the command line:
This will test all the
- Copy the checkstyle-all-4.4.jar and grade_checks.xml into the same directory as your Java source files.
I am using CheckStyle 4.4 for grading this semester because this is the version installed in the CTC.
- Open a console (terminal) window and type the following command:
java -jar checkstyle-all-4.4.jar com.puppycrawl.tools.checkstyle.Main -c grade_checks.xml *.java*.javafiles in the directory. If you want to restrict the files you will need to specify the file name rather than use*.java.