Let's start with the following statement:
String x = null;
1. What does this statement do specifically?
Back to what is a variable and what is a value. The usual analogy is that a variable is similar to a box.
Just as you can store things in boxes, you can use variables to store values.
When declaring a variable, we need to set its type.
There are two main categories of Java types: basic types and references. A variable that is declared as the underlying type holds the value of the underlying type, and the reference is saved by what holds the referenced variable.
In this case, initialize a variable declared as "X", and "X" holds the string reference. Here it is null.
Here's a visual way to better understand the concept.
If x = "abc", it will look like this:
2. In memory null What's the specifics?
How is null specific in memory or is the declaration a null value?
First, NULL is not a legitimate object instance, so there is no memory allocated for it. It is simply a value that indicates a reference to this object, and now does not point to a specific object.
JVM Standard:
The JVM does not enforce a specific null value. Note
The Java Virtual Machine specification does not mandate a concrete value encoding nul)
I assume it's like any other C-like language, a string of things like zero.
3. What is x specific in memory?
Now that we know what NULL is, we know that a variable is a storage area named after a specific symbol. What is that x specific in memory?
We know that each method in the thread has a private stack based on the data region that the JVM is running on, and the local variables are stored here.
Nine, the exact representation of NULL in Java