What exactly is null in Java?[转]
来源:互联网 发布:js字符串数字相加 编辑:程序博客网 时间:2024/05/15 08:47
http://www.programcreek.com/2013/12/what-exactly-is-null-in-java/
Let’s start from the following statement:
String x=null;
1. What exactly does this statement do?
Recall what is a variable and what is a value. A common metaphor is that a variable is similar to a box. Just as you can use a box to store something, you can use a variable to store a value. When declaring a variable, we need to set its type.
There are two major categories of types in Java: primitive and reference. Variables declared of a primitive type store values; variables declared of a reference type store references. In this case, the initialization statement declares a variables “x”. “x” stores String reference. It is null here.
The following visualization gives a better sense about this concept.
If x = “abc”, it looks like the following:
2. What exactly is null in memory?
What exactly is null in memory? Or What is the null value in Java?
First of all, null is not a valid object instance, so there is no memory allocated for it. It is simply a value that indicates that the object reference is not currently referring to an object.
From JVM Specifications:
The Java Virtual Machine specification does not mandate a concrete value encoding null.
I would assume it is all zeros of something similar like itis on other C like languages.
3. What exactly is x in memory?
Now we know what null is. And we know a variable is a storage location and an associated symbolic name (an identifier) which contains some value. Where exactly x is in memory?
From the diagram of JVM run-time data areas, we know that since each method has a private stack frame within the thread’s steak, the local variable are located on that frame.
- What exactly is null in Java?[转]
- 空指针NULL 和 What exactly is nullptr?
- What exactly is read_rnd_buffer_size
- What exactly is "iowait"?
- What exactly is "iowait"?
- What Exactly Is the Error?
- What is a JavaBean exactly?
- What exactly is copy-on-modify semantics in R, and where is the canonical source?
- What exactly is the difference between “pass by reference” in C and in C++?
- What Exactly Is A PLL?(ZT)
- Container.DataItem. What exactly is this?
- What exactly is a Neural Network?
- What, exactly, is a Product Manager?
- What is CountDownLatch in Java
- What is CyclicBarrier in Java
- What is /dev/null
- Java - What is final in Java?
- Java - What is Abstraction in Java
- Linux中用命令行方式发送邮件
- VisionMobile:2014年Q1移动开发者经济报告(十五)5、开发者工具:更好、更快、更多
- Web 单点登录系统
- 辗转相除法求两个数是否互素
- Objective-C相关Category
- What exactly is null in Java?[转]
- Yale CAS + .net Client 实现 SSO(1)
- CentOS 5.x和CentOS 6.x限制单个用户线程数上限的不同行为
- STM32 Printf函数实现方法
- java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
- VS TRACE的使用
- Yale CAS + .net Client 实现 SSO(2)
- NativeActivity通过jni调用java层的Android API
- 房地产售楼处神秘顾客调研方案