4 minutes read

Let's take a brief look at the useful tools in IntelliJ IDEA that help you code fast and efficiently.

Running your program

To start the program, run it with the

icon on the left gutter or ⌃ R / Shift + F10 shortcut, take a look at the output:

Run your code before checking the task to make sure everything works fine.

Comments

Commenting a line. Use ⌘ + / or Ctrl + / shortcut to comment the line your cursor is currently on. You don’t need to move your cursor to the beginning of the line.

Block comments. Use ⌘ ⌥ / (or Ctrl + Shift + /) shortcut to comment selected code fragment with block comment.

Creating Javadoc stubs. Typing /** then pressing Enter above a method signature will create Javadoc stubs for you.

Navigating through words. Use ⌥ Left Arrow / ⌥ Right Arrow (or Ctrl + Left Arrow / Ctrl + Right Arrow) to navigate through code elements in a line of code.

Navigating through lines. Use ⌘ Left Arrow / ⌘ Right Arrow (or Home / End) to navigate to the beginning/end of the line of code.

Selection. When you need to select some code fragments, handling the selection from the keyboard can be very helpful.

  • To manage the selection by word use ⌥ ⇧ Left Arrow / ⌥ ⇧ Right Arrow (or Ctrl + Shift + Left Arrow / Ctrl + Shift + Right Arrow).

  • To shrink or expand the selection by line use ⇧ Up Arrow / ⇧ Down Arrow (or Shift + Up Arrow / Shift + Down Arrow) shortcuts.

  • To move the selection to the line start/end use ⌘ ⇧ Left Arrow / ⌘ ⇧ Right Arrow (or Shift + Home / Shift + End) shortcuts.

Cut a line of code. You can cut a line of code with the ⌘ X / Ctrl + X shortcut, just put a cursor somewhere on the line.

Autocompletion and refactoring

Smart autocompletion is an essential feature of a professional code editor, which helps you to save time and avoid misprints. It is equally powerful for learning because you can use it to find the right variable, function, parameter, or code construct. Start typing or simply press ⌃ Space / Ctrl + Space to get a list of suggested options:

Code autocompletion can help you to find the right variable. Once declared, a variable is added to the autocompletion list. Just start typing or simply press the shortcut to get a list of all the options:

Code snippets, or live templates, can also be a handy tool. They not only speed up your coding but help you learn new language syntax as well. Use ⌘ J / Ctrl + J to see the full list of code snippets available. Start typing to find the one you want to add, and then use Tab to fill in the blanks:

If you have some experience of learning a foreign language, you might know this feeling when you can't quite put your finger on the right word. Learning a new programming language sometimes feels the same.

The IntelliJ IDEA can help you to remember the right syntaxes. Start typing any parts you remember and the code completion will give you hints even if you only have some parts of the naming right:

Code refactorings can also be handy regardless of how complicated your code is. For example, use ⌘ ⌥ V / Ctrl + Alt + V to extract a variable.

It is often more effective to duplicate a line of code and then edit it than to write a new code line from scratch. ⌘ D / Ctrl + D works great for this, as you don’t need to select the whole line.

Naming convention

Inspired by the best community practices, IntelliJ IDEA checks your code for many types of possible errors and code smells. Naming rules and conventions are among them.

If you try one of the examples above and declare a variable with an invalid name, the IntelliJ IDEA will highlight it as an error and suggest a quick fix (within the red bulb or ⌥ Enter / Alt + Enter shortcut):

IntelliJ IDEA can also declare a new variable for you with a quick intention action. Just start with a value, and then invoke the intention action with the shortcut:

You can also tell the IntelliJ IDEA to check your variables for naming conventions. Go to File | Settings | Editor | Inspections | Java | Naming conventions and switch on the Local variable naming convention inspection:

Now all the inappropriate names will be highlighted as well:

You can switch on or off all of the inspections, or configure them the way you need, as well as the intention actions.

Type casting

IntelliJ IDEA helps you to be aware of type incompatibility and when explicit casting is needed with error highlighting and intention actions:

Reading documentation

Reading documentation is a must when learning a new programming language. IntelliJ IDEA makes this process as seamless as possible.

Put a cursor on the class, method, variable, or function you want to read about, and then press ⌃ J / Ctrl + Q to open the quick documentation pop-up:

Use the shortcut once more to switch to the tool window mode:

This lets you read the documentation in parallel with reading your code. Go through the code fragment and read about the code constructions your cursor is on, without any additional shortcuts or mouse clicks. You can also click hyperlinks to find out more details.

Conclusion

As you see, IntelliJ IDEA has tools and shortcuts for many actions needed for everyday work. They not only include running, navigating and editing code but also features like autocompletion, refactoring of code, typecasting, and more. Learning them will help make working with code faster and more efficient.

341 learners liked this piece of theory. 6 didn't like it. What about you?
Report a typo