IDEA is the best IDE on the market today, I said!

Eclipse was very popular in the market a few years ago, so most people are used to some of its shortcuts. In recent years, with the rise of IDEA, many people have abandoned Exlipse in favor of IDEA, but some people prefer to replace the shortcut keys with Eclipse. I don’t recommend doing this. It takes about a week to get familiar with a set of shortcut keys. You can use the default shortcut keys of IDEA to experience more hidden tricks.

1. Postfix Completion

Postfix Completion is really just a set of templates for code Completion. You can see some of his templates in Settings — >Editor — >General — Postfix Completion. Let’s take a look at some commonly used syntax.

If the relevant

To test, define a Boolean variable flag and a String variable name.

boolean flag = true;
String name = "Java journey";
Copy the code
  1. Judgment condition holds

Grammar:

flag.if
Copy the code

Effect:

if (flag) {}
Copy the code
  1. The judgment condition is not valid

Grammar:

flag.else
Copy the code

Effect:

if(! flag) {}Copy the code
  1. The judgment condition is null

Grammar:

string.null
Copy the code

Effect:

if (string == null) {}
Copy the code
  1. The judgment condition is not null

Grammar:

String. The notnull or string. The nnCopy the code

Effect:

if(string ! =null) {}
Copy the code
  1. Using the Switch

Grammar:

string.switch
Copy the code

Effect:

switch (string) {}
Copy the code
  1. Use while to judge

Grammar:

flag.while
Copy the code

Effect:

while (flag) {}
Copy the code

For the relevant

Define an array of type string to test.

String[] param = {"1"."2"."3"};
Copy the code
  1. Iterate from the first element

Grammar:

param.fori
Copy the code

Effect:

for (int i = 0; i < param.length; i++) {}
Copy the code
  1. Iterate from the last element

Grammar:

param.forr
Copy the code

Effect:

for (int i = param.length - 1; i >= 0; i--) {}
Copy the code
  1. Enhanced for loop

Grammar:

param.forOr param. IterCopy the code

Effect:

for (String s : param) {}
Copy the code

Variables related to

Define a new User class and add the name and age attributes for testing.

public class User {
    
    private String name = "Java journey";
    private int age = 18;
    
    public User(a) {}

    public User(String name, int age) {
        this.name = name;
        this.age = age; }}Copy the code
  1. Create an object

Grammar:

User.new
Copy the code

Effect:

new User();
Copy the code
  1. Create a local variable

Grammar:

new User().var
Copy the code

Effect:

User user = new User();
Copy the code
  1. Create a global variable

Grammar:

new User().field
Copy the code

Effect:

private User user;
user = new User();
Copy the code
  1. Cast Object type, if we will convert Object to User

Grammar:

new object.castvar
Copy the code

Effect:

User user = (User) new Object();
Copy the code

Other common

  1. Return statement

Grammar:

"".return
Copy the code

Effect:

return "";
Copy the code
  1. Print statements

Grammar:

flag.sout
Copy the code

Effect:

System.out.println(flag);
Copy the code
  1. Catch and handle exceptions

Grammar:

new User().try
Copy the code

Effect:

try {
    new User();
} catch (Exception e) {
    e.printStackTrace();
}
Copy the code
  1. An exception is thrown

Grammar:

new Exception().throw
Copy the code

Effect:

throw new Exception();
Copy the code
  1. Lock variables

Grammar:

string.synchronized
Copy the code

Effect:

synchronized (string) {}
Copy the code

Second, the inject language

Inject Language can quickly help us build some of the syntax we need. Examples include JSON, HTML, XML, and so on.

Quick JSON definition

If we define a JSON string ourselves, we need to manually use \ to “escape. We use Inject language to eliminate this step.

Define a JSON string, place the cursor in the middle of “”, and then press Alt+Enter. Select Inject Language or Reference when the following message is displayed.

Then press Enter to Enter, select or search for JSON, and press Enter. Then press Alt+Enter and select Edit JSON Fragment after the following prompt is displayed.

When you press Enter, an input box will pop up. We can just write our JSON in the input box and it will automatically escape for us.

The same is true with HTML and so on, which will automatically complete the closing tag for us.

A couple of mysterious shortcuts

  • Quick rename
Shift+F6
Copy the code
  • Locate the most recently viewed file
Ctrl+E
Copy the code
  • Locate the most recently modified file
Ctrl+Shift+E
Copy the code
  • View all methods of the current class
Ctrl+F12
Copy the code
  • See the class diagram
Ctrl+Shift+Alt+U 
Copy the code