java String对象的创建(jvm).
本人目前也开始学习虚拟机,在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).的更多相关文章
- Java中String对象的创建
字符串对象是一种特殊的对象.String类是一个不可变的类..也就说,String对象一旦创建就不允许修改 String类有一个对应的String池,也就是 String pool.每一个内容相同的字 ...
- Java String对象的经典问题(转)
public class StringTest { public static void main(String[] args) { String strA = "abc"; St ...
- Java String 对象,你真的了解了吗?
String 对象的实现 String对象是 Java 中使用最频繁的对象之一,所以 Java 公司也在不断的对String对象的实现进行优化,以便提升String对象的性能,看下面这张图,一起了解一 ...
- JAVA String对象和字符串常量的关系解析
JAVA String对象和字符串常量的关系解析 1 字符串内部列表 JAVA中所有的对象都存放在堆里面,包括String对象.字符串常量保存在JAVA的.class文件的常量池中,在编译期就确定好了 ...
- 关于Java String对象创建的几点疑问
我们通过JDK源码会知道String实质是字符数组,而且是不可被继承(final)和具有不可变性(immutable).可以如果想要了解String的创建我们需要先了解下JVM的内存结构. 1.JVM ...
- 3.Java基础:String对象的创建和使用
一.常用的创建方式 String s1=”abc“: String s2=”abc“: s1==s2 ==> true 解析:s1和s2指向的是同一个字符串池地址 二.不常用的创建方式 S ...
- Java——String对象
前言 实际上任何语言都没有提供字符串这个概念,而是使用字符数组来描述字符串.Java里面严格来说也是没有字符串的,在所有的开发里面字符串的应用有很多,于是Java为了应对便创建了String类这个字符 ...
- Java String对象的问题 String s="a"+"b"+"c"+"d"
1, String s="a"+"b"+"c"+"d"创建了几个对象(假设之前串池是空的) 2,StringBuilde ...
- 深入理解java String 对象的不可变性
下面我们通过一组图表来解释Java字符串的不可变性 1.声明一个String对象 String s = "abcd"; 2.将一个String变量赋值给另一个String变量 St ...
随机推荐
- Technology Trader
zoj2071:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2071 题意:题意一些零件,每一个零件会有一个花费,然后用这 ...
- ckeditor与ckfinder简单整合使用
Ckeditor与ckfinder简单整合使用 功能:主要用来发送图文的email,图片上传到本地服务器,但是email的图片地址要写上该服务器的远程地址(图片地址:例如:http://www.bai ...
- SQL servere 范式、事务
一.数据库范式: 1.构造数据库必须遵循一定的规则.在关系数据库中,这种规则就是范式. 范式是符合某一种级别的关系模式的集合.数据库中的关系必须满足一定的要求,即满足不同的范式. 满足最低要求的范式是 ...
- duck type鸭子类型
在程序设计中,鸭子类型(英语:duck typing)是动态类型的一种风格.在这种风格中,一个对象有效的语义,不是由继承自特定的类或实现特定的接口,而是由当前方法和属性的集合决定.这个概念的名字来源于 ...
- Microsoft Internet Explorer 远程代码执行漏洞(CVE-2013-3186)(MS13-059)
漏洞版本: Microsoft Internet Explorer 6 - 10 漏洞描述: BUGTRAQ ID: 61663 CVE(CAN) ID: CVE-2013-3186 Windows ...
- 命令行利器Tmux
Tmux是一个优秀的终端复用软件,类似GNU Screen,但是对两个软件评价已经是一边倒了,大多数人认为tmux功能更加强大,使用更加方便. Tmux不仅可以提高终端工作效率,是服务器管理工作必不可 ...
- HDU 5933 ArcSoft's Office Rearrangement 【模拟】(2016年中国大学生程序设计竞赛(杭州))
ArcSoft's Office Rearrangement Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- C#调用Web Service时的身份验证
原理:webservice所在的系统中,在系统域中建立用于登录的软件的用户和密码,软件登录时将用户名.密码和登录的本机的域的名字通过webService的NetworkCredential传递到web ...
- HDU-2126 Buy the souvenirs
数组01背包. http://acm.hdu.edu.cn/showproblem.php?pid=2126 http://blog.csdn.net/crazy_ac/article/details ...
- 【转】SVN linux命令及 windows相关操作(二)
转自这里:http://www.uml.org.cn/pzgl/200904246.asp 1 安装及下载client 端 2 什么是SVN(Subversion)? 3 为甚么要用SVN? 4 怎么 ...