Nine, the exact representation of NULL in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.