Development Environments

Integrated Development Environments

Using IntelliJ IDEA

  

Logo IntelliJ

IntelliJ IDEA is a multi platform IDE developed by JetBrains. It was firstly released in 2001 as IntelliJ, and it was one of the first IDEs with advanced browsing and code refactoring. We can consider it a specific purpose IDE, since it focuses on a few group of programming languages.

It is available in two versions: Community Edition (free) and Ultimate Edition (commercial). The main difference between them can be found in the languages and version control systems supported. For instance, Community version does not allow PHP or Javascript. In our case, as we are going to work with Java Virtual Machine, we need to download the Community edition, which is free and open source. This is the download page.

IntelliJ download page

1. Installation and setup

Regarding the installation process:

IntelliJ download page

The first time that we run IntelliJ, it lets us import previous settings, if we had any previous version installed. If not, we can just choose “Do not import settings”. Next, we can choose the UI theme…

IntelliJ UI theme

Next, it lets us define a script to launch programs from command line, but we can skip this step and move to the next one, in which we can choose to install some additional plugins. We can also leave this step with its default settings, and start using IntelliJ.

2. Creating Java projects

From the welcome screen, we can choose among:

So, if we want to create a new project, we choose the option New Project, and then specify that we want to create a Java project, from the left panel:

IntelliJ welcome screen

Next, we can choose a template for our project in order to generate some default code, but, as we don’t have any previous template, we can skip this step, and move to the next one, in which we must specify a project name and location (we can leave the default location if we want to):

IntelliJ welcome screen

NOTE: by default, IntelliJ stores the projects inside a folder called IdeaProjects inside our home folder. Each project is assigned a subfolder inside this main folder.

Then, we click on Finish and we will see our project. If we click on the project tab on the left, we can see the project folder structure, and create elements (source files) on it.

IntelliJ welcome screen

Now, let’s create our first source file. Right click on the src folder and choose New > Java Class.

IntelliJ welcome screen

Then, we must specify the class name. For instance, Hello.

IntelliJ welcome screen

A new file will be created, and we can edit it in the main area. We can just leave a code like this one:

IntelliJ code editor

We can run the file by right clicking on it and choosing “Run Hello.main()” option:

IntelliJ run program

Then, we can check the results in the embedded terminal at the bottom of the window:

IntelliJ terminal

3. Keybindings

In the following table you can see some of the most common keybindings or shortcuts available for IntelliJ IDEA under Windows systems.

Shortcut Action
Ctrl+Shift+N Open new file.
Ctrl+N Open any class.
Ctrl+Spacebar Complete code.
Ctrl+Shift+Spacebar Smart code completion.
Ctrl+S Save file.
Ctrl+O Overwrite methods.
Ctrl+I Implement all.
Ctrl+/ Comment / Uncomment line.
Ctrl+D Duplicate line.
Ctrl+Z Undo last action.
Ctrl+Shift+Z Redo last undone action.
Ctrl+F Show search dialog.
Ctrl+R Show replace dialog.
Ctrl+F9 Compile project.
Shift+F10 Run project.
Shift+F9 Debug.
F7 Step into function (in debug mode).
F8 Next line (in debug mode).
F9 Stop debug.
Ctrl+F8 Create breakpoint.
Ctrl+Shift+F12 Maximize editor panel.

Most of these shortcuts are also available under Linux. Regarding MacOSX systems, you must replace Ctrl key with Cmd key. You can find more shortcuts here.

Exercise 1:

Create a new Java project with IntelliJ called Test and copy this code in a class called Test. Then, run the application to check if everything is OK.

public class Test
{
    public static void main(String[] args)
    {
        System.out.println("Hello");
        System.out.println("Have a nice day!");
        System.out.println("And learn a lot of Java :-)");
    }
}