java--variables and data types

Source: Internet
Author: User

I. Heap and stack (brief introduction) 1. Stack

Stack space relative to the heap is small, there is a system of space allocation and recycling work. The read efficiency of the stack is very high.

2. Heap

The heap space is relatively large, like a large warehouse. The garbage collector (GC) is working on space reclamation. The heap is less efficient to access

Two. Data type (emphasis)

In order to make better use of the memory space, the data types are divided in the programming language. The total can be divided into two main categories: basic type, reference type

    • Basic type
      • Numeric type
        • long:64 bits of Integer data
        • int:32 bits of Integer data
        • Short:16 bit integer data
        • Byte:8 bit integer data
        • double:64 bit floating point number (double-precision floating-point number)
        • float:32 bit floating point number (single-precision floating-point number, the data is usually followed by F, otherwise the default is DOUBL
      • Character type
        • Char: Character type, 16-bit Unicode character (minimum \u0000). The contents of a character type are usually enclosed in single quotation marks. Character content has a length (there can be at most one content in the content).
      • Boolean type
        • Called a Boolean type, which contains true and false, used for "true" and "false" in Pepsi Life
    • Reference type
      • class, Interface (interface), string (string), array
      • The string type is called a string type, which is made up of a series of characters (char), and the value of string needs to be caused by "".
    • Object
      • object is the parent class of all types

    • For conversions between basic data types such as (real arrows represent no data loss conversions, virtual arrows represent conversions that may have loss of precision):

    

Iv. variables and identifiers (emphasis)

A variable is actually a piece of memory that stores data.

    1. The process of declaring a variable is actually applying a piece of memory space and making a name for the space.
    2. Assigning a variable is actually storing a data in the memory space. The variable name represents the space's alias, and the type represents the size of the space
    3. Variable
    • Variables: In Java, each variable belongs to a variety of types (type). When declaring a variable, the type to which the variable belongs is preceded, followed by the variable name.
    • Initialize variable: After declaring a variable, the variable must be explicitly initialized with an assignment statement.

4. Constants

In Java, using the keyword final to declare a constant (the final keyword means that the variable can only be assigned once, and once assigned, it cannot be changed again.) In practice, the constant name uses uppercase. )

java--variables and data types

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.