Variables and constants, type conversions for Java basics

Source: Internet
Author: User

One, variable

Variable is the amount that can be changed, and each value assigned will open up a new memory address.

1, first, the variable needs a declaration, for example: int A, the A can also be regarded as a label, it points to a memory address, the address is an int type of package, you can access a to access memory address, the principle of

2. Rules for declaring variables

Letters or underscores "_" Start with numbers available at the end and cannot be declared with a keyword

The format of the declaration is as follows:

where float a=15.5f, the reason behind the addition of an F, and the following long v=123456789123456l behind the reasons for adding an L is as follows:

First, there is a default data type in Java

Here A is a float type, but the system recognizes that the default 15.5 is a double type, so if you want him to become a float type, 15.5 to add an F (case does not matter), as long v=123456789123456l, the principle of the same, you need to pay attention to, int cannot store such a large number.

One, constant

Values that cannot be changed, each constant has only one memory address.

Constant modifier final

Are some of the differences when declaring constants and variables, each value assigned to a variable opens a new memory address. Each constant corresponds to only one memory address, and multiple identical constant memory addresses have only one.

Iii. type Conversion

1), Automatic type conversion

Automatic type conversion is equal to conversion, or small to large conversion of a class

2), forced type conversion

Forcing type conversions is large to small conversions, and the system does not mind turning, but requires permission.

For example:

When the data type is converted, it is determined whether the corresponding data type can accept the number of bits of this data type, and the second binary is needed to determine the judgment.

Variables and constants, type conversions for Java basics

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.