This document instructs you on how to set up a Java programming environmentfor your Linux computer.It also provides a step-by-step guide for creating and compiling a Javaprogram in IntelliJ and executing it from the command line.
You will need a 64-bit version of Linux.
For me, as a developer, WSL 2 is great because I can develop on a real Linux kernel. The problem is that WSL 2 is a special feature for Windows users, In this article, I am going to show you how we can set up a development environment look like WSL 2 (but not completely) on Linux, Mac. Java in Visual Studio Code. Support for Java in Visual Studio Code is provided through a wide range of extensions.Combined with the power of core VS Code, these extensions give you a lightweight and performant code editor that also supports many of the most common Java development techniques. FREE Download Java SE Development Kit (JDK) Linux/MacOS. (Direct Link).Java SE Development Kit is a special Java programming language. Linux is UNIX like a source software and can use an operating system which provides full memory protection and multi-tasking operations. It is an open d by anyone. Head To Head Comparison Between Linux and MAC and Windows (Infographics) Below is the Top 5 Comparisons Between Linux vs MAC.
Warning:
Beta version of instructions. Please send bug reports to wayne@princeton.edu.
Todo: replace Mac OS X screenshots with Linux screenshots.
1. Install Java |
You will use Java SE Development Kit 11 (JDK 11).
Note
Skip this step if you already have JDK 11 installed.
- Log in to the user account in which you will be programming.Your account must have Administrator privileges and you must be connected to the Internet.
- Launch your shell.We'll assume that the command prompt looks like the following (though your command promptwill likely differ):The symbol
~
is shorthand for your home directory. - Install theJava SE Development Kit 11,either fromOpenJDKorOracle.Many Linux distributions (such as Ubuntu 18.04 or 20.04) includeOpenJDK 11 by default, so you can skip this step.Otherwise, use your Linux distribution's package manager(see the first FAQ) to installOpenJDK 11.For example, here are the commands for Ubuntu 16.04:
- To confirm that Java 11 is installed,type the following commands:It's important that the Java version numbers match and thatyou see the number
11
,but the rest is not critical.
2. Install Command-Line Tools |
Next, you will install our textbook libraries,SpotBugs, PMD, and Checkstyle to/usr/local/lift
and associated wrapper scripts to/usr/local/bin
.
- Type the following commands:The command
curl
downloads files from the web. - To confirm that the command-line tools are installed,type the following command:You should hear an A-scale.
.bashrc
) or set anyenvironment variables (such as JAVA_HOME
or CLASSPATH
).For reference, here are our recommended shell configuation files for Bash:- .bashrc
- .bash_profile
3. Install IntelliJ |
Now, you will install IntelliJ.
- Download and install IntelliJ IDEA, Community Edition 2020.1 for Linux.Use all of the default options.
- Download our IntelliJ preferences to your home directory.
Warning
This will overwrite any previous IntelliJ 2020.1 settings with ournovice-friendly settings.
4. 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).
- Download the project for your programming assignment to a convenient location(such as the Desktop).
[ 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) ]
Unzip the zip file using the following command:This creates a project folder with thename of the corresponding programming assignment (such as
hello
orpercolation
).Delete the zip file.Warning
The project folders contain course-specific information. Be sure to downloadthe one corresponding to your institution and course.
- Launch IntelliJ.
- When you launch IntelliJ for the first time,
- IntelliJ may displaytheJetBrains privacy policy.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.You should see an assignment logo (in the main editor window) and a list of project files (in the Project View sidebar at left).
When you launch IntelliJ for the first time,it may take a minute or two to index your files;some features (such as auto importing) will be unavailable until this process completes.Warning
Do not select Create New Project;this option is intended for advanced programmers.Also, always use Open with a project folder, not an individual file. - You will need to manually configure the Platform SDK. To do so,
- Navigate to File → Project Structure → Platform Settings → SDKs.
- Click the + symbol (top left) to add an SDK.
- Locate an SDK. A typical location for a Java SDK onLinux is
/usr/lib/jvm/java-11-openjdk-amd64/
. - Use the shorthand name suggested by IntelliJ(e.g., 11 for version 11.0.7).
- When you are finished working, select the menu optionFile → Exit to exit IntelliJ.The next time you launch IntelliJ, your recent projectswill appear in the Welcome screen for easy access.
5. 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.
- To create a new Java program:
- Re-open IntelliJ and the project (if you closed it in the previous step).
- Click the project name in the Project View sidebar (at left), so that itbecomes highlighted.
- Select the menu option LIFT → New Java Class.When prompted, type HelloWorld for the Name and click OK.
- In the main editor window, complete the Java program
HelloWorld.java
exactly 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. - As you type, IntelliJ highlights different syntactic elementsin different colors.When you type a left bracket, IntelliJ adds the matching right bracket.When you begin a new line, IntelliJ indents it.
- To save the file, select the menu option File → Save All (Ctrl + S).When you save the file, IntelliJ re-formats it (if necessary).
Download Java Jdk For Linux
6. 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.
- Select the program that you wish to compile and execute in the the Project View sidebar. The program should now appear in the main editor window.
- To compile your program,select the menu optionLIFT → Recompile 'HelloWorld.java' (Ctrl + B).If the compilation succeeds, you will receive confirmationin the status bar (at bottom).
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.
- To execute your program,select the menu option LIFT → Run 'HelloWorld' with Arguments (Ctrl + E).Since this program takes no command-line arguments, click OK.
You should see the output of the program (in white), along with a messagethat the program finished normally (with exit code 0).
Tip
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).
7. 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.
- Select the menu option View → Tool Windows → Terminal (Alt + 2).
- This will launch a Bash terminal where you type commands.You will see a command prompt that looks something like this:
The
~/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 thecommand prompt.Assuming that the fileHelloWorld.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: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 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).
8. 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 programBarnsley.javauses our standard drawing and standard random libraries in
stdlib.jar
to draw aBarnsley fern.First download Barnsley.java.Then, use your system's file manager (such as Nautilus) to move itto a project folder (such ashello
).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.
- Algorithms, 4th Edition (including COS 226 and Coursera students).The programCollidingDisks.javauses various libraries in
algs4.jar
to simulate the motion of n disks subject to the lawsof elastic collision.First download CollidingDisks.javaThen, use your system's file manager (such as Nautilus) to move it to a project folder (such aspercolation
).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 - How is the software licensed?
- All of the included software is licensed under various open-source licenses.
- IntelliJ IDEA, Community Edition is licensed under theApache License, Version 2.0.
- OpenJDK 11 is licensed under theGNU General Public License,version 2, with the Classpath Exception.
- SpotBugs is licensed under theGNU Lesser Public License, Version 2.1.
- Checkstyle is licensed under theGNU Lesser Public License, Version 2.1.
- PMD is licensed under a BSD-style license.
- stdlib.jar and algs4.jar are licensed under theGNU General Public License, Version 3.
- My distribution of Linux is{ Gentoo, Debian, Ubuntu, Fedora, Red Hat, SuSE, Mandriva, or Slackware }.How should I modify the instructions?
- We haven't tested out these instructions on all flavors of Linux, butthe instructions should be identical except for installing Java.We recommend using your distribution'spackage manager(such as
apt
,zypper
,emerge
, oryum
) to install Java. - Can I use a vendor and version of Java other than OpenJDK 11?
- Yes.You may use any version of Java 8, Java 9, Java 10, or Java 12, from either Oracle or OpenJDK.However, if you do so, you will need to manually configure the Platform SDK and Project SDK viaIntelliJ via File → Project Structure.
- How can I check which version of Java is installed (and where it is installed)?
- Type the following commands in the terminal:It's important that the Java version numbers match and that you see the number
11
,but the rest is not critical. - How does this custom version of IntelliJ different from the standard one?
- IntelliJis an industrial-strength integrated development environment (IDE),suitable for use by professional programmers.The installer configures your user preferences to make itmore suitable for use by novice programmers:
- Disables all built-in plugins except Terminal and JUnit. Installs the SpotBugs, Checkstyle-IDEA, Run-with-Arguments, Save-Actions, and Archive browser 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
, andalgs4.jar
). - Configures SpotBugs 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.
- What are the most important IntelliJ menu options to remember?
- Here are the most important ones (and their shortcuts).
- LIFT → New Java Class (Ctrl + N). Create a new Java class.
- LIFT → Recompile (Ctrl + B). Compile the current program.
- LIFT → Run with Arguments (Ctrl + E). Run the current program with command-line arguments.
- LIFT → Open in Terminal (Ctrl + T). Open a new Terminal tab.
- File → Save All (Ctrl + S). Save (and reformat) all open files.
- View → Tool Windows → Project (Alt + 1). Show/hide the Project View sidebar.
- View → Tool Windows → Terminal (Alt + 2). Show/hide the Terminal window.
- Any special characters to avoid when naming IntelliJ projects or files?
- Do not use an exclamation point (!) as the last characterin the project folder (or any directory name along the path to your project folder);that will confuse both IntelliJ and Checkstyle.
- How can I create a new project in IntelliJ?
- If you want to inherit all of the properties of an existing project,
- Use your system's file manager (such as Nautilus) to copy the project folder,giving it your preferred name.
- Delete any unwanted files.
- Be sure to keepthe
.iml
file (which defines the project),the.idea
subdirectory (which containsthe IntelliJ course preferences), andthe.lift
subdirectory (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.
- Can I use a version of IntelliJ that is more recent than 2020.1.1?
- Yes, though if it is 2020.2 (or above),you will need to migrate your user preferences.
- How I can I restore the original IntelliJ settings(instead of the abbreviated novice-friendly ones)?
- To restore the menus and toolbars: Preferences → Appearances & Behavior → Menus and Toolbars → Restore All Defaults.
- To restore all settings: Help → Find Action → Restore Default Settings.
- When I compile or execute a program from the command line that uses one of thetextbook 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
orjava-algs4
. - How should I configure Bash?
- If you followed our instructions, our wrapper scripts (such as
javac-algs4
andjava-algs4
)should already be available.Our autoinstaller customizes the command line in a few ways by copying these three configuration files:
.bashrc
,.bash_profile
, and.inputrc
. - How do I break out of a program in an infinite loop?
- Type
Ctrl-C
. - How do I specify EOF to signal that standard input is empty?
- On Mac OS X and Linux, type
Enter
Ctrl-D
.On Windows, typeEnter
Ctrl-Z
Enter
,even in Git Bash. - How can I run SpotBugs, PMD, and Checkstyle from the command line?
- The installer includes wrapper scripts to simplify this process.
- To run SpotBugs 4.0.3, type the following command in the terminal:The argument must be a list of
.class
files.Here is a list ofbug descriptions. - To run PMD 6.15.0, type the following command in the terminal:The argument must be either a single
.java
file ora directory containing one or more.java
files.Here is a list of bug patterns. - To run Checkstyle 8.31, type one ofthe following commands in the terminal, depending on whether you are COS 126, COS 226, or Coursera student:The argument must be a list of
.java
files.Here is a list ofavailable checks.
- To run SpotBugs 4.0.3, type the following command in the terminal:The argument must be a list of
- How do I verify that
/usr/local/bin
is in myPATH
environment variable? - Type the following command:You should see the entry
/usr/local/bin
,where entries are delimited by the colon (:) character.
Linux FAQIntelliJ FAQ
(P)Bookmarks.dev - Open source Bookmarks and Codelets Manager for Developers & Co. See our How To guides to help you get started. Share your favorites bookmarks with the community and they might get published on Github -
Well, I've recently gone to the 'silver' side and acquired a MacBook Pro to use it for development when I am not at my PC. By development I mean here mainly Java + Javascript development. So I've written this post to remember what I had to install/configure to achieve this goal.
I need to mention that until now I've been a user of Windows (XP/7) and Linux (Ubuntu/Mint/Cent OS) operation systems.
At the time of this writing MacBook Pro runs on OS X Yosemite Version 10.10.5. The new version El Capitan was available, but I didn't do the upgrade first because it had to many bad reviews…
Contents
- JDK
- Extras
- Keyboard shortcuts
- MySQL
- Terminal window
JDK
So first things first- installe a Java Development Kit (JDK), which is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
Download the Mac OS X x64 .dmg files version
You can find out where the JDK is installed, by executing the /usr/libexec/java_home -v 1.7
, on the terminal command:
You will need to know this when setting up a project in IntelliJ for example.
Set JAVA_HOME
JAVA_HOME
is just a convention, usually used by Tomcat, other Java EE app servers and build tools such as Maven
to find where Java lives.
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME
variable to /usr/libexec/java_home
, just export $JAVA_HOME
in file ~/.bash_profile
or ~/.profile
Maven
- Log in to the user account in which you will be programming.Your account must have Administrator privileges and you must be connected to the Internet.
- Launch your shell.We'll assume that the command prompt looks like the following (though your command promptwill likely differ):The symbol
~
is shorthand for your home directory. - Install theJava SE Development Kit 11,either fromOpenJDKorOracle.Many Linux distributions (such as Ubuntu 18.04 or 20.04) includeOpenJDK 11 by default, so you can skip this step.Otherwise, use your Linux distribution's package manager(see the first FAQ) to installOpenJDK 11.For example, here are the commands for Ubuntu 16.04:
- To confirm that Java 11 is installed,type the following commands:It's important that the Java version numbers match and thatyou see the number
11
,but the rest is not critical.
2. Install Command-Line Tools |
Next, you will install our textbook libraries,SpotBugs, PMD, and Checkstyle to/usr/local/lift
and associated wrapper scripts to/usr/local/bin
.
- Type the following commands:The command
curl
downloads files from the web. - To confirm that the command-line tools are installed,type the following command:You should hear an A-scale.
.bashrc
) or set anyenvironment variables (such as JAVA_HOME
or CLASSPATH
).For reference, here are our recommended shell configuation files for Bash:- .bashrc
- .bash_profile
3. Install IntelliJ |
Now, you will install IntelliJ.
- Download and install IntelliJ IDEA, Community Edition 2020.1 for Linux.Use all of the default options.
- Download our IntelliJ preferences to your home directory.
Warning
This will overwrite any previous IntelliJ 2020.1 settings with ournovice-friendly settings.
4. 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).
- Download the project for your programming assignment to a convenient location(such as the Desktop).
[ 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) ]
Unzip the zip file using the following command:This creates a project folder with thename of the corresponding programming assignment (such as
hello
orpercolation
).Delete the zip file.Warning
The project folders contain course-specific information. Be sure to downloadthe one corresponding to your institution and course.
- Launch IntelliJ.
- When you launch IntelliJ for the first time,
- IntelliJ may displaytheJetBrains privacy policy.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.You should see an assignment logo (in the main editor window) and a list of project files (in the Project View sidebar at left).
When you launch IntelliJ for the first time,it may take a minute or two to index your files;some features (such as auto importing) will be unavailable until this process completes.Warning
Do not select Create New Project;this option is intended for advanced programmers.Also, always use Open with a project folder, not an individual file. - You will need to manually configure the Platform SDK. To do so,
- Navigate to File → Project Structure → Platform Settings → SDKs.
- Click the + symbol (top left) to add an SDK.
- Locate an SDK. A typical location for a Java SDK onLinux is
/usr/lib/jvm/java-11-openjdk-amd64/
. - Use the shorthand name suggested by IntelliJ(e.g., 11 for version 11.0.7).
- When you are finished working, select the menu optionFile → Exit to exit IntelliJ.The next time you launch IntelliJ, your recent projectswill appear in the Welcome screen for easy access.
5. 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.
- To create a new Java program:
- Re-open IntelliJ and the project (if you closed it in the previous step).
- Click the project name in the Project View sidebar (at left), so that itbecomes highlighted.
- Select the menu option LIFT → New Java Class.When prompted, type HelloWorld for the Name and click OK.
- In the main editor window, complete the Java program
HelloWorld.java
exactly 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. - As you type, IntelliJ highlights different syntactic elementsin different colors.When you type a left bracket, IntelliJ adds the matching right bracket.When you begin a new line, IntelliJ indents it.
- To save the file, select the menu option File → Save All (Ctrl + S).When you save the file, IntelliJ re-formats it (if necessary).
Download Java Jdk For Linux
6. 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.
- Select the program that you wish to compile and execute in the the Project View sidebar. The program should now appear in the main editor window.
- To compile your program,select the menu optionLIFT → Recompile 'HelloWorld.java' (Ctrl + B).If the compilation succeeds, you will receive confirmationin the status bar (at bottom).
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.
- To execute your program,select the menu option LIFT → Run 'HelloWorld' with Arguments (Ctrl + E).Since this program takes no command-line arguments, click OK.
You should see the output of the program (in white), along with a messagethat the program finished normally (with exit code 0).
Tip
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).
7. 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.
- Select the menu option View → Tool Windows → Terminal (Alt + 2).
- This will launch a Bash terminal where you type commands.You will see a command prompt that looks something like this:
The
~/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 thecommand prompt.Assuming that the fileHelloWorld.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: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 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).
8. 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 programBarnsley.javauses our standard drawing and standard random libraries in
stdlib.jar
to draw aBarnsley fern.First download Barnsley.java.Then, use your system's file manager (such as Nautilus) to move itto a project folder (such ashello
).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.
- Algorithms, 4th Edition (including COS 226 and Coursera students).The programCollidingDisks.javauses various libraries in
algs4.jar
to simulate the motion of n disks subject to the lawsof elastic collision.First download CollidingDisks.javaThen, use your system's file manager (such as Nautilus) to move it to a project folder (such aspercolation
).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 - How is the software licensed?
- All of the included software is licensed under various open-source licenses.
- IntelliJ IDEA, Community Edition is licensed under theApache License, Version 2.0.
- OpenJDK 11 is licensed under theGNU General Public License,version 2, with the Classpath Exception.
- SpotBugs is licensed under theGNU Lesser Public License, Version 2.1.
- Checkstyle is licensed under theGNU Lesser Public License, Version 2.1.
- PMD is licensed under a BSD-style license.
- stdlib.jar and algs4.jar are licensed under theGNU General Public License, Version 3.
- My distribution of Linux is{ Gentoo, Debian, Ubuntu, Fedora, Red Hat, SuSE, Mandriva, or Slackware }.How should I modify the instructions?
- We haven't tested out these instructions on all flavors of Linux, butthe instructions should be identical except for installing Java.We recommend using your distribution'spackage manager(such as
apt
,zypper
,emerge
, oryum
) to install Java. - Can I use a vendor and version of Java other than OpenJDK 11?
- Yes.You may use any version of Java 8, Java 9, Java 10, or Java 12, from either Oracle or OpenJDK.However, if you do so, you will need to manually configure the Platform SDK and Project SDK viaIntelliJ via File → Project Structure.
- How can I check which version of Java is installed (and where it is installed)?
- Type the following commands in the terminal:It's important that the Java version numbers match and that you see the number
11
,but the rest is not critical. - How does this custom version of IntelliJ different from the standard one?
- IntelliJis an industrial-strength integrated development environment (IDE),suitable for use by professional programmers.The installer configures your user preferences to make itmore suitable for use by novice programmers:
- Disables all built-in plugins except Terminal and JUnit. Installs the SpotBugs, Checkstyle-IDEA, Run-with-Arguments, Save-Actions, and Archive browser 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
, andalgs4.jar
). - Configures SpotBugs 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.
- What are the most important IntelliJ menu options to remember?
- Here are the most important ones (and their shortcuts).
- LIFT → New Java Class (Ctrl + N). Create a new Java class.
- LIFT → Recompile (Ctrl + B). Compile the current program.
- LIFT → Run with Arguments (Ctrl + E). Run the current program with command-line arguments.
- LIFT → Open in Terminal (Ctrl + T). Open a new Terminal tab.
- File → Save All (Ctrl + S). Save (and reformat) all open files.
- View → Tool Windows → Project (Alt + 1). Show/hide the Project View sidebar.
- View → Tool Windows → Terminal (Alt + 2). Show/hide the Terminal window.
- Any special characters to avoid when naming IntelliJ projects or files?
- Do not use an exclamation point (!) as the last characterin the project folder (or any directory name along the path to your project folder);that will confuse both IntelliJ and Checkstyle.
- How can I create a new project in IntelliJ?
- If you want to inherit all of the properties of an existing project,
- Use your system's file manager (such as Nautilus) to copy the project folder,giving it your preferred name.
- Delete any unwanted files.
- Be sure to keepthe
.iml
file (which defines the project),the.idea
subdirectory (which containsthe IntelliJ course preferences), andthe.lift
subdirectory (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.
- Can I use a version of IntelliJ that is more recent than 2020.1.1?
- Yes, though if it is 2020.2 (or above),you will need to migrate your user preferences.
- How I can I restore the original IntelliJ settings(instead of the abbreviated novice-friendly ones)?
- To restore the menus and toolbars: Preferences → Appearances & Behavior → Menus and Toolbars → Restore All Defaults.
- To restore all settings: Help → Find Action → Restore Default Settings.
- When I compile or execute a program from the command line that uses one of thetextbook 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
orjava-algs4
. - How should I configure Bash?
- If you followed our instructions, our wrapper scripts (such as
javac-algs4
andjava-algs4
)should already be available.Our autoinstaller customizes the command line in a few ways by copying these three configuration files:
.bashrc
,.bash_profile
, and.inputrc
. - How do I break out of a program in an infinite loop?
- Type
Ctrl-C
. - How do I specify EOF to signal that standard input is empty?
- On Mac OS X and Linux, type
Enter
Ctrl-D
.On Windows, typeEnter
Ctrl-Z
Enter
,even in Git Bash. - How can I run SpotBugs, PMD, and Checkstyle from the command line?
- The installer includes wrapper scripts to simplify this process.
- To run SpotBugs 4.0.3, type the following command in the terminal:The argument must be a list of
.class
files.Here is a list ofbug descriptions. - To run PMD 6.15.0, type the following command in the terminal:The argument must be either a single
.java
file ora directory containing one or more.java
files.Here is a list of bug patterns. - To run Checkstyle 8.31, type one ofthe following commands in the terminal, depending on whether you are COS 126, COS 226, or Coursera student:The argument must be a list of
.java
files.Here is a list ofavailable checks.
- To run SpotBugs 4.0.3, type the following command in the terminal:The argument must be a list of
- How do I verify that
/usr/local/bin
is in myPATH
environment variable? - Type the following command:You should see the entry
/usr/local/bin
,where entries are delimited by the colon (:) character.
Linux FAQIntelliJ FAQ
(P)Bookmarks.dev - Open source Bookmarks and Codelets Manager for Developers & Co. See our How To guides to help you get started. Share your favorites bookmarks with the community and they might get published on Github -
Well, I've recently gone to the 'silver' side and acquired a MacBook Pro to use it for development when I am not at my PC. By development I mean here mainly Java + Javascript development. So I've written this post to remember what I had to install/configure to achieve this goal.
I need to mention that until now I've been a user of Windows (XP/7) and Linux (Ubuntu/Mint/Cent OS) operation systems.
At the time of this writing MacBook Pro runs on OS X Yosemite Version 10.10.5. The new version El Capitan was available, but I didn't do the upgrade first because it had to many bad reviews…
Contents
- JDK
- Extras
- Keyboard shortcuts
- MySQL
- Terminal window
JDK
So first things first- installe a Java Development Kit (JDK), which is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
Download the Mac OS X x64 .dmg files version
You can find out where the JDK is installed, by executing the /usr/libexec/java_home -v 1.7
, on the terminal command:
You will need to know this when setting up a project in IntelliJ for example.
Set JAVA_HOME
JAVA_HOME
is just a convention, usually used by Tomcat, other Java EE app servers and build tools such as Maven
to find where Java lives.
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME
variable to /usr/libexec/java_home
, just export $JAVA_HOME
in file ~/.bash_profile
or ~/.profile
Maven
With the JAVA_HOME environment variable configure, go to the Apache Maven Downloads website, download the .tar.gz or .zip archive and unpack it in a folder of your choice – I put it under the /opt directory:
It is also recommended to create a symbolic link to the Maven home, so that when let's say you update your Maven version, you'll only have to change the symbolic link target:
Then set Maven in the environment variables
Close the terminal and open a new one. When you try now to get the maven versioning you should get something like the following:
An alternative is to use Homebrew and execute the following command:
GIT
Open a terminal window and type the following command for example:
At the next moment you will be asekd to install Xcode. This is the a complete developer toolset for building apps that run on Apple TV, Apple Watch, iPhone, iPad, and Mac. It includes the Xcode IDE, simulators, and all the required tools and frameworks to build apps for iOS, watchOS, tvOS, and OS X (it also contains GNU Compiler Collection-gcc).
You can do the above, but if you do not want everything from that package you can install Homebrew ('Homebrew installs the stuff you need that Apple didn't.') and run the following commands:
Either way once Git is installed the initial command git –version will bring the installed version:
If you are working with Github, I recommend you also install the Github Desktop
IntelliJ
In the mean time IntelliJ has become my favorite IDE, mainly because you have almost the same feature support when doing front-end development. To install it, go to the download page and follow the installation instructions:
INSTALLATION INSTRUCTIONS
- Download the idea-15.dmg OS X Disk Image file.
- Mount it as another disk in your system.
- Copy IntelliJ IDEA to your Applications folder
Once done you need to get acquainted with key shortcuts for OS X – IntelliJ IDEA Mac OS X Keymap
Extras
Keyboard shortcuts
General
Please visit](https://support.apple.com/en-us/HT201236) for usual keyboard shortcuts (Cut, copy, paste, and other common shortcuts, document shortcuts etc.)
Finder
- Shift + cmd + C > go to Computer
- Shift + cmd + H > go to Home folder
- Shift + cmd + D > go to Desktop
A quick access with the mouse to the same folders is by dragging and dropping them on the sidebar under Favorites
As long as we are by sidebar subject, a good productivity gain can be achieved by using Smart Folders – these folders let you save a search to reuse in the future. Smart Folders are updated continuously, so they always find all the files on your computer that match the search criteria. Watch the following video to see how you can easily add them to the sidebar
NodeJS
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world. Recently is a must have tool if you need to do fancier stuff on your front-end part of your application.
Go to https://nodejs.org/ and download the latest version for OS X (x64). Double click on the node-v4.2.2.pkg file (latest stable version at the writing of the post) and follow the installation instructions steps.
When ready open a terminal window and check the version installed to see if it is working:
MySQL
Go to Downloads page – http://dev.mysql.com/downloads/mysql/, download the Mac OS X 10.10 (x86, 64-bit), DMG Archive and follow the steps described in the installation guide.
Start, stop server
The MySQL Installation Package includes a MySQL preference pane that enables you to start, stop, and control automated startup during boot of your MySQL installation.
This preference pane is installed by default, and is listed under your system's System Preferences window, which can be found under Applications.
Access MySQL from command line
Basically need to add MySQL to the PATH variable. Edit the /~.bash_profile with the following:
To test that it's working start a new terminal and verify mysql version from command line:
Install MySQL Workbench
If you want to have also a GUI on top of it I recommend you install the MySQL Workbench that can be also found in the downloads section. Installation instruction is the same as the MySQL server installation.
Terminal window
Set background black
Open Terminal, then go to the Terminal menu -> Preferences, choose the Settings tab and set the Pro theme as the default.
Jump to beginning/end of a line
To jump at
- beginning of a line – Ctrl+A
- end of a line – Ctrl+E
- jump between words – Alt+
Open terminal in here
Go to:
Enable New Terminal at Folder. There's also New Terminal Tab at Folder, which will create a tab in the frontmost Terminal window (if any, else it will create a new window). Seiki sk 870t driver. These Services work in all applications, not just Finder, and they operate on folders as well as absolute pathnames selected in text.
You can even assign command keys to them.
Services appear in the Services submenu of each application menu, and within the contextual menu (Control-Click or Right-Click on a folder or pathname).
The New Terminal at Folder service will become active when you select a folder in Finder. You cannot simply have the folder open and run the service 'in place'. Go back to the parent folder, select the relevant folder, then activate the service via the Services menu or context menu.
In addition, Lion Terminal will open a new terminal window if you drag a folder (or pathname) onto the Terminal application icon, and you can also drag to the tab bar of an existing window to create a new tab.
Finally, if you drag a folder or pathname onto a tab (in the tab bar) and the foreground process is the shell, it will automatically execute a 'cd' command. (Dragging into the terminal view within the tab merely inserts the pathname on its own, as in older versions of Terminal.)
Linux Java Home
You can also do this from the command line or a shell script:
This is the command-line equivalent of dragging a folder/pathname onto the Terminal application icon.
Use aliases
To ease your life for long and usual commands use aliases. For example to connect remote instead of typing ssh ama@x.y.z.q and having to remember ip address or server name, you could just type rmcon (or whatever it's easy for you to remember). To do that append to the .bash_profile in your home directory the alias command and then source the file:
I can't stress enough, how much comfortable your life can become, if you are using aliases the right way - A developer's guide to using aliases
Commands
Find out who is listening on port (e.g. 8080)
iTerm2
A very nice alternative to the 'classic' terminal is iTerm, now in version 2:
'iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with OS 10.5 (Leopard) or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted'
Look under Preferences > Keys for shortcuts to easily navigate/move the tabs…
Generate ssh keys
Open a terminal window and execute the following command:
Man pages:
ssh-keygen generates, manages and converts authentication keys for ssh(1).ssh-keygen can create RSA keys for use by SSH protocol version 1 and DSA, ECDSA, ED25519 or RSA keys for use by SSH protocol version 2.The type of key to be generated is specified with the -t option.If invoked without any arguments, ssh-keygen will generate an RSA key for use in SSH protocol 2 connec-tions.
You will be asked then where to store the key (default under /Users/YOUR_USERNAME/.ssh/id_rsa)
When asked for a passphrase you can enter a passphrase to add it to the key. If you choose to add a passphrase every time you want to use your key with ssh, you'll have to enter this passphrase. It is a little bit more inconvenient, but more secure.
Once that is done, you should get a message like the following:
You can now use the generated id_rsa.pub key and upload it to the systems you want to connect to over ssh.
Install Programs from Unidentified Developers {.title}
By default, Mac OS only allows users to install applications from ‘verified sources.' To change that open the System Preferences > Security & Privacy > General and select 'Allow applications downloaded from: Anywhere'. Follow this link, to see a more detailed description with pictures.
Mac Or Linux For Java Development Tutorial
Often used UNIX keys on the German/Swiss keyboard
I bought the Mac Book to use it as developer machine on the go and one of my initial surprises was the missing of some keys a developer/terminal user uses pretty often like []|{}~
Find below a map for these keys:
So here it is, my personal keyboard map reminder for the Mac OS X:
| | pipe symbol | alt7 |
backslash | alt shift 7 = alt/ | |
[ | left (opening) square bracket | alt 5 |
] | right (closing) square bracket | alt 6 |
{ | left (opening) curly bracket | alt 8 |
} | right (closing) curly bracket | alt 9 |
~ | Tilde | alt n followed by the space key |
@ | 'At' symbol | alt g (lowercase G) alt L German Keyboard |
How to test everything is working
A smoke test to verify if everything installed is functioning properly 'together' is to generate an application with JHipster and push it to a git repository.
JHipster is a Yeoman generator, used to create a Spring Boot + AngularJS project.
For any suggestions please leave a comment. Thank you.
References
Adrian Matei