Compiling and running a Java application on Mac OSX, or any major operating system, is very easy. Apple includes a fully-functional Java runtime and development environment out-of-the-box with OSX, so all you have to do is write a Java program and use the built-in tools to compile and run it. Installing Java: Java should be already installed by default. Click the button labeled 'Download Mac OS X App'. Double click on the tar file to expand it, and then drag the Dr.Java application into the Applications folder on your mac. The Archive, a mac OS note-taking app for heroic authors and prolific writers Zettelkasten Live, our ongoing video blog The German Zettelkasten Method book, written by Sascha. Java can run applications developed using the java programming language and set of development tools. The JVM is a crucial component of the Java platform. The availability of JVMs on many types of hardware and software platforms enables Java to function both as middleware and a platform in its own right. This version is supposed to work whether you have Java 1.4.2 or Java 1.5, and we advise using it. If you want, open this web page (by clicking the link) in your browser and choose another version of DrJava to download.
This page describes how to install and uninstall JDK 8 for OS X computers.
This page has these topics:
See 'JDK 8 and JRE 8 Installation Start Here' for general information about installing JDK 8 and JRE 8.
See 'OS X Platform Install FAQ' for general information about installing JDK 8 on OS X.
System Requirements
Observe the following requirements:
Any Intel-based computer running OS X 10.8 (Mountain Lion) or later.
Administrator privileges.
Note that installing the JDK on OS X is performed on a system wide basis, for all users, and administrator privileges are required. You cannot install Java for a single user.
Installing the JDK also installs the JRE. The one exception is that the system will not replace the current JRE with a lower version. To install a lower version of the JRE, first uninstall the current version as described in 'Uninstalling the JRE'.
JDK Installation Instructions
When you install the Java Development Kit (JDK), the associated Java Runtime Environment (JRE) is installed at the same time. The JavaFX SDK and Runtime are also installed and integrated into the standard JDK directory structure.
Depending on your processor, the downloaded file has one of the following names:
jdk-8u
version
-macosx-amd64.dmg
jdk-8u
version
-macosx-x64.dmg
Where version
is 6 or later.
Download the file.
Before the file can be downloaded, you must accept the license agreement.
From either the Downloads window of the browser, or from the file browser, double click the
.dmg
file to launch it.A Finder window appears containing an icon of an open box and the name of the
.pkg
file.Double click the package icon to launch the Install app.
The Install app displays the Introduction window.
Note:
In some cases, a Destination Select window appears. This is a bug, as there is only one option available. If you see this window, select Install for all users of this computer to enable the Continue button.Click Continue.
The Installation Type window appears.
Click Install.
A window appears that says 'Installer is trying to install new software. Type your password to allow this.'
Enter the Administrator login and password and click Install Software.
The software is installed and a confirmation window appears.
Refer to
http://www.oracle.com/technetwork/java/javase/downloads/jdk-for-mac-readme-1564562.html
for more information about the installation.After the software is installed, delete the
.dmg
file if you want to save disk space.
Determining the Default Version of the JDK
If you have not yet installed Apple's Java OS X 2012-006 update, then you are still using a version of Apple Java 6 that includes the plug-in and the Java Preferences app. See 'Note for Users of OS X that Include Apple Java 6 Plug-in'.
There can be multiple JDKs installed on a system, as many as you wish.
When launching a Java application through the command line, the system uses the default JDK. It is possible for the version of the JRE to be different than the version of the JDK.
You can determine which version of the JDK is the default by typing java -version
in a Terminal window. If the installed version is 8u6, you will see a string that includes the text 1.8.0_06. For example:
To run a different version of Java, either specify the full path, or use the java_home
tool:
For more information, see the java_home(1) man page.
Uninstalling the JDK
To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.
For example, to uninstall 8u6:
Do not attempt to uninstall Java by removing the Java tools from /usr/bin
. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.
Downloading and setting up DrJava
DrJava is a free environment for writing and running Java programs. It is installed on CIT's computers throughout the campus and in the ACCEL lab.
Please note that there are two versions of Java. The older version, Java 1.4.2, and the newer version, Java 1.5. For most of the semester, it will not matter which version you are using. We will not make use of the new features in Java 1.5.
You need a Java virtual machine
You will need the Java software development kit (JDK) from the Sun website. THIS MAY ALREADY BE ON YOUR COMPUTER. Don't attempt to download and install it unless you know you don't have it. If you have a Macintosh running Mac OS X, you almost certainly have it. If you have a PC, this site can check whether you have it:
If you need the Java software development kit (JDK) get it from this website:
See the Popular Downloads link on the right side of that page. Choose J2SE 5.0. Also, choose the J2SE JDK or SDK (not just the JRE and not the 'bundles' that include other programming environments, such as netBeans). Warning: this is a big download!
Can't execute jar files
If you cannot double-click on a jar file to start it running, or if you cannot execute any of the commands java, javac, javadoc, or jar, you probably have not set your path correctly. We explain this for Windows 2000; older windows systems are similar.
Your system contains a variable that lists directories with executable files in them. Type 'path' in a command-line window. The line that is printed contains path names separated by semicolons. For example, one path name may be:
C:WINNTsystem32
There should be a path that looks like this: C:j2sdk1.4.1_02bin. This is a directory called bin inside the directory where you installed the sdk. It may be different on your computer. If such a path is not there, you have to add it. Bring up the help in your Windows system, open the index, and look for 'path'. There, you will find instructions on appending another directory to variable path. It may be something like this (but read the instructions):
path %path%;C:j2sdk1.4.1_02bin
Downloading DrJava
The easiest thing for you to do is to download this version of DrJava drjava-stable-20080106-0744. This version is supposed to work whether you have Java 1.4.2 or Java 1.5, and we advise using it.
If you want, open this web page (by clicking the link) in your browser and choose another version of DrJava to download. Get the latest version. Note that DrJava won't run unless you have a Java 2 v1.3 (or later) virtual machine already installed.
Warning: you may get a dialog saying something about a 'JAR archive security check'. If you do, just right-click on the DrJava download link and select 'Save Link As' (or the equivalent in your browser).
We know that all this setup can be annoying, but you have to do it only once!
A common DrJava problem: finding tools.jar
Question: I downloaded Sun's J2SE SDK and DrJava. When it came to actually running DrJava, the following window kept popping up even though somehow DrJava still managed to run without me finding the file --what should I do?:
Compiler not found. The file you chose did not appear to contain the compiler. Would you like to pick again? The compiler is generally located in 'tools.jar', in 'lib' subdirectory under your JDK installation director. (If you say 'No', DrJava will be unable to compile programs.)
Answer: First, make sure you installed the Java SDK, not the JRE. (See above.)
Next, file tool.jar comes with the JDK. The usual location is
C:Program FilesJavajdk1.5.0_02libtools.jar
if you have followed the default options during the JDK download process. You can also use a desktop tool to search for this file on your computer. You simply need to set DrJava's Preferences to the correct path. To do so, follow these menu items: Edit - Preferences - Resource Locations - Tools.jar Location then type or browse to the correct location.
Running DrJava
There are several ways to run DrJava:
- From the command line, you can type java -jar drjava-stable-20061025-1556.jar
- On many platforms, you can simply double-click the jar file to start DrJava.
- On OS X, you can download the drjava-stable-20061025-1556.jar-osx.tar.gz package. You can then run DrJava as a normal application.
Documentation --how to use DrJava
The demos given in class and in the demo sessions should help, if you take notes. However, here is documention on using DrJava (http://drjava.sourceforge.net/userdocs/) on the web.
Wrong-version error.
Do you get a message that looks like this?
Error: cannot access javax.swing.JFrame
bad class file: C:Program FilesJavajre1.5.0librt.jar(javax/swing/JFrame.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
It may mean that your computer has two different systems on it and is an inconsistent state. If your computer has jre5.0, then it cannot use SDK 4.7. Uninstall SDK4.7 and download JDK 5.0 and use its tools.jar.