"Head First Java reading notes" (iii) primitive master data types and references

Source: Internet
Author: User

Recognize variables

There are two types of variables: primitive data types and references.

declaring variables

Java focuses on variables. It will not let you put the floating-point type variable into an integer-type variable unless you first confirm with the compiler that the number can lose precision.

In order for type safety to work, you must declare the types of all variables.

There are two types of variables: primitive master data type and object reference.

The primitive primary data type is used to hold the values of the base type, including integers, booleans, and floating-point numbers, while object references hold references to objects.

Rules for declaring variables:

Variables must have type

Variables must have type

Variables must has a name

Variable must have a name

A variable is like a cup, is a container, carries certain things, he has size and type.

Primitive main data types like coffee cups, they have different sizes, and each university has a noun, such as a small cup, a big cup, a medium cup, etc.

Each primitive main data type variable has a fixed number of digits (cup size), and the primitive master data type that holds the value has the following 6 sizes

Byte:8, Short:16, int:32, long:64, float:32, double:64

Primitive assignment of the primary data type

Make sure that the variable can save the saved value.

You can't put a big value in a small cup.

For example, you can't load an int size into a byte container.

You can assign values to variables in several ways:

Directly after the equals sign

Assigning values to other variables

The combination of the above two methods

Avoid keywords (keyword)

Naming rules for Java:

The name must begin with a letter, underscore, or $ symbol and cannot begin with a number

In addition to the first character, a number can be used behind it. As long as it's not for the first character.

As long as the two rules above are met, you can name them arbitrarily, but avoid Java reserved words.

List of reserved words

Object reference

We already know how to declare a primitive main data type variable and assign it to her, but what about a variable of a non-primitive master data type? That

"Head First Java reading notes" (iii) primitive master data types and references

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.