Variables, data types, and operators

Source: Internet
Author: User
Tags java keywords

Variable:

The computer uses the memory to remember the data used for a large amount of computation. Allocate a space to the memory according to the data type, and then the data can be put into the space.

You can use the variable name to quickly find the data it stores. Specify the data to the variable, that is, store the data to the room with the alias as the variable name; call the variable to retrieve and use the data in that room. It can be seen that variables are a basic unit for storing data, and different variables are independent of each other.

Declare a variable, that is, "Apply for a space in the Memory Based on the Data Type". here you need to name the variable.

Data Type:

Int integer

Double double point type

Char character type

String type.

Different types of data require different storage spaces. Different types of data require different Memory Spaces for storage.

Variable declaration and usage:

Apply for a space in the memory based on the data type. Name the variable here.

Store data to the corresponding memory space.

Call the variable. The stored variables are called "Call variables ".

The declared variable name is used to store data in the memory space corresponding to the variable. "variables must be declared or assigned values before they can be used".

Variable naming rules:

1. The variable must start with a letter, underscore "_", or "$;

2. variables can contain mathematics, but cannot start with numbers;

3 except the "_" or "$" symbol, the variable name cannot contain any special characters;

4. You cannot use keywords in Java, such as int, class, and public.

There is no limit on the length of the Java variable name, but the Java language is case sensitive, so price and price are two completely different variables.

Java keywords cannot be used as variable names, class names, package names, etc. A variable name can be composed of one or more words. Generally, the first letter of the first word is lowercase, and the first letter of the next word is capitalized.

Troubleshooting method:

1. assign a value to the variable before use according to the learned content.

2. Modify invalid variable names according to the naming rules of variables.

3. Use two different variable names for storage.

OPERATOR:

"=" Is used to assign the result of the expression on the right of the equal sign to the variable on the left of the equal sign.

Use "=" to put the value 1000 into the bucket of the money. "=" Is also called the value assignment operator.

"=" Can assign a value to a variable or assign the value of an expression to the variable.

Arithmetic Operators:The arithmetic operator is provided in Java. It is mainly used to perform mathematical operations using numeric operands.

The addition operator "++" and the subtraction operator "--" requires only one operand.

Data type conversion:

1. Automatic Data type conversion (Rule 1. If an operand is of the double type, the entire expression can be upgraded to the double type. Rule 2 meets the conditions for automatic type conversion. The two types must be compatible: Numeric (positive and floating point .)

2. Force data type conversion. Add brackets before the variable. The type in the brackets is the type to be forcibly converted.

Since the forced type conversion is often converted from a type with a large width to a type with a small width, so that the precision of the value is lost, you can call this conversion as a "narrow conversion ".

Boolean Type:

In this case, a data type is required. Monopoly is used to represent truth and false.

Java uses the boolean type to indicate true or false. "Boolean" is also called "Boolean", so we often say "Boolean ". Value: tsue (true) False (false ).

Relational operators:

> (Greater)

<(Less)

> = (Greater than or equal)

<= (Less than or equal)

= (Equal)

! = (Not equal ).

Relational operators are used for comparison. The comparison result is a Boolean value, either true or false ).

Relational operators are used for comparison. The comparison result is a booleam value, either true or false ).

"=" And "=:

"=" Is a value assignment operator that assigns the value on the right to the variable on the left of "=", such as Int = 20;

"=" Is a comparison operator. The value on the left of "=" is compared with the value on the right to see if they are equal,

If they are equal, true is used. Otherwise, false is used. For example, the result of 3 = 4 is false.

Variables, data types, and operators

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.