Let’s understand it from the perspective of class bytecode 1.String s1 = "", the following is the compiled bytecode, you can see that there is actually no difference in this case s1="aaa", they are all Push a string from the constant pool to the top of the stack and assign it to a local variable.
0: ldc #16 // String
2: astore_1
3: return
2. In the case of String s2=null, at this time, no string constant is generated in the constant pool, only null is pushed to the top of the stack and assigned to the variable.
0: aconst_null
1: astore_1
2: return
3. In the case of String s3 = "u0000", a string representing NUL will be generated in the constant pool, which is the so-called Control Character.
Let’s understand it from the perspective of class bytecode
1.String s1 = "", the following is the compiled bytecode, you can see that there is actually no difference in this case s1="aaa", they are all Push a string from the constant pool to the top of the stack and assign it to a local variable.
2. In the case of String s2=null, at this time, no string constant is generated in the constant pool, only null is pushed to the top of the stack and assigned to the variable.
3. In the case of String s3 = "u0000", a string representing NUL will be generated in the constant pool, which is the so-called Control Character.
Test environment: jdk-8.0-102