Java ,从char 和 Character到内存分配

来源:互联网 发布:创建一个数据库sql语句 编辑:程序博客网 时间:2024/06/06 08:37

Reference:
http://stackoverflow.com/questions/8790809/whats-the-difference-between-primitive-and-reference-types
http://stackoverflow.com/questions/24823420/what-is-the-difference-between-char-and-character-in-java
http://docs.oracle.com/javase/tutorial/java/data/characters.html

char 与 Character的区别

type allocate note char primitive type stack 16 bit Unicode character Character wrapper class heap a class with a char field and class methods

Java中的primitive data types(基本数据类型):

boolean character byte short integer long float double true/false 16 bit Unicode characters 8 bit signed 16 b 32 b 64 b 32 b 64 b

Java 内存

From book OCA(Oracle Certified Associate) JAVA SE 7

Just as men and women are fundamentally different (according to John Gray, author of Men Are from Mars, Women Are from Venus), primitive variables and object reference variables differ from each other in multiple ways. The basic difference is that primitive variables store the actual values, whereas reference variables store the addresses of the objects they refer to. Let’s assume that a class Person is already defined. If you create an int variable a, and an object reference variable person, they will store their values in memory as shown in figure 2.13.

这里的primitive variable可以说是简单变量或者基本变量,对应的类型属于上表中的基本数据类型。简单变量和引用变量的区别在于简单变量存储的是实际的值,引用变量存储的是它们所引用的对象的地址。之后是这样的例子:

int a = 77;Person person = new Person();

reference:Berguiga.M.Amine

0 0