Basic naming rules and data types in the Java basic article No2--java

Source: Internet
Author: User
Tags arithmetic operators float double

Constants and binary in 1.Java
1. Constants:
In the process of running the program, can not change the amount, is the constant

A Boolean value can only be true or false
NULL: null constant, no representation exists!

---------------------------below are the things to know-----------------------------------
2. Binary: (Learn)
Common in-system:
Binary, octal, decimal, hex

In the form of a binary representation:
Binary: Start with 0b
Octal: Starting with 0
Hex: Starts with 0x

Binary conversions:
Any binary into decimal:
Coefficient * The power of the cardinality, sum.

Decimal goes to any binary:
The remainder is removed from the base.

Fast Conversion method: 8421 yards

Original code, anti-code, complement:
1. All content in the computer is stored in complementary form

2. We can not directly understand the complement, must be converted into the original code to understand.

3. Anti-code is the complement converted into the original code of the transfer content.

Normal Condition:
Complement-----> Anti-code----> Original Code

I usually write the original code----> anti-code----> complement

Positive number: The original code is the same as the anti-code complement.

The original code to reverse code: the highest bit unchanged, others 0 change to 0

Anti-code to complement: anti-code +1

2. Variable, data type conversion (Key Mastery)

1. Variables
1. Format:
Data type variable name = variable value;

2. Data type:
1. Classification:
Basic data types
Four types of eight types:
Integer type: byte short int long
Float type: float double
Boolean Type: Boolean
Character type: Char

BYTE range: -128~127
Short range: ( -2^15) ~ (2^15-1)

Reference data type: Talk about the Object!

2. An integer is not identified, the default is int type
If it is a decimal, there is no identity, the default is double type

3. Precautions for use of variables:
1. Scope:
Effective interval.
The range you can use

2. Initialize:
Local variables (variables defined in the method)
Before use, you must assign a value first.
You can define not to use, and you do not need to initialize.

3. A statement can declare multiple variables.

4. Data type conversions:
1. Implicit conversions:
Small data types are calculated with large data types, and small data types are automatically promoted to large data types before they are calculated.

2. Cast:
Assigning a value of a large data type to a variable of a small data type

(data type) value or variable

int x=100;

byte B = (byte) x;

3.byte Short Char These three types of variables are automatically raised to type int when they are being operated on.

4. Constant optimization mechanism:
When compiling the source code, the compiler checks that there are constants in operation, and will automatically complete the constant operation before compiling into the bytecode file.

Byte b=3+4;====> is equivalent to byte b=7;

Range of values for 5.float and long types:
The range of float is larger than the range of type long because the storage structure of the underlying float is different.

6. Value range of data type:
byte < Short,char < int < Long < float < double

7. (char) character type:
There are two types of patterns:
1. Characters
2. Integer (each character corresponds to a code value in the Code table: ' A ' =97)

' A ' =97
' A ' =65
' 0 ' =48

Value range for char type: 0~65535

Char type can be stored in Chinese!

8. String:
Strings can be added to any other data type, actually connecting,
It can turn the value of any data type into a string and then concatenate it to produce a new string.

3. Operator (Key Mastery)
1. Arithmetic operators
%: The remainder of dividing two numbers

/: Divide two number of quotient, two integers, get no decimal.

When used alone, whether in front of the variable or behind, there is no difference between the variable is self-increment

In the operation, if the + + symbol is in front of the variable, the variable is self-increment and then the value after the increment is calculated.

If the + + symbol is followed by a variable, the variable is self-increment and then the value before the increment is calculated.

+ + and--with a cast effect

2. Assignment operators

The left side of the assignment operator must be a variable.

+ =: The variable on the left side of the operator is evaluated with the variable or constant on the right, and the result is assigned to the left variable.

+ = or other special assignment operators have the effect of casting.

3. Comparison operators
> >= < <= = = =!

The result of the comparison operator operation is a Boolean type!

Basic naming rules and data types in the Java basic article No2--java

Related Article

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: 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.