Home Programming IntelliJ IDEA Essentials

IntelliJ IDEA Essentials

By Jaroslaw Krochmalski
books-svg-icon Book
eBook $28.99 $19.99
Print $48.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $28.99 $19.99
Print $48.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    Get to Know Your IDE, Fast
About this book
Publication date:
December 2014
Publisher
Packt
Pages
276
ISBN
9781784396930

 

Chapter 1. Get to Know Your IDE, Fast

In this chapter, we will compare IntelliJ IDEA editions and licenses, install the tool, and quickly introduce the main workspace. IntelliJ IDEA comes with many settings; it is not possible to cover all of them in one book so we will focus on the most important ones. We will cover the following topics in this chapter:

  • Comparing the various editions

  • Installing the tool

  • Workspace overview

  • IDE settings

  • Configuration tips and tricks

 

Comparing the various editions


IntelliJ IDEA is available as a free Community Edition and full-fledged Ultimate Edition. From the licensing point of view, the good thing is you can use both editions to develop the software you want to sell. It is worth mentioning that the new Android Studio that is used for the development of mobile Android applications is also based on IntelliJ IDEA.

The detailed comparison table can be found on the JetBrains website: http://www.jetbrains.com/idea/features/editions_comparison_matrix.html. To cut a 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:

  • Commercial license: IntelliJ IDEA can be used by any developer in your company but the total number of concurrent users cannot exceed the number of purchased 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.

Tip

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.

 

Installing IntelliJ IDEA


Installing IntelliJ IDEA is straightforward. Perform the following steps:

  1. Go to http://www.jetbrains.com/idea/download/.

  2. Pick the OS version and edition of your choice.

  3. After opening the downloaded installation package in MS Windows, you should see the installation wizard. In Mac OS, double-click on the downloaded .dmg file and then just drag IntelliJ IDEA to the Applications folder.

    Tip

    When you install IntelliJ IDEA over an existing installation, the installation wizard will ask if you want to import settings from the previous set up. Don't worry, your settings will be preserved.

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.

 

An overview of the workspace


Basically, the workspace in IntelliJ IDEA consists of the main editor with tabs, menus, and many tool windows.

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:

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.

Tip

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:

View modes in tool windows

The tool windows have a context menu available when you right-click on them. The context menu contains items specific to a particular tool window and some possible view modes, as shown in the following screenshot:

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.

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:

Tip

You can quickly go to the specific tool window by using the mnemonic shortcut displayed before its name, for example, Alt + 1 (PC) or cmd + 1 (MAC) will take you to the Project tool window. It works for hidden tool windows, too.

Multiple views in tool windows

Some tool windows have more than one view available. For example, the Project tool window can show Project, Packages, or Problems, as shown in the following screenshot:

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).

Tip

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.

Navigating inside the tool window

If the tool window contains a list (and most of them do, actually) to navigate or search inside the tool window, focus on the tool window, and just start typing the search text. It doesn't matter if it is a project or another tool window: IntelliJ IDEA will search for the characters you typed on the fly, as shown in the following screenshot:

Tool windows set up for a specific project

There is a very useful plugin you can find in the IntelliJ IDEA plugin repository named ToolWindow manager. We will talk more about installing plugins later in this chapter.

This plugin makes tool window buttons available to be controlled on a per-project basis. It allows the creation of tool window profiles, that is, you can set specific tool windows to be hidden for one project and shown for another. This is the way to keep your IDE clean and tidy.

To access the settings, go to Window | Tool Window Management | Configure Preferred Availabilities from the main menu, as shown in the following screenshot:

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.

Tip

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.

 

Crafting your settings


In the next section, we will discuss the options of the IDE—setting keyboard shortcuts, colors, fonts, and plugins.

Searching for options

The settings dialog is available from the main menu by navigating to File | Settings (PC) or IntelliJ IDEA | Preferences (Mac). You can also use the wrench icon on the toolbar or Ctrl + Alt + S (PC) or cmd + , (Mac) keyboard shortcuts. All of the settings are divided into two groups: one for project-specific settings (such as code style, version control, and so on) and one for global, IDE settings (such as appearance or HTTP proxy, for example).

There are many options here. The good thing is you can use the search field to search for a specific option. Just start typing the option name and the dialog box will be searched from top to bottom to present you the result.

For example, if you introduce a "typo" in the search box, you will be presented with the Inspection project settings, where you can turn the Spelling/Typo inspection option off. In the Editor/Colors & Font/General section, you can change colors for misspelled words.

Setting keyboard shortcuts

IntelliJ IDEA is a keyboard-centric IDE. Any action you can do by using your mouse, you can do by using the keyboard as well.

It's possible to completely redefine default IntelliJ IDEA keymaps to suit your needs. The keyboard shortcuts configuration is available in the Keymap section in the IDE settings.

There are some predefined keymaps available. Whether you come from using Eclipse or NetBeans, you can find your well-known keymap here and apply it. Please note that predefined keymaps are not editable. To modify the keymap, you must create and edit a copy.

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.

Colors and fonts

In IntelliJ IDEA, you can change your preferable colors and font's layout for syntax and error highlighting in the editor, search results, debugger, and consoles.

To do this, open Editor and then Colors & Fonts in the IDE settings dialog box.

IntelliJ IDEA comes with some predefined color schemes. You can select one of them, or create your own, and configure its settings to your liking.

Note that you are not allowed to change any of the predefined schemes. If you decide to tweak the existing theme, you have to copy it first. To change the editor font, select Font from the Colors & Fonts section of the IDE settings page.

Note

Many nice color themes can be found at http://www.ideacolorthemes.org.

For example, if you use the Darcula IDE theme, the Obsidian color scheme looks good, as shown in the following screenshot:

Tip

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.

Picking your plugins

The IntelliJ IDEA plugin repository is available on the Internet at http://plugins.jetbrains.com/?idea or from the IDE itself, by going to the Plugins section in the Settings page. Going to the Plugins section in the IDE is more convenient in comparison to the Internet repository. All you have to do is find your plugin, install, and restart the IDE.

To install JetBrains' plugin, click on the Install JetBrains plugin… button. To install a third-party plugin, choose Browse repositories. In the next dialog box, you can filter the available plugins by category, or find a specific plugin just by typing its name.

Tip

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:

Tip

Use the Key promoter plugin available in the plugins repository to see how easy you can make the same action you just did using your mouse, by only using your keyboard!

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.

 

Configuration tips and tricks


In this section, you will be presented with some configuration tips, such as sharing settings and tuning IntelliJ IDEA.

Exporting and importing settings

If you have your IDE set the way you like, it may be a good idea to back up all settings. Sometimes, it's good to have common settings across all team members. IntelliJ IDEA gives you the ability to archive and export all or specific settings.

To export IDE settings to a JAR archive, do the following:

  1. Go to File | Export Settings from the main menu.

  2. Specify the settings to export the Export Settings dialog box by selecting the checkboxes next to them. All of them are selected by default.

  3. Specify the fully qualified name and path or click on the Browse button to choose the target file.

To import IDE settings from a JAR archive, do the following:

  1. Go to File | Import Settings from the main menu.

  2. Select the desired archive from the Import File Location dialog box.

  3. Specify the settings to be imported in the Select Components to Import dialog box and click on OK.

You should be really careful with importing settings. Importing a set of settings will overwrite all your settings with the imported set. For example, if you export some live templates and reimport them during a colleague's installation, the import will overwrite all their live templates with the imported ones.

Tip

There are many nice-looking themes exported this way, available to be downloaded at http://ideacolorthemes.org. Just pick and import the JAR file and check out how beautiful your IDE will look!

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:

Otherwise, the red icon will be presented:

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.

Tip

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.

Tuning IntelliJ IDEA

IDEA's Virtual Machine settings are usually very good out of the box. However, when you work on a specific huge project and decide that you want to tweak IntelliJ IDEA's own virtual machine settings, you can change that in the following locations, depending on your operating system.

On Windows, you can tweak IntelliJ IDEA's own virtual machine settings by executing the following code:

<IntelliJ IDEA installation folder>/bin/idea.exe.vmoptions

Alternatively, you can use the following code:

<IntelliJ IDEA installation folder>/bin/idea64.exe.vmoptions

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

Alternatively, you can use the following code:

<IntelliJ IDEA installation folder>/bin/idea64.vmoptions

On OS X, since Version 12, the file /Applications/IntelliJ IDEA.app/Contents/bin/idea.vmoptions should be copied to the following path:

~/Library/Preferences/IntelliJIdeaXX/idea.vmopti ons

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.

Tip

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.

About the Author
  • Jaroslaw Krochmalski

    Jaros?aw Krochmalski is a passionate software designer and developer who specializes in the financial business domain. He has over 12 years of experience in software development. He is a clean-code and software craftsmanship enthusiast. He is a Certified Scrum Master and a fan of Agile. His professional interests include new technologies in web application development, design patterns, enterprise architecture, and integration patterns. He has been designing and developing software professionally since 2000 and has been using Java as his primary programming language since 2002. In the past, he worked for companies such as Kredyt Bank (KBC) and Bank BPS on many large-scale projects such as international money orders, express payments, and collection systems. He currently works as a consultant at Danish company 7N as an infrastructure architect for the Nykredit bank. You can reach him via Twitter at @jkroch or by e-mail at jarek@finsys.pl.

    Browse publications by this author
Latest Reviews (2 reviews total)
Отличная книга, выписываю из неё рекомендации и упражняюсь ежедневно по будням.
It was quick and was easy paying with PayPal
IntelliJ IDEA Essentials
Unlock this book and the full library FREE for 7 days
Start now