JetBrains makes a high end IDE called IntelliJ Idea, usually called
simply IntelliJ. The current version is 11.0.2
Last revised/verified: 2012-02-02.
Jetbrains gave me a copy of Personal IntelliJ on 2006-02-20. I have been using it as
my only IDE (Integrated Development Environment) ever since. I still use Visual SlickEdit for quick
edits since Idea takes so long to start. IntelliJ is reknowned for its advanced editing and clever algorithms for
factoring code. It is written in Java Swing itself. It comes with its own
JRE (Java Runtime Environment) 1.6.0_21. It does not
show up in the Java control panel or the Windows control panel. You can delete it by deleting the J:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.0.1\jre\ directory tree, then IntelliJ will try to
use your default JRE. IntelliJ is also known for being faster than the competition. It has to be
quicker and better since its competitors like Eclipse, NetBeans and Oracle are free. This is Chris Lamb’s
favourite IDE. It runs under Windows, Max OS (Operating System) X, and Linux. I like it better than Eclipse, but I
have not used Eclipse in a long while, and gave up on NetBeans long ago as too slow for my elderly machine. It is
hard to find someone with up-to-date experience on all three.
Pricing
It comes in five versions:
- for the Stripped down Community version. Free to everyone. This is the
Java developer’ Core. The Ultimate edition has support for J2EE, other languages etc.
-
for Ultimate Edition for Open
Source developers.
-
for the Ultimate Edition for Academic use.
-
for the Ultimate Edition for Personal use.
-
for the Ultimate Edition for Commercial
use.
All but the free versions come bundled with unlimited email support. The support is fast, courteous and generous,
even when you don’t have official support. This is the advantage of using a commercial package.
Getting Started
To get started on your first project, you must manually navigate on hard disk to find a
JDK (Java Development Kit) for it. At first, it looks as if it is broken, showing an empty list of installed
JDKs.
Like Eclipse, IntelliJ has its own vocabulary. Classes are grouped into packages. Packages are grouped into directories. Directories are grouped
into modules. A module in a group of packages all compiled with a common source code
level. Modules are grouped into projects. All classes in a project must use a common
code style. You recompile the. project as a whole. Projects are usually more or less self contained collections
of code that share code. You might carve many distributables out of a single project.
It is easy to muddle up projects, directories, modules, packages. I discovered two tricks to help sort it
out.
- Use a naming convention, e.g. end projects in p, and modules in m.
- If you don’t know if some node IntelliJ is showing you is a project or a module or a directory,
refactor and threaten to rename it. IntelliJ will tell you what sort of beast you are about to
rename.
Unfortunately IntelliJ will ask you to create packages and modules without properly defining them. You will
likely have to start from scratch once the meanings come clear. The key place to define these terms should be the
screens displayed the first you are asked to name your project and module. Hint hint…
To allow one project to use the class files of another, you import not the project, or the module, but the
name of the classes directory into your module settings.
You get at the module settings not with settings menu item, but by right clicking on
the module name in the left panel. This also where you select which compiler and compiler settings to use.
I suggest experimenting with some small projects for a while to get the hang of things before you commit to
your overall structure.
Configuring a Project and Modules With IntelliJ
Configuring a project into modules is very simple, but there are so many options is it easy to go off the
rails and spend an evening pulling out your hair. Here is how I do it. I create a new project (a very rare event)
lets say called mp. I create six modules within that project, that I call j1 j2 j3 j4 j5 j6. I keep the code designed to run inJava version 1.1 or later in j1, the
code to run inJava version 1.2 or later in j2 etc.
I configure each module with the appropriate source code level and click apply. I
configure the output directory to use the module compile output path. Then compiled classes will then be put in
directories with names like J:\intellij\mp\out\production\j1\com\mindprod\bio. These
output directories are intentionally not visible inside IntelliJ. when I want to explore them, I will have to use
some sort of external file manager such as Windows Explorer.
I configure module j2 under module settings ⇒ dependency
⇒ add a j1 module dependency to j2 ⇒ mark it exported so that users of j2 will see j1 as well. I configure module j3
under module settings ⇒ dependency ⇒ add a j2 module dependency to j3 ⇒ mark
it exported so that users of j3 will see j2 and
j1 as well. I repeat for j4 j5 j6.
I now create my package structure under each module, i.e. com then
mindprod then bio which creates a collapsing tree
structure of packages. Then I can either create new classes or use Windows Explorer to drag Java source files
into place in the tree. Clicking synchronise will make IntelliJ notice the new or
updated files I placed in its source tree. I can also create new package directories with Explorer. The easiest
way to handle this is to create your first packages and files with IntelliJ, look at the structure, then use
Explorer to create more of the same structure.
IntelliJ stores each module configuration in an IML/XML file. Yours should look something like this:
In the bad old days, when you installed an upgrade to IntelliJ, you had to redo all your settings, reinstall
your plug-ins. Now it cleverly copies this sort of information from the previous install, even the vmoptions.
However, when you uninstall the old version, after you get the new one working, do not tell the uninstall to also
remove settings, otherwise you will delete them for the new version too.
Hooking Up the JDK
You must tell each project in IntelliJ where your JDK is and tell each module in each
project where which target version to simulate.
- Click File.
- Click Settings.
- Click Compiler.
- Click Java Compiler.
- Click Javac.
- Click OK.
- In the project panel, click the name of your project. This is the tricky part.
You must click the project, not the module to configure the module.
- Click Module Settings.
- Click Project.
- Select your Project SDK (Software Development Kit). If your JDK is not listed, click
new and follow your nose. You can use a 32 or
64-bit JDK. You can use one different from what IntelliJ
itself is using to drive the IDE.
- On the left, click modules.
- Click the name of one of your modules from the middle column.
- Select the JDK version level you wish to simulate for that module.
- Click Dependencies
- Select your Module SDK.
If your JDK is not listed, click
new and follow your nose.
- Configure anything else about he module while you are here.
- Repeat last five steps for each module.
- Repeat everything for each project.
Nice Stuff
- It starts in 19 seconds. I would like this faster, but it pretty good compared with what I put up with in past.
- Like Eclipse, it instantly warns you of syntax errors as you type. They disappear as soon as you fix the
problem. You don’t need to invoke the compiler to check out your corrections.
- The error messages are more intelligible than Eclipse’s.
- It warns you when override a method in the superclass with a tiny red arrow in the margin, with a tooltip
to explain what it means.
- It is quite easy to find things. Menus and dialogs go more or less directly to what you want. Even on my
first time out I did not get lost wandering around a rabbit warren of nested dialogs. It is quick and easy to
find thing in help. For example, you click the wrench icon, and then laid out before are all icons for all the
different things you could possibly configure. You go right to what you want, rather than playing rabbit in the
warren of nested menus trying to find it.
- It has a built-in lint they call code
analysis.
- It is very similar to Eclipse. I had very little problem adjusting to the differences.
- If IntelliJ were a person, you might describe it is polite, considerate or thoughtful. It is sort of like
the lady in a hotel who puts a little chocolate on your pillow. There are considerate little touches, like
telling you in the default code templates where to look to modify them, rather than making you go digging. Like
the gracious Mrs. Prothero in Dylan Thomas’s A child’s Christmas in Wales, IntelliJ
offers you something interesting to read while it is compiling.
- Back in the 70s IBM (International Business Machines) used to give away folding cardboard cheatsheets.
The green card, the blue card or the pink card neatly summarized all the information you often had to look up
in manuals. IntelliJ carries on this fine tradition offering a PDF (Portable Document Format)
file that when you print it, turns into a folding cheat sheet that shows all the keyboard short cuts. It is one
sided. Perhaps there is a backside for it.
Plug-Ins
IntelliJ Plug-ins come with no installation instructions. It turns out that installing any plug-in, including the
Rearranger, is a snap. You don’t have to download or build anything. In IntelliJ, Click
File ⇒ Settings ⇒ IDE Setting ⇒ Plug-ins.. You can then view the plug-ins installed already
and also what is available. Right click “the Rearranger” (or whatever
plug-in you want to install, then left click Install. (Selecting the plug-in and
hitting OK does nothing, ditto reload.). You have to
shut-down and restart IntelliJ before you can start using the plug-in.
The Rearranger
The ability to order your methods is not built-in as it is in Eclipse. Instead you install a plug-in called
the Rearranger that does even more:
- rearranges (reorders) class and class member declarations according to a user-specified order and/or method
call hierarchy;
- generates section-marking comments
- provides several controls for spacing within and between methods and classes.
- permits the user to manually rearrange items. This is particularly useful for related groups of constants
or to manage initialisation order.
You must configure The Rearranger before use to tell it your preferred ordering. To configure, go to File ⇒ Settings ⇒ IDE Settings ⇒ Rearranger. It gives you very fine control. It is wise to save your Rearranger configuration
to a file in case you have to later reinstall.
If you want to clump your String[] declaration together, you must specify the class
like this: "String\[\]" since the expression is a regex, and [] have special
meaning in regexes.
It is clever in the way it arranges methods, and inserts comments to label the groupings. It can put getters
and setters next to the corresponding property. It knows that the main method is the primary one and should come
before the other static public methods.
Here
Make sure you export and back up your Rearranger configuration.
Downsides
- IntelliJ is less jittery about temporary errors in code, such as something not defined yet, or is unused
— it just changes colour. However, IntelliJ annoys you by asking if you want to import anything it does
not recognise. In Eclipse, syntax errors generate a giant slew of messages, making it hard to deal with
anything else.
- It has thousands of specialised features not relevant to developing ordinary Java code. These suck up all the support
oxygen
often leaving more mundane problems unattended to.
- It does not summarise your errors at the bottom of the screen the way Eclipse’s problems panel does. At least it doesn’t by default. You have to go looking for the little
syntax error markings. I find them easy to overlook and thus don’t find out about my errors until a full
compile. F2/Shift-F2 help you find them within a file fairly easily.
- Though it sometimes underlines errors in Javadoc, it does not pester you about fixing them the way Eclipse
does. I find it easy to overlook the errors. They don’t count as compile errors or warnings. I
don’t get them cleaned up until an Inspector pass.
- If there are files in the library for a project that don’t belong, and you delete them, it literally
deletes the files. It does not simply remove them from the project.
- If you want to access files you compiled outside IntelliJ, it is best to bundle them up into jars and
include the jars individually rather than try to provide a classpath. If you use a classpath, you will either
end up including far more than you intended, or it will claim not be to able to see the directories you did
import.
- When you are working in Eclipse you are always aware instantly of the global effect of your every
keystroke. In IntelliJ, you focus on one class at a time. You can only see one project at a time, and when you
swap projects IntelliJ frantically rescans the source. There is no equivalent of the workspace, a collection of
classes from various projects that you are working on right now in concert, other than a set of windows you
have open.
- When you run the code inspector (lint), it often display the results from some previous run. It saves old
runs, something that is just confusing.
- Sometimes the message from a successful compilation gets lost. All works, but it does not acknowledge.
- If you reconfigure which JDK to use for a project, IntelliJ hums away for what seems an eternity. It is
reindexing all the class files in all the jars and also all the source code in the JDK. Just let it churn. If it doesn’t, select invalidate caches to force it to
reindex the JDK.
- You have very detailed ability to define your code formatting style. With a single click you can pull an
entire project into conformance. However, when you save a configuration, it does not show up in C:\Users\user\.IntelliJIdea11\config\codestyles until you exit IntelliJ. It requires
you to have changed something in the configuration before it will save it. Strange as it sounds, you must make
some tiny change to the configuration both before and after the save-as to have it recorded on disk. Further it
fails to save unless you run IntelliJ as an administrator. It is not enough to just log-on as administrator.
You must configure the icon to launch IntelliJ with run as administrator. To restore, you must put the
xml config file in C:\Users\user\.IntelliJIdea11\config\codestyles. You
can’t load it from some other directory. Just to confuse you, the name of the configuration is not
necessarily the same as the name of the file. It is embedded in the XML (extensible Markup Language)
in <code_scheme name="xxx">. Make sure the external and internal names
match. The current scheme is recorded in C:\users\user\.IntelliJIdea11\config\options\other.xml. The behaviour is
mindbogglingly hare-brained. Why can’t they just let you export/import a scheme or insert one in the
codestyles directory and have it included. There is a way to export/import settings, but not just the code scheme.
- If you try to debug a class not in the current project, it gives no error message, just terminates
immediately.
Tips
- One by one, the IntelliJ features stopped working. Programs would not run. Ctrl-B could not find definitions.
The inspector gave bizarre advice. IntelliJ would ask to me import classes that were already imported.
Presumably there was some corruption in my
configuration files, but I could not find or correct the problem despite many attempts. I was about to give up on IntelliJ and try NetBeans or
Eclipse. I fixed the problem by uninstalling IntelliJ, erasing all IntelliJ files on all drives
including those interspersed with my java source
code, and reinstalled, and recreating my configuration by hand rather than by restoring my old config. I cheated a bit my importing
the Rearranger config.
- If you change your plug-ins, you must restart IntelliJ to make those changes take effect.
If that fails, invalidate the caches.
- Let’s say I know I need an addAdjustmentListener, but I am not sure where
to hook it in. I don’t know what classes support addAdjustmentListener. If I
type Ctrl-Alt-Shift-N addAdjustmentListener, IntelliJ will tell me the classes and
interfaces that support addAdjustmentListener.
- Always use the change signature feature when you add, remove, reorder parms on a method. It will not forget
to fix some obscure invoking of the method you forgot about.
- When you click settings, scroll down. Most of the options, including the one to install plugins, are not
immediately visible.
- To install a plug-in, find it in the column on the right, and right click it.
- Install the PluginUpdateNotifier 10 to let you know about updates to your
plugins.
- If IntelliJ gets sluggish, you will want to buy some more RAM, get a cheap ReadyBoost flash
drive and boost the amount of virtual address space allocated to IntelliJ Idea. IntelliJ hides the command
line options for the JVM (Java Virtual Machine) it uses while running in
Program Files\JetBrains\IntelliJ IDEA 11.0.1\bin\idea.exe.vmoptions.
Here are the IntelliJ’s default settings for 32-bit.
-Xms128m
-Xmx512m
-XX:MaxPermSize=250m
-XX:ReservedCodeCacheSize=64m
-ea
Here are my suggested settings for 32 bit:
-Xms128m
-Xmx800m
-XX:MaxPermSize=400m
-XX:ReservedCodeCacheSize=64m
-ea
Here the default settings for 64 bit, in idea64.exe.vmoptions.
-Xms128m
-Xmx800m
-XX:MaxPermSize=400m
-XX:ReservedCodeCacheSize=64m
-ea
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-ea enable assertions
Last revised/verified: 2009-12-08
Make sure there is a linefeed after the final -ea or IntelliJ won’t even
start. The options have the usual meaning they would have on the java.exe command line. If you crank them up to high,
garbage collection takes too long and the machine goes unresponsive for unacceptably long periods, even
though performance improves generally. Hopefully the Jet and the
Jetbrains people will get together and make Idea work under Jet. The Jet JVM
is self-tweaking. Every time you install an update to IntelliJ, you will need to readjust these values.
- Put your resources in the out\production not the src
branch of your project.
- Use Help ⇒ Default Keymap to get a PDF
cheat sheet of all the keystrokes and print it out. There are commands there you won’t find on the
menus.
- You can change the theme/skin/look &feel with Settings ⇒ Appearance ⇒
Look & Feel.
- Use Ctrl + Shift + Backspace to navigate back to the previous edit
location.
- Projects can only see files in the same project unless you configure otherwise. You must add the
module library of class files of some other project as a dependency. Add the class files, not the source. Then attach sources to
the corresponding class files. If you simply attach the source files, when you hit Ctrl-B you will see decompiled class files, not the original source.
- When you add the content root (where the source and other project files are) to a
module, add the entire module directory not just module\src.
- TODOs are not hidden tags like breakpoints. They are ordinary comments of the form . You can configure other text and comments to be treated as TODOs. There is no special command to
create them.
- Use the Analyse ⇒ Inspect feature. It does all kinds of wonderful things
like detect code of the form if ( expectedValue ==
expectedValue ) where you meant if ( actuaValue == expectedValue ). It will tell you about variables you never
set but never use. It will add finals appropriately. It will reduce scope. It
detects missing periods in Javadoc. It will reformulate Boolean nests into simpler code. But best of all, it
detects when you used ==when you should have used equals.
- Use Alt + Enter to get light-bulb tips on how to improve your code, such as
converting concatenation to explicit StringBuilders where you can add a proper
length estimate.
- When the results of your find-all or find-uses disappear, you can bring them back by clicking the find tab on the bottom left of your screen.
- Turn off auto-scroll-from source to stop IntelliJ from losing your place in the
navigation window.
- Ctrl + Q on a method to see its Javadoc. It will show you the
up-to-the-second changes, not what was generated on the last Javadoc utility run.
- To see the definition of a something in you code, use Ctrl-B, but if you
want to see tho code for something not in the current code, use Ctrl+Alt+Shift-N
(Go To | Symbol)
- When you install a new version, it will put it in a new directory and ask you where configuration files are
from a previous version to copy over. Give it the C:\Program Files\JetBrains\IntelliJ IDEA
11.0.1 directory, not the C:\Users\user\.IntelliJIdea11
directory.
- Don’t delete the old version until you have used a new version for a week or so, and are sure all the
configurations are copied over into the new version. IntelliJ does not install over top of the previous
version. When you install a new version, do not delete the C:\Users\user\.IntelliJIdea90, or C:\Users\user\.IntelliJIdea910 directories as they are needed for the config information they contain
- When you install a new version, it will ask you if you want to import the data from the old version. Oddly,
it does not want the C:\Users\.IntelliJIdea11 data. It wants the F:\Program Files\JetBrains\IntelliJ IDEA 11.0.1 for the directory where the old version is.
- Don’t run the code reformatter unless you have a clean compile. It will mess your code up so badly it
will require a lot of manual tidying to get it back in shape. Another reformat after recompile will not be
sufficient to get rid of dozens of unwanted newlines.
- Use the refactor ⇒ introduce constant carefully. If you factor out the
constant 4, all the 4s in the program will be
replaced, not just the ones in the particular context you refactored. This can create all manner of
hard-to-find bugs. Unless the numeric value of the String is distinctive, you are
best to do this manually.
- If the module settings are disabled, click the module node, and hit F4.
- If you are debugging a program that reads resources from the jar, you must put a copy of the various
resources in the corresponding tree of the IntelliJ out directory next to the
*.class files the IDE generates. I could not get it to work any other way.
Backup
Other than your source files make sure you back up the project description files, the *.ipr and *.iws files. Also back up your Rearranger configuration and your
codestyle configurations in C:\Users\user\.IntelliJIdea11. These files can
take hours to recreate from scratch.
Restoring the codestyle is a bit round about. You must create a new dummy configuration, and save it, without
the .xml extension. Then, shut down IntelliJ and overwrite that file with the one from
backup. There is no menu command to restore. Make sure the internal codestyle name is also what you want.
Files
*.ipr is an XML file containing the project settings for a single project. It
contains such things as code style preferences and spelling exceptions.
*.iws is an XML file containing the debugging settings for a single project.
It contains such things as where the breakpoints are.
*.iml is an XML file containing the dependency settings for a single
project/module. It contains the list of source code and class jars that this project code depends on.
C:\Users\user\.IntelliJ10 is a directory that contains all manner of
configuration information about IntelliJ, including the codestyles description, plug-in jars relevant to all
projects.
Annotations
To use annotations, e.g. @Nullable or @NotNull inside
IntelliJ, you must add
F:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.0.1\redist\annotations.jar
as a library of annotations to the module. You might want to turn on external annotations in settings ⇒ code stile ⇒ code generation to store annotations outside the source code. I
could not get annotations internal or external to work.
Yet To Learn
I need to find way to trigger the light bulb suggestions for improvement. If I don’t look at them right
away, they disappear.
How to keep the Alt-F7 Usages Window from disappearing before I have finished
with it. You can get in back again with the tab. It might be nice to have them in another window always visible,
especially if you have a big screen.
IntelliJ has a CSS (Cascading Style Sheets) and HTML (Hypertext Markup Language)
editor as well, complete with refactorings. I have not yet used it. Perhaps it will do the various cleanups I
thought I would have to write custom code to do.
IntelliJ integrates with many version control programs.