Data types and references in Java

Source: Internet
Author: User

Java data types are divided into primitive data types and reference data types.

The primitive data types in Java are divided into four classes and eight kinds. Primitive also do not know how to translate more appropriate, call him the basic data type bar, in fact, directly from the literal meaning of English understanding easier.

Primitive data types include: boolean, char , Integer, float. The integral type also includes: Short, Byte, int, long . Float type also includes:float, double .

All primitive are eight species in total. Size: Boolean (determined by JVM) char (BITS) short (BITS) byte (8 bits) int (64bits) float (zero bits)

In addition to the basic data types, all that is left in Java is references (reference).

In general, there are three steps to declaring, assigning, and creating objects: In a simple small example:

Dog Mydog = new Dog (); In this sentence we can create a dog object (Mydog), and later see this new statement must have three steps in mind to put it together:

    • Step1: dog Mydog = new Dog (); Executes the red part of the statement, declares a reference Mydog(requires the Java Virtual machine to allocate space on the stack to the reference variable, and named Mydog, this reference variable will always be fixed to the dog type)
    • Setp2:dog Mydog = new Dog (); Executes the red part of the statement, creating an object (requires the Java Virtual machine to allocate space on the heap to the dog object)
    • Setp3:dog Mydog = new Dog (); Executes the "=" symbol in the statement, connecting the object and the reference (assigning the Dog object to the Mydog reference)

Here is a special object that needs to be specifically explained, that is, arrays, yes, arrays are also objects ! The creation of the array object is as follows: (Picture truncated from headfirst Java)

Data types and references 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.