1. Introduction

Some days before , I have introduced some keyboard shortcuts for java developers. Today I would introduce more keyboard shortcuts for java developers.

2. Environments

  • Intellij IDEA 2016.2+

3. The keyboard shortcuts

3.1 Auto complete for java code blocks

  • Windows users:
    • use ctrl+shift+enter to generate the java code block
  • Mac Users:
    • use command+shift+enter to generate the java code block

Before:

if

click the shortcut after typing if and then we get:

After:

if() {
	
}

You can also use this shortcut to generate the code block for for,while,try etc.

3.2 Auto generate notnull-checking code

We always need to check the param to be not null, In IntelliJ IDEA, you can use the following keyboard shortcut to generate the notnull-checking boilertemplate code for you.

  • Windows users:
    • type the object.notnull and then use enter to generate the notnull-checking code block
  • Mac Users:
    • type the object.notnull and then use enter to generate the notnull-checking code block

Before:

public void method1(Object o) {
	//need to check if o is not null
}

You can just type o.notull in the body of the method

public void method1(Object o) {
	o.notnull
}

and then click enter,we got:

After:

public void method1(Object o) {
	if(o != null) {

	}
}

5. Summary

You can find all the default keymap of IntelliJ IDEA here: