java String对象的创建(jvm).
2014-01-20 10:19
393 查看
本人目前也开始学习虚拟机,在java中,有很多种类型的虚拟机,其中就以sum公司(当然现在已经是oracle了)的虚拟机为例,介绍可能在面试的时候用到的,同时对自己了解String有很大帮助,这里仅仅是笔记的整理(张龙老师的).
class StringDemo { public static void main(String[] args) { //String pool is in the 'Stack. //Retrieve whether there exist an instance "a"(In the String pool),found no(and create in the 'String pool'). String s = "a"; //Retrieve whether there exist an instance "a"(In the String pool),found yes(and not create). String s2 = "a"; System.out.println(s == s2); //outputs 'true'. //Retrieve first in the String pool(found no,and create in the String pool), //and then create one in the 'Heap',return the reference of the instance(in the heap). String s3 = new String("b"); //Retrieve first in the String pool(found yes,and not create in the String pool), //and then create one in the 'Heap'(each new create an instance),return the reference of the instance(int the heap). String s4 = new String("b"); System.out.println(s3 == s4); //outputs 'false'. //Retrieve whether there exist an instance "c"(In the String pool),found no(and create in the 'String pool'). //Return the reference of the instance in the 'String pool'. String s5 = "c"; //Retrieve first in the String pool(found yes,and not create in the String pool), //and then create one in the 'Heap',return the reference of the instance(int the heap). String s6 = new String("c"); System.out.println(s5 == s6); //outputs 'false'. } }
相关文章推荐
- 关于java annotation的学习笔记。。。
- 几秒前,几分钟前,几小时前,几天前,几月前,几年前的java实现
- spring mvc数据模型
- [Leetcode] Symmetric Tree (Java)
- poi 实现下拉框级联选择省市
- eclipse failed to create the java virtual machine 问题图文解析
- java代码调用rtx发送提醒消息
- [Leetcode] Recover Binary Search Tree (Java)
- java值传递几个注意点
- Java concurrent Framework之util.concurrent(包括atomic and locks)包概述
- 深入JAVA源码分析
- Struts2值栈学习
- Java之JVM调优案例分析与实战(5) - 服务器JVM进程奔溃
- 学生信息管理系统--java
- 走在学习Java开发开始的路上
- java基础知识点笔记
- 学习java进门
- 第一个java应用程序。
- 接触 JAVA的感受
- JAVA命令如何执行带包名的类