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 ...
随机推荐
- Cow Contest
poj3660:http://poj.org/problem?id=3660 题意:一些奶牛之间进行编程比赛,每头牛都有一个编程能力.如果a的能力比b的能力高,则a总能打败b .现在给你一些牛之间的比 ...
- vim文本编辑器的总结
说起文本编辑器,在下就不得不说vim这个老古董了,说老吧,但也是老当益壮,至今还是有不少拥护者.的确,vim很实用,在下就先列出vi的优点吧. 1.如果精通了vim,就可以省去鼠标了. 2.vim是跨 ...
- Android中SharedPreferences和序列化结合保存对象数据
前言: 最近在做用户注册的时候,遇到了需要填写很多表单数据,不可能在一页把所有的数据都展示完全,因此采用了分页的方式,由于在用户填写数据数据之后我们需要对用户填写的数据进行暂时的记录的,当用户会到此页 ...
- Git遇到的一点错误
[背景] 折腾: [记录]将googlecode上面的crifanLib迁移到Github上 期间出错: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...
- Linux Eclipse代码提示功能设置(Java & C/C++)
最近在Linux下开发,由于长期使用Visual Studio 2010,对代码提示功能情有独钟,现在在Linux下,使用Eclipse做开发,当然免不了怀念Visual Studio强悍的代码提示, ...
- POI做题记录:第二届POI
Trees Memory limit: 32 MB Trees occur very often in computer science. As opposed to trees in nature, ...
- tomcat配置多实例
CATALINA_HOME环境变量不必配置,因为在startup.sh脚本里会指定CATALINA_HOME的位置. 配置tomcat多实例 首先是理解下原理:CATALINA_HOME指向安 ...
- Performance testing of web application
Testing the performance of web application is easy . It's easy to design unrealistic scenario . Easy ...
- python 正则表达式(一)
正则表达式(regular exprssion)是一种形式化语法描述的文本匹配模式.模式被解释为一组指令,然后会执行这组指令.以一个字符串作为输入,生成一个匹配的子集或源字符串的修改版本. 表达式可以 ...
- std::numeric_limits<int>::max() error C2589: '(' : illegal token on right side of '::' 解决办法
int max =std::numeric_limits<int>::max(); 根据错误提示: f:\code\cpp\webspider\main.cpp(47) : war ...