IntelliJ IDEA Essentials Sample Chapter
IntelliJ IDEA Essentials Sample Chapter
I would like to thank my wife, Marylka, and my two boys, Wojtu and
Mati, for being patient and letting me finish the book. Without their help
and understanding, this book would not have been possible.
I would like to thank all the people at Packt Publishing, especially
Govindan K, Aman Preet Singh, Ellen Bishop, Richard Gall, and Sam
Woodyou've made the entire writing and publishing process very smooth
and straightforward. A special thanks to all the technical reviewers and
proofreaders for providing me with valuable feedback from which I have
learned a lot. Thank you.
Greetings to my friends at 7N, Nykredit, Kredyt Bank, and Bank BPSI
hope you enjoy reading the book as much as I enjoyed writing it.
server or standalone. This chapter focusses not only on Java, but on other technologies
such as Node.js as well.
Chapter 6, Building Your Project, focusses on building a project. You use IntelliJ IDEA's
own build system, and Maven and Gradle integration as well.
Chapter 7, Red or Green? Test Your Code, is all about unit testing in IntelliJ IDEA. We
focus on setting IntelliJ IDEA up specifically to run tests. You create JUnit and TestNG
run configurations and then run and debug the tests. Then, you are given a brief overview
of the test runner windows, useful settings, and option suggestions.
Chapter 8, Squash'em The Debugger, focusses on the IntelliJ IDEA debugger. You get
familiar with the debugger tool window and debugger options. We look under the hood
evaluating expressions, using watches, conditional breakpoints, and other debugger
features. We also talk briefly about remote debugging.
Chapter 9, Working with Your Team, This chapter is all about version control, and
managing change lists and tasks. There is a brief description on how to set up VCS
integration, with the main focus on Git. This chapter describes integration with popular
bug trackers, such as JIRA and YouTRACK.
Chapter 10, Not Enough? Extend It, describes briefly the plugin architecture of IntelliJ
IDEA. We talk about possibilities and develop a simple plugin, so that you have
knowledge of how to extend the IDE. You are also presented with useful links and
resources to develop your knowledge even further..
Workspace overview
IDE settings
long story short, there are many features missing in the Community Edition, but
there are some workarounds available if you look close enough. For example, when
you want to use Tomcat or Jetty servers in the Community Edition, you can use
Maven plugins to run and debug your web applications freely. We will discuss
this in Chapter 5, Make It Happen Running Your Project.
You can use the Community Edition to develop applications using many
frameworks such as Play, Struts, or Spring. It's all Java, after all. The IDE will not
assist you in that. Most of the configuration hints, warnings, autocompletion, and
runtime configuration features will be unavailable.
The Ultimate Edition, on the other hand, is the full-featured commercial IDE. You
have the full support of almost all of the modern frameworks and application
servers. The IDE will assist you by providing code completion, hints, and diagrams.
The language support in this edition is also more comprehensive; you will get HTML
and scripting languages analysis available on the fly, for example.
Apart from the provided features, the Ultimate Edition can be categorized
based on the license. Depending on your needs, you can purchase any of the
following licenses:
Personal license: IntelliJ IDEA can be used only by the person who
purchased it. You can use it on as many computers as you own, as long as
you are the only user. The Personal license, of course, can also be used to
develop commercial products.
Additionally, there are some licensing options and discounts based on the target
audience, for startups, students, and teachers, for education or training, and finally,
for open source projects.
When you decide to buy the Ultimate Edition, sometimes it is wise
to wait till the holidays, for example, Christmas or Easter. The
JetBrains team usually provides some discounts on their products
then.
[8]
Chapter 1
During the first startup, IntelliJ IDEA will ask you which plugins should be enabled
by default. Usually, it's best to enable only what you need, so the IDE loads and
works faster with fewer plugins enabled. Don't worry if you don't know what to
select; you can always change your mind later by editing the IDE settings. On the
first startup, you will not be able to see the workspace without the project opened.
While we will go through the details of creating the project in the next chapter, you
can now just create the basic Java project by choosing New Project
from the File menu, selecting Java, and proceeding with the New Project wizard
by clicking on Next a couple of times.
Tool windows
The tool windows are hidden, by default, in Version 13 and later of IDEA. You
can toggle them on and off using the button in the bottom-left corner of the screen:
[9]
Tool windows are those little "tabs" visible at the edges of the workspace.
These edges are called tool window bars, as shown in the following screenshot:
Some of the tool windows are always available, such as Project or Structure, while
some of them are available only when the corresponding plugins are enabled.
You can arrange the order of the tool windows by dragging them with your mouse.
You can drag the tool window to other screen edges as well.
There's a fourth tool window bar available at the top of the screen,
which is hidden. Just drag any tool window to the top of your
workspace to use it, as shown in the following screenshot:
[ 10 ]
Chapter 1
Pinned Mode
The pinned tool window will stay open even when it becomes inactive by losing
focus. You may prefer to have the Project tool window pinned to have a constant
overview of the project structure. Only docked windows can be pinned. On the
other hand, you can keep the project view closed almost all the time and simply
use the keyboard shortcuts to navigate. On large projects, this approach is much
faster than searching the tree manually for your file.
Docked Mode
When docked, the tool window will share the total workspace area with other
workspace elements such as the editor. On the other hand, when undocked, the
tool window will overlap the other workspace elements when resized. An undocked
window will go away if inactive. For example, it is especially useful to have the
console tool window undocked and resized; reading huge logfiles or console output
will be a lot easier.
[ 11 ]
Floating Mode
Floating, as the name suggests, allows the tool window to float over the workspace
and be detached from the screen edges. It may be useful when you work on
multimonitor environments with huge display resolutions set. There are no limiting
factors for the number of floating windows shown simultaneously. When floating,
tool windows can be easily arranged to suit your needs.
Split Mode
The tool window will share the tool window bar with other tool windows when it
has Split Mode enabled. This gives you the ability to see two tool windows at once.
It's nice to see the project structure and file structure at the same time, as shown
in the following screenshot:
When you use the Ctrl + left-click (PC) or cmd + left-click (Mac) keyboard shortcuts,
the splitter between the two tool windows is displayed at once; IntelliJ IDEA will
switch them to the wide screen mode and display them in a horizontal layout. It is
priceless when you work on a fancy panoramic display and would like to use the
screen space effectively, as shown in the following screenshot:
[ 12 ]
Chapter 1
[ 13 ]
These views can be made visible as separate tabs by selecting Show views as tabs in
the tool window context menu:
When you have your tool windows set up, it may be a good idea to back up your
current layout. You can save the way the tool windows are currently arranged by
navigating to Window | Store Current Layout as Default in the main menu. You
can always load the saved workspace layout by navigating to Window | Restore
Default Layout or pressing Shift + F12.
You can quickly open your last active tool window by using the F12 (PC) or Fn +
F12 (Mac) keyboard shortcut. To make this shortcut work on Mac, you first need to
adjust the F12 system shortcut behavior in the System Preferences window available
in the Apple menu. To quickly hide/unhide all tool windows and focus on the
editor, press Ctrl + Shift+ F12 (PC) or cmd + Fn + Shift + F12 (Mac).
The Esc key will always get you back into the editor.
When switched off, you can temporarily show the tool window bars by pressing the
left Alt key (PC) twice or tapping and holding down the left cmd button (Mac). This
way, you can switch tool windows swiftly and save screen space at the same time.
[ 14 ]
Chapter 1
[ 15 ]
Next, set up preferences for particular tool windows. Select Hide to switch off the
specific tool window and Show to turn it on, as shown in the following screenshot:
Editor tabs
An important part of the workspace is the editor tabs. They represent opened files
and have a context menu with file-specific options, such as adding a file to a favorites
list or using version control on the file.
Tabs are great to switch files, but there is a drawback here. They occupy some of the
editor space when you have many files opened. The limit of the visible tab count can
be set by navigating to Settings | Editor | General | Editor tabs (PC) or IntelliJ
IDEA | Preferences | Editor | Editor tabs (Mac) dialog box. IntelliJ IDEA autocloses
tabs if the tab count exceeds the defined limit. This is a very useful feature to reduce
the tab clutter. IntelliJ IDEA will always close the least used tab.
Consider switching tabs off completely. It may sound a little weird at the beginning,
but when you develop the habit of using keyboard shortcuts to navigate through
opened files, you will not need tabs, and will regain some of the valuable editor space.
Use Ctrl + E (PC) or cmd + E (Mac) to display the list of opened files.
Use Ctrl + Shift + E (PC) or cmd + Shift + E (Mac) to display the list of
recently edited files. You can also switch between the last opened files
with Ctrl + Tab and Ctrl + Shift + Tab.
[ 16 ]
Chapter 1
[ 17 ]
When defining a new keyboard shortcut, the Second Stroke keyboard shortcut
editor feature is very useful. You can use this to set up double strokes, easy to
remember keyboard shortcuts, or even shortcut groups. You can define your base
shortcut, such as Ctrl + Shift + O for example, and then numbers as second strokes,
as shown in the following screenshot:
The Abbreviation option in the keyboard shortcut editor is used to quickly find the
Search Everything (double Shift) dialog box. The Search Everything dialog box will
be discussed in Chapter 3, The Editor.
[ 18 ]
Chapter 1
For example, if you use the Darcula IDE theme, the Obsidian color scheme looks
good, as shown in the following screenshot:
There is a truly great font designed especially for developers: Source Code
Pro. This font family was created specifically for coding environments
it's very readable. It's available free of charge from Adobe, at GitHub
https://github.com/adobe/source-code-pro.
You can download Source Code Pro for Windows, Linux, and OS X
as well.
You can sort the list of plugins by the download count or rating to see
the most popular (and probably the most useful) plugins at the top of
the list:
To deactivate the installed plugin, uncheck the checkbox next to its name. To
uninstall the plugin, use the context menu, but take note that bundled JetBrains
plugins cannot be uninstalled from within the IDE, as shown here:
Some of the plugins add new languages to the IntelliJ IDEA arsenal. If you develop
in a language other than Java, just filter the plugins list using the Custom Languages
option. When you install the plugins, the on-the-fly analysis, hints, and refactoring
will be available in your IDE. These plugins include, for example, Scala, Python,
Ruby, PHP, and many others.
The next huge group of plugins is available when you filter using Framework
Integration. There is a big chance you will find support for the framework you
use in your project, such as AngularJS or Play, for example.
If you are new to IntelliJ IDEA, there is a plugin that is especially useful called Key
promoter. It will show you a banner with the keyboard shortcut for the action you
just performed using the mouse. It will help you memorize keyboard shortcuts and
quickly become a keyboard ninja:
[ 20 ]
Chapter 1
Feel free to browse JetBrains and the third-party plugins directory. It's a real gold
mine to extend the IDE functionality. Select the plugin, read the description to the
right, click on Install, restart the IDE, and you're all set.
[ 21 ]
Sharing settings
Sometimes it's good to have the same configuration across all members of your team,
organization, or the company. For this purpose, IntelliJ IDEA can use a server to
store IDE settings and share them within your team.
To do this, first download the IntelliJ Configuration Server plugin, using the Plugins
page of the Settings dialog box.
To connect to the IntelliJ Configuration Server, use your JetBrains account. If you don't
have the account, you can create one on the JetBrains website using the link provided
in the login dialog.
You can connect to IntelliJ Configuration Server in two ways: during the first startup
or on demand.
During the first IntelliJ IDEA startup after installing the plugin, you can select the
connection option for the next startup, such as Show login dialog, Login silently,
or Do not login.
When the configuration server is connected, the green icon is displayed in the status
bar, as shown in the following screenshot:
[ 22 ]
Chapter 1
You can log in to the IntelliJ Configuration Server at any time using the button on
the status bar.
The IntelliJ IDEA server stores almost all of the IDE and project settings except for
those containing local paths. Your code style settings, keymaps, fonts, color schemes,
and inspection profiles will be synced.
Take note that the IntelliJ IDEA server is a public, third-party server. It's secured by a
username and password and uses SSL communication, but if you are very concerned
about your privacy, you should share your settings using the export/import feature
rather than the IntelliJ Configuration Server.
If you have to use a proxy to access the Internet in your
environment, you can set up the proxy settings in the login
dialog box.
On Linux and Unix systems, you can tweak IntelliJ IDEA's own virtual machine
settings by executing the following code:
<IntelliJ IDEA installation folder>/bin/idea.vmoptions
[ 23 ]
In this file, you can find, or change, Java Virtual Machine settings that IntelliJ
IDEA runs on. For example, to increase the IntelliJ IDEA heap size, modify the
-Xmx setting. If you keep getting an OutOfMemoryError message in the PermGen
space exceptions, try changing the -XX:MaxPermSize setting.
The file-scanning applications (such as Spotlight or Alfred on OS
X, for example) can slow down the IDE a bit; think about excluding
IDEA's folders from their scope.
Having an SSD drive to develop helps a lot with the performance.
Indexing, looking for usages, and other file-related tasks will be a lot
faster on the SSD drive.
Summary
In this chapter, we discussed what IntelliJ IDEA is, briefly presented a comparison
of the available editions, and revealed the main workspace elements and how to
customize them.
Install IntelliJ IDEA and try to set up your IDE the way you like it. Use the tips
provided to configure the workspace like a pro. Back up your configuration or
share it with others.
In the next chapter, we will create and import a project and start the actual work.
[ 24 ]
www.PacktPub.com
Stay Connected: