使用javap工具分析Java String(字符串)操作
Created by Jerry Wang, last modified on Oct 06, 2016
Put this line into class main method:
String a = “i042416”;
And decompile the .class file using javap:
We can see the “i042416” is included in the constant pool:
The java code String a = “i042416” is implemented via two lines of codes below:
(1) When the class is loaded by JVM, the string “i042416” is represented by #16. When instruction ldc #16 is called for the first time, the native method StringTable::intern will be called to generate char[], and store the reference into StringTable and constant pool. When the ldc #16 is called subsequently, the reference #16 is directly returned from constant pool.
(2) Instruction astore_1 stores the reference of “i042416” to local variable table.
Test via these lines instead:
String aa1 = “i042416”;
String aa2 = “jerrywang”;
String aa3 = “i042416” + “jerrywang”;
We can see for line aa3, the string concatenation is done in compilation time.
As a result, the following println gets true as result:
String aa1 = “i042416jerrywang”;
String aa2 = “jerrywang”;
String aa3 = “i042416” + “jerrywang”;
System.out.println(aa1 == aa3);
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- Java工具类
- JAVA环境变量一键配置工具
- mysql与java数据类型对照
- Eclipse直接看Java源码(含所需工具)
- Java实现 蓝桥杯 算法提高 高精度减法(JDK方法)
- java算法集训代码填空题练习3
- [工具] 将Sublime Text 3配置为Java代码编辑器
- Java开源工具
- Java知识回顾 (6)正则表达式、方法、文件与异常
- 如何将S/4HANA系统存储的图片文件用Java程序保存到本地
- 使用javap分析Java的字符串操作
- paip. uapi 过滤器的java php python 实现aop filter
- 【项目实战】使用Java Keytool工具生成的CSR给第三方云平台签名
- Java中String详解
- 【Android 安全】DEX 加密 ( Java 工具开发 | apk 文件签名 )
- 【Android 安全】DEX 加密 ( Java 工具开发 | 生成 dex 文件 | Java 命令行执行 )
- java使用DBCP连接池创建工具类
- Bean-Query 一个把对象转换为Map的Java工具库
- Java集合类汇总记录-- apache.commons4(TreeList)
- elasticsearch java工具类
- java.awt包提供了基本的java程序的GUI设计工具
- eclipse上的Java静态分析工具——待续