本人目前也开始学习虚拟机,在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 String对象的创建(jvm).的更多相关文章

  1. Java中String对象的创建

    字符串对象是一种特殊的对象.String类是一个不可变的类..也就说,String对象一旦创建就不允许修改 String类有一个对应的String池,也就是 String pool.每一个内容相同的字 ...

  2. Java String对象的经典问题(转)

    public class StringTest { public static void main(String[] args) { String strA = "abc"; St ...

  3. Java String 对象,你真的了解了吗?

    String 对象的实现 String对象是 Java 中使用最频繁的对象之一,所以 Java 公司也在不断的对String对象的实现进行优化,以便提升String对象的性能,看下面这张图,一起了解一 ...

  4. JAVA String对象和字符串常量的关系解析

    JAVA String对象和字符串常量的关系解析 1 字符串内部列表 JAVA中所有的对象都存放在堆里面,包括String对象.字符串常量保存在JAVA的.class文件的常量池中,在编译期就确定好了 ...

  5. 关于Java String对象创建的几点疑问

    我们通过JDK源码会知道String实质是字符数组,而且是不可被继承(final)和具有不可变性(immutable).可以如果想要了解String的创建我们需要先了解下JVM的内存结构. 1.JVM ...

  6. 3.Java基础:String对象的创建和使用

    一.常用的创建方式 String s1=”abc“: String s2=”abc“: s1==s2    ==> true 解析:s1和s2指向的是同一个字符串池地址 二.不常用的创建方式 S ...

  7. Java——String对象

    前言 实际上任何语言都没有提供字符串这个概念,而是使用字符数组来描述字符串.Java里面严格来说也是没有字符串的,在所有的开发里面字符串的应用有很多,于是Java为了应对便创建了String类这个字符 ...

  8. Java String对象的问题 String s="a"+"b"+"c"+"d"

    1, String s="a"+"b"+"c"+"d"创建了几个对象(假设之前串池是空的) 2,StringBuilde ...

  9. 深入理解java String 对象的不可变性

    下面我们通过一组图表来解释Java字符串的不可变性 1.声明一个String对象 String s = "abcd"; 2.将一个String变量赋值给另一个String变量 St ...

随机推荐

  1. TCP协议的3次握手与4次挥手过程详解

    1.前言 尽管TCP和UDP都使用相同的网络层(IP),TCP却向应用层提供与UDP完全不同的服务.TCP提供一种面向连接的.可靠的字节流服务. 面向连接意味着两个使用TCP的应用(通常是一个客户和一 ...

  2. DLL ActiveForm 线程同步问题

    本文试着从分析Synchronize同步执行的实现机制入手,来解决DLL/ActiveForm中线程同步的问题. 线程中进行同步时调用的Synchronize函数,仅仅是把调用调用线程.调用方法地址. ...

  3. 如何对一个不断更新的HashMap进行排序

    如何对一个不断更新的HashMap进行排序? 解答:等到HashMap更新稳定后,用ArrayList包装进行排序.或者自己写一个可以类似HashMap的有序Map,每次更新的时候都进行排序,构建自己 ...

  4. 查看TEMP使用情况

    SQL> select * from v$mystat where rownum<2; SID STATISTIC#    VALUE ---------- ---------- ---- ...

  5. 【HDOJ】1466 计算直线的交点数

    找了个规律. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 21 ...

  6. HTML,CSS编码规范

    不管有多少人共同参与同一项目,一定要确保每一行代码都像是同一个人编写的. HTML 语法 对于属性的定义,确保全部使用双引号,绝不要使用单引号. 为每个 HTML 页面的第一行添加标准模式(stand ...

  7. 介绍4款json的java类库 及 其性能测试

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Programming Lan ...

  8. Light OJ 1038 - Race to 1 Again(概率DP)

    题目的意思是说任何一个大于1的整数,经过若干次除以自己的因子之后可以变为1, 求该变换字数的数学期望值.   题目分析: 我们设置dp[n] 为数字n的期望.假设n的因子为k1, k2, k3.... ...

  9. FAT32,NTFS,EXT3,支持的最大分区和单个文件大小?

    FAT32 Filesystem: 最大单一档案大小 4GB 最大文件系统总容量 128GB NTFS Filesystem: 最大单一档案大小 64GB 最大文件系统总容量 2TB Ext3 Fil ...

  10. 使用VisualStudio进行单元测试之四 顺序测试

    前文中所提到的测试都是针对一个方法进行的独立测试,即使是同事测试多个方法,他们之间也没有影响.但是在实际的生产过程中,更多的情况是方法与方法之间是存在相互的逻辑关系的,所以也就有了今天要介绍的顺序测试 ...