Java LiveTemplates

This blog is a simple introudction of the live templates of IDEA, it can accelerate your coding speed. Let’s get started.

Useful templates

// type in 'psvm', or 'main', you can get:
public static void main(String[] args) {
  // type in 'psg', you can get the following:
  public String getFile_name() {
      return file_name;
  }

  //type in 'fori', you can get:
  for (int i = 0; i < ; i++) {
    Object o = null;
    //type in 'ifn'(inn <=> if not null), you can get:
        if (o == null) {

        }
  }
  //type in 'sout', youc can get:
  System.out.println();

  //type in 'souf', you can get:
  System.out.printf("");
}

Create your own templates

  • ctrl+alt+s

  • Click Editor

  • Click Live templates

  • You can creat your own templates (group), for example:

    @Test
    @DisplayName("$TEST_NAME$")
    void $METHOD_NAME$() {
        Assertions.fail("no passed.");
        $End$
    }

Share your individual templates with others

  • Press Shift twice
  • Insert ‘export’
  • Select ‘export settings’

Import others templates

  • Press Shift twice
  • Insert ‘import’
  • Select ‘import settings’