This document instructs you on how to set up a Java programming environment for your Mac OS X computer. It also provides a step-by-step guide for creatingand compiling a Java program in IntelliJ and executing itfrom the command line.
You will need a Mac runningMac OS X 10.13 (High Sierra) to Mac OS X 10.15 (Catalina).
We will download and install java on MAC OS. If you wish to install java on Windows you may skip this tutorial and may refer our tutorial Install JDK on Windows and Set Environment Path on Windows. But make sure that it’s version is either 8 or 9 as JMeter4.0 does not support Java 10 and Java. An easy way to run 'classic' Mac OS applications under Windows. Under Windows, software written for the 'classic' Mac OS (i.e. Versions 6 through 9) can only be run through software that emulates Macintosh hardware from 1980s and 1990s. The most advanced of these emulator programs is SheepShaver. Mac OS 9's Software Update control panel software notes that there's a new version of Mac OS Runtime for Java in distribution. The new version, 2.2.5, can be downloaded and installed through the. Mac OS X 10.6 and below: Apple's Java comes pre-installed with your Mac OS. Mac OS X 10.7 (Lion) and above: Java is not pre-installed with Mac OS X versions 10.7 and above. To get the latest Java from Oracle, you will need Mac OS X 10.7.3 and above. If you have Java 7 or later versions, you will see a Java icon under System Preferences. Mac OS 10.9 uninstalls the Java SE 6 Runtime. Install Java SE 6 Runtime to launch Adobe Dreamweaver.
|0. Install the Java Programming Environment|
The installer installs and configures a Java programming environment, includingOpenJDK 11 andIntelliJ IDEA, Community Edition 2020.1.
If you have previously used IntelliJ,run this installer only if you want a clean re-install.The installer overwrites IntelliJ IDEA CE.app andany previous IntelliJ 2020.1 settings.
|1. Open a Project in IntelliJ|
You will develop your Java programs in an application called IntelliJ IDEA, Community Edition.
IntelliJ organizes Java programs into projects.In our context, each project corresponds to one programming assignment.A typical project contains Java programs, associated data files, andcourse-specific settings (such as compiler options, style rules, and textbook libraries).
[ sample project for COS 126 (Princeton) ]
[ sample project for COS 226 (Princeton) ]
[ sample project for Computer Science: Programming with a Purpose (Coursera) ]
[ sample project for Algorithms, Part I (Coursera) ]
Double click the zip file to unzip.This creates a project folder with thename of the corresponding programming assignment (such as
percolation).Delete the zip file.
The project folders contain course-specific information. Be sure to downloadthe one corresponding to your institution and course.
WarningDo not select Create New Project;this option is intended for advanced programmers.Also, always use Open with a project folder, not an individual file.
|2. Create a Program in IntelliJ|
Now you are ready to write your first Java program.IntelliJ features many specialized programming toolsincluding line numbering, syntax highlighting, bracket matching, auto indenting,auto formatting, auto importing, variable renaming, and continuous code inspection.
HelloWorld.javaexactly as it appears below.(IntelliJ generates the gray boilerplate code automatically,along with the course header block comment.)If you omit even a semicolon, the program won’t work.
|3. Compile and Execute the Program (from IntelliJ)|
Now, it is time to execute (or run) your program.This is the exciting part, where your computer follows the instructionsspecified by your program.Before doing so, you must compile your program intoa form more amenable for execution on a computer.
If the compilation fails, a Recompile panel will open up (at bottom),highlighting the compile-time errors or warnings.Check your program carefully for typos, using the error messages as a guide.
You should see the output of the program (in white), along with a messagethat the program finished normally (with exit code 0).
Use the LIFT menu to compile and execute your program from IntelliJ.The Build and Run menus support additional options for advanced programmers.
Also be sure that the main editor window is active before using the LIFTmenu (e.g., by clicking the code you want to compile or execute).
|4. Compile and Execute the Program (from the command line)|
The command line is a simple and powerful mechanism forcontrolling your programs (e.g., command-line arguments,file redirection, and piping).IntelliJ supplies an embedded terminalfor easy access to the command line.
~/Desktop/hello is the current working directory, where
~ is shorthand for your home directory.
javaccommand.More specifically, type the text in yellow that appears on the same line as thecommand prompt.Assuming that the file
HelloWorld.javais in the current working directory,you should not see any compile-time errors or warnings.
javacommand:You should see the output of your program beneath the line on which you typed the command.
Typically, you should compile from IntelliJ(because IntelliJ highlights the lines on which anycompile-time errors or warnings occur) and execute from the command line(because the command line makes it is easy to specify command-line argumentsand use file redirection).
|5. Textbook Libraries (from the command line)|
To make our textbook libraries accessible to Java from the command line,you will use our wrapper scripts.
stdlib.jarto draw aBarnsley fern.First download Barnsley.java.Then, use the Finder to move itto a project folder (such as
hello).Finally, to compile and execute it,type the following commands in the terminal:When you execute the program, a standard drawing window will appearand an image like this one will be generated, one point at a time:
To get your command prompt back, close the standard drawing window.
algs4.jarto simulate the motion of n disks subject to the lawsof elastic collision.First download CollidingDisks.javaThen, use the Finder to move it to a project folder (such as
percolation).Finally, to compile and execute it,type the following commands in the terminal:When you execute the program, a standard drawing window will appearwith an animation of 20 colliding disks.To get your command prompt back, close the standard drawing window.
|Frequently Asked Questions|
sudo installer -verbose -pkg lift-java.pkg -target /
/Applications/IntelliJ IDEA CE.app
11,but the rest is not critical.
The course-specific project folders perform additional customizations:
To manually configure the Project SDK,
.imlfile (which defines the project),the
.ideasubdirectory (which containsthe IntelliJ course preferences), andthe
.liftsubdirectory (which contains the courselibraries).
To create a new project from scratch, you can use the Create New Project option from theWelcome screen. But, we do not recommend this approach for novice programmers.
java-algs4)should already be available.
Our autoinstaller customizes the command line in a few ways by copying these three configuration files:
.inputrc.Note that the autoinstaller will copy these files only if none of them already exists.If you had previous versions and wish to replace your versions with ours, type the following commands:
Ctrl-D.On Windows, type
Enter,even in Git Bash.
.classfiles.Here is a list ofbug descriptions.
.javafile ora directory containing one or more
.javafiles.Here is a list of bug patterns.
.javafiles.Here is a list ofavailable checks.