Appendix - IntelliJ Hints and Tips
Throughout the book I mentioned hints and tips, and shortcuts for using IntelliJ.
I collate all of those in this appendix for easy reference, and add some additional information on using IntelliJ with this book.
Shortcut Keys
This table contains the shortcut keys that I use most often.
| Function | Windows | Mac |
|---|---|---|
| Create New | alt + insert |
ctrl + n |
| Intention Actions | alt + enter |
alt + enter |
| Intention Actions | alt + return |
alt + return |
| Run JUnit Test | ctrl + shift + F10 |
ctrl + shift + F10 |
| Show Parameters | ctrl + p |
cmd + p |
| Show JavaDoc | ctrl + q |
ctrl + j |
| Code Completion | ctrl + space |
ctrl + space |
| Find by class | ctrl + n |
ctrl + n |
| Find by filename | ctrl + shift + n |
ctrl + shift + n |
| Find by symbol | ctrl + shift + alt + n |
ctrl + shift + alt + n |
JetBrains IntelliJ have supporting documentation on their website:
- Reference pdf for Windows and Linux
- Reference pdf for Mac OS X
And the help files have “Keyboard shortcuts you cannot miss”
Code Completion
Code completion is your friend. You can use it to explore APIs and Libraries.
All you do is start typing and after the . you will see context specific items you can use.
You can force a start of code completion if you close the pop-up menu by pressing:
ctrl + space
Navigating Source Code
ctrl + click
For any method in your code, either a built in method, or a library method, or even one that you have written. You can hold down ctrl and left mouse click on the method name to jump to the source of that method.
You might be prompted to allow IntelliJ to download the source for external libraries.
This can help when working with the example source code for this book as you can navigate to the domain objects from within the @Test method code.
Finding Classes and Symbols
If in this book you see a method name or a class name, but don’t know where to find it in the source code then you can use the find functionality in IntelliJ to help.
To find a class by name, use the keyboard shortcut:
-
ctrl + n
This can perform partial matching, so you don’t have to type in the full name of the class.
If you want to find a ‘file’ in the project then use keyboard shortcut:
ctrl + shift + n
If you want to find a method name, or variable name (symbol) then use the keyboard shortcut:
ctrl + shift + alt + n
Running a JUnit Test
Annotating methods with @Test makes it easy for us to ‘run’ the methods we write. You can right click on the method name or class and choose to Run as JUnit test. Or use shortcut key:
ctrl + shift + F10
Loading Project Source
The easiest way to load a project into IntelliJ, and this applies to the book example source code, is to use:
-
File \ Openand select thepom.xmlfile.
Help Menu
The help menu does more than offer a link to a help file.
Find Action
The menu option Help \ Find Action allows you to type an action and IntelliJ will provide menu options and short cut keys to help.
e.g.
- Select
Help \ Find Action - type “junit” and you will see a list of ‘settings’ you can use to help configure JUnit in IntelliJ
- type “run” and you will see a list of options for running code, or tests
The list isn’t just for information, you can click on the items in the list and you will be taken to the functionality in IntelliJ or run the command.
Enable Auto Importing
Auto Importing can help faster coding as it will add Import statements automatically, and download maven dependencies when you amend the pom.xml file.
You will probably see an onscreen prompt to switch this on, but if you miss it then you can use the settings to enable it.
-
SettingsandMaven. Importingto switch on the Maven pom.xml importing automatically. -
SettingsandEditor. Auto Importto amend the Java import settings.
You can use the Find Action to help you locate these options if a future version of IntelliJ has moved them.
Use the Terminal in IntelliJ
IntelliJ has a built in terminal. The button for this is shown at the bottom of the GUI.
This is very useful for quickly issuing mvn commands or any of the other terminal commands mentioned in this book.
Productivity Guide
The Help \ Productivity Guide menu option shows a dialog with common productivity improvements.
You can click on the items in the list to see what it does, and you can also see which ones you have used, and which you haven’t.
This can help you learn the basics of IntelliJ very quickly.
Summary
IntelliJ offers a lot of flexibility in how we work with code. Over time you will learn to make your work with Java faster as you learn more about the IDE.
Over time I will add videos and information to JavaForTesters.com to demonstrate more functionality with IntelliJ that I do not have space to add to this book.