IDEA Bizarre Tips

Posted May 26, 20203 min read

IDEA is currently the best IDE on the market, I said it!

A few years ago, Eclipse is very popular in the market, so most people are used to some shortcut keys of Eclipse. In recent years, with the rise of IDEA, many people have abandoned eclipse and chose IDEA, but some people are used to changing the shortcut key way to eclipse. I do n t recommend doing this here. It s enough to be familiar with a set of shortcut keys for about a week. You can experience more hidden tips by directly using IDEA s default shortcut keys. .

  1. Postfix Completion related skills

Postfix Completion is actually some templates about code completion. We can see some of his templates in Settings > Editor > General Postfix Completion. Let's take a look at some commonly used syntax.

Define a boolean variable flag and a String variable name for testing.

boolean flag = true;
String name = "Java Journey";
  1. The judgment condition is established

grammar:

flag.if

effect:

if(flag) {}
  1. The judgment condition is not established

grammar:

flag.else

effect:

if(! flag) {}
  1. The judgment condition is equal to null

grammar:

string.null

effect:

if(string == null) {}
  1. Judgment condition is not equal to null

grammar:

string.notnull or string.nn

effect:

if(string! = null) {}
  1. Use switch to judge

grammar:

string.switch

effect:

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

grammar:

flag.while

effect:

while(flag) {}

Define an array of type string to test.

String []param = {"1", "2", "3"};
  1. Traverse from the first element

grammar:

param.fori

effect:

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

grammar:

param.forr

effect:

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

grammar:

param.for or param.iter

effect:

for(String s:param) {}

Newly define a User class, add name and age attributes for testing.

public class User {

     private String name = "Java Journey";
     private int age = 18;

     public User() {}

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

grammar:

User.new

effect:

new User();
  1. Create a local variable

grammar:

new User(). var

effect:

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

grammar:

new User(). field

effect:

private User user;
user = new User();
  1. Mandatory conversion of object type, if we convert Object to User

grammar:

new object.castvar

effect:

User user =(User) new Object();

Other commonly used

  1. Return statement

grammar:

"" .return

effect:

return "";
  1. Print statement

grammar:

flag.sout

effect:

System.out.println(flag);
  1. Capture and handle exceptions

grammar:

new User(). try

effect:

try {
 new User();
} catch(Exception e) {
 e.printStackTrace();
}
  1. Throw an exception

grammar:

new Exception(). throw

effect:

throw new Exception();
  1. Lock the variable

grammar:

string.synchronized

effect:

synchronized(string) {}

Second, inject language

inject language can quickly help us build some of the grammar we need. Such as JSON, HTML, XML, etc.

Quickly define JSON

If we define a json string by ourselves, we need to manually escape it with \. We can use injection language to save this step.

We define a json string, place the cursor in the middle of "", and then press Alt + Enter. When the following prompt comes out, select Inject language or reference.

Then click Enter to enter, select or search for JSON and press Enter. Then continue to press Alt + Enter. After the following prompt, we select Edit JSON Fragment.

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

Using html and other methods is the same, it will automatically complete the end tag for us.

Several mysterious shortcut keys

  • Quick rename

    Shift + F6

  • Locate recently viewed files

    Ctrl + E

  • Locate recently modified files

    Ctrl + Shift + E

  • View all methods of the current class

    Ctrl + F12

  • View class diagram

    Ctrl + Shift + Alt + U