Created by Jerry Wang, last modified on Oct 05, 2016

I have written the following test code:

I would like to test the difference with “static int” and “static final int”.
Use javap to decompile .class file:

The result is listed below:

According to JVM instruction list explanation in wiki: https://en.wikipedia.org/wiki/Java_bytecode_instruction_listings
sipush 545: push int value 545 to stack
putstatic #16: put the stack value 545 to static class field number3

aload_0: load a reference onto the stack from local variable 0
invokespecial: invoke instance method on object objectref and puts the result on the stack (might be void); the method is identified by method reference index in constant pool
ldc: push a constant #index from a constant pool (String, int or float) onto the stack
Here we can know the fact that the value of result 512 * 623 has already been calculated during compilation and stored in constant pool index #29.
istore_1: store int value into variable 1
getstatic: get a static field value of a class, where the field is identified by field reference in the constant pool index
imul: multiply two integers
new: create new object of type identified by class reference in constant pool index
dup: duplicate the value on top of the stack

You might wonder how we can know each # represents. In order to get the table you can use javap -v instead:


We can also know that the "Value: " + product1 + " , " + product2 is coverted automatically by JVM to create a new StringBuilder instance and call append method to achieve string concatenation.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

使用Javap分析Java代码里的static final的工作原理相关推荐

  1. eclipse中使用javap分析java代码备忘

    在run中打开external tools configurations,配置如下运行就行. 转载于:https://www.cnblogs.com/mapleyuan/archive/2013/04 ...

  2. java执行sql列名无效_列名无效!java代码里的SQL语句!数据库里可以得到正确为什么放java里出错了?...

    在数据库里执行下面的SQL语句可得到正确结果,放在java代码里错误了!Stringsql="SELECTtradeId,t.cardNo,tradeType,tradeAmount,tar ...

  3. Java中的public static final来修饰数组与接口变量

    Java中的public static final来修饰数组与接口变量 public static final来修饰数组 final对数组的作用 怎样实现对数组的public static final ...

  4. 优秀的Java程序员必须了解GC的工作原理

    一个优秀的Java程序员必须了解GC的工作原理.如何优化GC的性能.如何与GC进行有限的交互,因为有一些应用程序对性能要求较高,例如嵌入式系统.实时系统等,只有全面提升内存的管理效率 ,才能提高整个应 ...

  5. 优秀Java程序员应该了解的GC工作原理

    一个优秀的Java程序员必须了解GC的工作原理.如何优化GC的性能.如何与GC进行有限的交互,因为有一些应用程序对性能要求较高,例如嵌入式系统.实时系统等,只有全面提升内存的管理效率 ,才能提高整个应 ...

  6. 使用javap分析Java的字符串操作

    我们看这样一行简单的字符串赋值操作的Java代码. String a = "i042416"; 使用命令行将包含了这行代码的Java类反编译查看其字节码: javap -v con ...

  7. javaparser_JavaParser入门:以编程方式分析Java代码

    javaparser 我最喜欢的事情之一是解析代码并对其执行自动操作. 因此,我开始为JavaParser做出贡献,并创建了两个相关项目: java-symbol-solver和Effectiveja ...

  8. JavaParser入门:以编程方式分析Java代码

    我最喜欢的事情之一是解析代码并对其执行自动操作. 因此,我开始为JavaParser做出贡献,并创建了两个相关项目: java-symbol-solver和Effectivejava . 作为Java ...

  9. es文本分析java代码_Elasticsearch系列---Java客户端代码Demo

    前言 前面历经33篇内容的讲解,与ES的请求操作都是在Kibana平台上用Restful请求完成的,一直没发布Java或python的客户端代码,Restful才是运用.理解ES核心功能最直接的表达方 ...

最新文章

  1. 入局智慧城市,科技互联网巨头路在何方?
  2. 自律到极致-人生才精致:第4期
  3. 修改电脑开机时间记录6005_这些优化步骤,让你的电脑远离卡顿!
  4. [MySQL] 几句MySQL时间筛选SQL语句[进入查看]
  5. 将用户添加到sudoers_在CentOS系统中将用户添加到Sudoers文件的方法
  6. Express + Node 爬取网站数据
  7. c语言不定参数个数,C语言中不定参数的实现
  8. 【hadoop】Apach Hdoop 安全模式
  9. rcnn代码实现_轻松学Pytorch实现自定义对象检测器
  10. spring中的class配置不能使用properties中的字符串
  11. Vue 项目优化,持续更新...
  12. 【统计学习方法】统计学习方法概论(2)
  13. python可视化迷宫求解_用python求解迷宫
  14. java学习心得与体会(自我鼓励)
  15. css 按钮按下样式
  16. Excel如何将单元格中的多数字提取出来
  17. UE4 后期材质节点学习
  18. PDF是如何在线分割的?简单方法介绍
  19. 脚踏实地做好本职工作——职场人士寓言(4)
  20. BottomNavigationView简单使用,增加小红点,增加中间操作按钮

热门文章

  1. JS 内置对象DATE的方法
  2. 黑马程序员-面向对象-06天-5(单例设计模式)
  3. 从赖斯想谈恋爱-------到教育的启迪
  4. aria2的安装与配置
  5. OO第三次博客总结作业
  6. uva10405-最长公共子序列
  7. PhpExcel 删除默认的Sheet
  8. 20151117个人日记
  9. Android中贝塞尔曲线的绘制方法
  10. 机器学习中的数学知识(part4)--拟牛顿法