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 ...
随机推荐
- RabbitMQ安装简单过程
找到一本ACTION IN RABBITMQ,仔细看.现在先安装起来.. 参考主要的URL,包括安装,用户管理,权限管理.我用的都是最新版本. http://my.oschina.net/indest ...
- Android 使用HttpClient方式提交GET请求
public void httpClientGet(View view) { final String username = usernameEditText.getText().toString() ...
- 迅雷创始人程浩:创业公司5招做好内部创新(组建小型敢死队:一共3个人,一个产品经理,两个研发;腾讯做不做这个项目是一个伪命题;让用户来验证,而不是相反 good)
欢迎关注“创事记”的微信订阅号:sinachuangshiji 文/程浩 编者按:本文首发于微信公众号“浩哥说”(ID:haogetalks),作者程浩,迅雷创始人.内容为作者在混沌AI成长营上的演讲 ...
- .rdp 文件参数详解
Overview of .rdp file settings Setting Type Default value Description and possible values Settable f ...
- 【PPC】Qemu怎么玩儿
1. 编译Qemu这里不建议使用自动安装,手工编译下.Qemu源代码的质量很高,什么环境都能编译过.tar -xzvf qemu.tar.gzmkdir build-qemucd build-qemu ...
- rootkit的检测工具使用(chkrootkit和rootkit hunter)
信息安全 这两天突然发现我们的服务器产生大量DNS解析连线.为了查明问题,就下载网上找工具检查问题所在.用了两个工具,一个chkrootkit,另外一个rootkit huntur. ...
- 支付宝APP支付Java回调具体步骤
/** * 支付宝异步请求通知 * * @param request * @return */@RequestMapping(value = "async", method = R ...
- MySQL中的类Decode用法
SELECT DISTINCT ( CASE ' THEN '关羽' ' THEN ' 张飞' ' THEN ' 赵云' ' THEN ' 马超' ' THEN ' 黄忠' ' THEN ' 魏延' ...
- ubuntu设置WPA2-PSK的wifi热点(AP)——hostapd+dhcpd
在ubuntu 12.04中,默认可以设置的wifi热点是只能用WEP加密,毫无疑问,这样的加密方式,安全性低,现在可以在10几秒的时间内破解,并且只能添加ad-hoc模式的热点,不支持添加AP模式, ...
- UVaLive6039 Uva1668 Let's Go Green
一开始考虑所有边都是单独的一条路径 然后尽量多的合并 #include<cstdio> #include<cstring> #include<cstdlib> #i ...