Hello World in Java (Mac OS X) Hello World in Java (Mac OS X) 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 creating and compiling a Java program in IntelliJ and executing it from the command line.
Sep 7, 2018 - You will need an Intel-based Mac running Mac OS X 10.8 (Mountain. Downloads the Java wrapper scripts javac-introcs and java-introcs. Java Service Wrapper Pro is configurable tools which not only allows Java applications to be installed and controlled like native Windows Services or UNIX. Best Video Software for the Mac How.
You will need a Mac running Mac OS X 10.8 (Mountain Lion) to Mac OS X 10.13 (High Sierra). Install the Java Programming Environment The installer installs and configures a Java programming environment, including OpenJDK 10 and IntelliJ IDEA, Community Edition 2018.2. Log in to the user account in which you will be programming. Your account must have Administrator privileges.
Download the Mac OS X installer. Double-click lift-java.pkg to install the software. Enter your Mac OS X password when prompted and use all of the default options. Warning If you have previously used IntelliJ 2018.2, run this installer only if you want a clean re-install. The installer overwrites any previous IntelliJ 2018.2 settings with our novice-friendly settings. Delete lift-java.pkg (if it is not automatically deleted). 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, and course-specific settings (such as compiler options and style rules). Download the project for your programming assignment to a convenient location (such as the Desktop). COS 126 assignments. COS 226 assignments.
Coursera Algorithms, Part I. Double click the zip file to unzip. This creates a project folder with the name of the corresponding programming assignment (such as hello or percolation). Delete the zip file.
Launch IntelliJ via Finder → Applications → IntelliJ IDEA CE.app. When you launch IntelliJ for the first time,. IntelliJ may display the. Scroll down and Accept. IntelliJ may ask if you want to send anonymous usage statistics to JetBrains. Choose your preferred option.
To open a project from the Welcome screen, click Open and select the project folder. When you use IntelliJ for the first time, it may take a minute or two to index your files. Then, you should see an assignment logo (in the main editor window) and a list of project files (in the Project View sidebar at left). Tip Use the Tools menu to compile and execute your program from IntelliJ.
The Build and Run menus support additional options (such as a debugger) for advanced programmers. Also be sure that the main editor window is active before using the Tools menu (e.g., by clicking the code you want to compile or execute). Compile and Execute the Program (from the command line) The command line is a simple and powerful mechanism for controlling your programs. It supports features that are unavailable in IntelliJ, including file redirection and piping.
In the editor window containing your program, select the menu option Tools → Open in terminal (⌘T). This will launch a terminal where you type commands. You will see a command prompt that looks something like this: /Desktop/hello The /Desktop/hello is the current working directory, where is shorthand for your home directory. To compile your program, type the following javac command. More specifically, type the text in yellow that appears on the same line as the command prompt.
/Desktop/hello javac HelloWorld.java /Desktop/hello Assuming that the file HelloWorld.java is in the current working directory, you should not see any compile-time errors or warnings. To execute your program, type the following java command: /Desktop/hello java HelloWorld Hello, World You should see the output of your program beneath the line on which you typed the command. Tip Typically, you should compile from IntelliJ (because IntelliJ highlights the lines on which any compile-time errors or warnings occur) and execute from the command line (because the command line makes it is easy to specify command-line arguments and use file redirection). Textbook Libraries (from the command line) To make our textbook libraries accessible to Java from the command line, you will use our wrapper scripts. Computer Science: An Interdisciplinary Approach (including COS 126 students). The program uses our standard drawing and standard random libraries in stdlib.jar to draw a. First download.
Then, use the Finder to move it to a project folder (such as hello). Finally, to compile and execute it, type the following commands in the terminal: /Desktop/hello ls Barnsley.java COS 126.iml WELCOME.txt logo.png /Desktop/hello javac-introcs Barnsley.java /Desktop/hello java-introcs Barnsley 10000 When you execute the program, a standard drawing window will appear and an image like this one will be generated, one point at a time: To get your command prompt back, close the standard drawing window. Algorithms, 4th Edition (including COS 226 and Coursera students). The program uses various libraries in algs4.jar to simulate the motion of n disks subject to the laws of elastic collision. First download Then, use the Finder to move it to a project folder (such as hello).
Finally, to compile and execute it, type the following commands in the terminal: /Desktop/hello ls CollidingDisks.java COS 226.iml WELCOME.txt logo.png /Desktop/hello javac-algs4 CollidingDisks.java /Desktop/hello java-algs4 CollidingDisks 20 When you execute the program, a standard drawing window will appear with an animation of 20 colliding disks. To get your command prompt back, close the standard drawing window. Frequently Asked Questions.
Java FAQ Can I use a vendor and version of Java other than OpenJDK 10? You may use either Oracle or OpenJDK.
You may also use Java 8, Java 9, or Java 11; however, if you do so, you will likely need to manually configure the Project SDK in IntelliJ. How can I check which version of Java is installed (and where it is installed)? Type the following commands in the terminal: /Desktop/hello javac -version javac 10.0.2 /Desktop/hello java -version openjdk version '10.0.2' 2018-07-17 OpenJDK Runtime Environment 18.3 (build 10.0.2+13) OpenJDK 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode) /Desktop/hello /usr/libexec/javahome /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home It’s important that the Java version numbers match and that you see the number 10, but the rest is not critical. IntelliJ FAQ How does this custom version of IntelliJ different from the standard one? IntelliJ is an industrial-strength integrated development environment (IDE), suitable for use by professional programmers. The installer configures your user preferences to make it more suitable for use by novice programmers:.
Disables all built-in plugins except Terminal and JUnit. Installs the Findbugs-IDEA, Checkstyle-IDEA, Run-with-Arguments, Custom Title, and Save-Actions plugins.
Eliminates or reduces various popup elements (lightbulbs, code folding, breadcrumbs, gutter markers, notifications, parameter hints). Simplifies menus and toolbars, hiding advanced options. Disables live templates and postfix completion. Adopts the Obsidian Black color scheme.
Auto-configures Java upon installation. Adds a few keyboard shortcuts. The course-specific project folders perform additional customizations:. Streamlines autocomplete to display only relevant libraries (such as java.lang, java.util, and algs4.jar). Configures Findbugs and Checkstyle with course-specific rules. Provides course-specific libraries (such as algs4.jar). Enables auto-formatting of code on save.
Enables auto-importing of Java libraries. How can I manually configure the Project SDK in IntelliJ? The installer should do this automatically. To configure it manually,.
Navigate to File → Other Settings → Project Structure → SDKs. Click the + symbol (top left) to add an SDK. Locate an SDK. A typical location for a Java SDK on Mac OS X is /Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/. Use the shorthand name suggested by IntelliJ, e.g., 10 for version 10.0.2. Be sure to keep the Project language level as 8 because our autograder currently supports only Java 8 features. How can I create a new project in IntelliJ?
If you want to inherit all of the properties of an existing project,. Use the Finder to copy the project folder, giving it your preferred name. Delete any unwanted files. Be sure to keep the.iml file (which defines the project), the.idea subdirectory (which contains the IntelliJ course preferences), and the.lift subdirectory (which contains the course libraries).
To create a new project from scratch, you can use the Create New Project option from the Welcome screen. But, we do not recommend this approach for novice programmers. Can I use a version of IntelliJ that is more recent than 2018.2?
Yes, though if it is 2018.3 (or above), you will need to migrate your user preferences. How I can I restore the original IntelliJ menus (instead of the abbreviated novice-friendly ones)? Preferences → Appearances & Behavior → Menus and Toolbars → Restore All Defaults.
Command-Line Tools FAQ When I compile or execute a program from the command line that uses one of the textbook libraries, I get an error that it cannot find the library. How can I fix this? Make sure that you are using the appropriate wrapper script, such as javac-algs4 or java-algs4. How can I run Spotbugs, PMD, and Checkstyle from the command line? The installer includes wrapper scripts to simplify this process. To run Spotbugs 3.1.3, type the following command in the terminal: /Desktop/hello spotbugs HelloWorld.class Running spotbugs on HelloWorld.class: The argument must be a list of.class files. Here is a list of.
To run PMD 6.3.0, type the following command in the terminal: /Desktop/hello pmd HelloWorld.java Running pmd on HelloWorld.java: The argument must be either a single.java file or a directory containing one or more.java files. Here is a list of.
To run Checkstyle 8.11, type one of the following commands in the terminal, depending on whether you are COS 126, COS 226, or Coursera student: /Desktop/hello checkstyle -cos126 HelloWorld.java Running checkstyle on HelloWorld.java: /Desktop/hello checkstyle -cos226 HelloWorld.java Running checkstyle on HelloWorld.java: /Desktop/hello checkstyle -coursera HelloWorld.java Running checkstyle on HelloWorld.java: The argument must be a list of.java files. Here is a list of.