1. Autocomplete (Tab)

IntelliJ IDEA is a very smart development environment. Some people believe that it not just a great IDE for Java development, but the all-around best IDE in the world. Which, admittedly, is not far from the truth.

For example, IntelliJ IDEA has this magnificent thing called auto-completion. IntelliJ IDEA parses and analyzes all the files in your project (including all the libraries you are using). It understands what classes you have and what methods and variables those classes have. Then it uses all that information to help you write your code.

You just start typing a word, and it immediately offers hints to finish it. One of the most commonly used autocomplete keys is Tab.

For example, suppose you want to write "System". To do this, you need to type "Sys" and press the "Tab" key: IDEA will finish the rest for you.

If you put a period after the name of a variable, then IDEA will first determine what type the variable is, and then offer you a list of methods that can be called on the variable. This is super convenient.

Or suppose you want to write the class name InputStreamReader. IntelliJ IDEA can save you time: you can just type three capital letters "ISR" (InputStreamReader) and press Tab. IDEA will convert what you wrote into InputStreamReader. It's almost magic.

4.2. Live Templates: psvm, sout, psfs, fori

There are thousands of reasons why professional programmers adore IntelliJ IDEA, but it also has something for beginners. For example:

main method

Let's say you want to write public static void main(String[] args)  in less than a second.

To do this, type the 4 letters psvm and press Tab. IDEA will replace "psvm" with "public static void main(String[] args)". Magic.

It's super easy to remember the sequence psvm  — its an abbreviation of "public static void main".

Console output

There is also a way to quickly write System.out.println();

To do this, you also need to write 4 letters ("sout") and press Tab. IDEA will replace "sout" with "System.out.println();"

This is also easy to remember: the 4 letters in sout come from System.out.println

Declaring a string constant

There is a way to quickly declare a String variable (at the class level).

To do this, you once again need to write 4 letters ("psfs") and press Tab. IDEA will replace "psfs" with "public static final String".

You won't have trouble remembering this: psfs is made up of the 4 letters from public static final String

There is a similar abbreviation that can be used with any data type: "psf", which stands for public static final


You can quickly write a loop in IDEA using the fori + Tab combination. When you do this, IDEA will replace fori with the following code:

for (int i = 0; i < ; i++) {

You just need to write in the maximum value for the i counter variable.

These may not be the most popular tricks for working Java professionals, but they will definitely make your life easier as a beginner.

3. Surrounding code fragments: Ctrl+Alt+T

Sometimes programmers face situations where they want to do something with the code that has already been written. IntelliJ IDEA makes this easier by providing a special command to wrap existing code with something.

For example, suppose you want to execute some code not once, but several times. It makes sense to create a loop and place the code inside the loop. You can, of course, write the loop header and put a curly brace at the beginning and another curly brace at the end. Then you could also copy the required code into the loop, and go through all the lines inside the body of the loop and shift them to the right.

But there is an easier way: you can surround the existing code in a loop, and IntelliJ IDEA will do the rest by itself. You will need to do 3 things:

  1. Highlight the code you want to surround with other code
  2. Press Ctrl+Alt+T
  3. Select one of the options for adding surrounding statements:
    1. if
    2. if-else
    3. while
    4. do while
    5. for
    6. try catch
    7. try finally
    8. try catch finally
    9. synchronized

Here's an example of a menu in IDEA:

Surrounding code fragments

4. Code style: Ctrl+Alt+L

And one more piece of advice. Quite often, copying the code messes up its alignment: there are extra spaces in one place, while they are missing somewhere else, etc. The code seems to work, but it looks like a train wreck.

To keep your code looking great, you just need to press 3 buttons: Ctrl+Alt+L

As soon as you press this combination, IntelliJ IDEA will immediately format all the code in the current file, placing spaces and tabs wherever necessary. It will no longer be code, but eye candy.


Before After
public class Main {
   public static void main(String[] args) {
System.out.println("Hello World!");
   if (2 < 3)   {
System.out.println("Opps");   }

for (int i = 0; i < 10; i++) {
public class Main
   public static void main(String[] args)
      System.out.println("Hello World!");
      if (2 < 3)

      for (int i = 0; i < 10; i++)

By the way, each "code style" is fully customizable in the IntelliJ IDEA settings:

Code style IntelliJ IDEA