basic syntax in Java (i)
• Main content
1. Constants
2. Binary conversion
3. Variables
4. Data type
5. Conversion of data types
6. Operators
Two • Constants: (emphasis)
Constants Overview:
Its value cannot be changed during program execution
Constant classification:
Literal constants:
String constants are enclosed in double quotes for example: "Hello", "Hello"
integer constant all integers
Decimal constant All Decimals
The contents of a character constant enclosed in single quotation marks
Boolean constant True (True) False (false)
Empty constant NULL
Custom constants:
Variables that are modified by the keyword final
Three • In-process conversion
1. Introduction: It is the carry system, is a kind of carry-out method stipulated by people
Other binary conversions to decimal: coefficient * cardinality ^ power power
Decimal conversion to other binary: In addition to the base fetch, except for the end of the quotient of 0, then the remainder is reversed to fetch
2. Original code anti-code complement: Put a binary number, divided into sign bit, and value bit
Original code: Positive number: Sign bit 0, others are numeric digits
Negative numbers: Sign bit 1, others as numeric digits
Inverse code: Positive number: Same as the original code
Negative number: Sign bit 1, value bit reversed by bitwise
Complement: Positive: Same as the original code
Negative number: Anti-code +1
Four • variables
1. Variable Overview: In the course of a program execution, the amount of its value can change within a range
2. Define the format of the variable: Mode 1: Data type variable name = initialization value; Mode 2: Variable name of data type-----variable name = initialization value;
Five · data type
1. Basic Data type:
Integer type: Byte occupies a range of 1 bytes ( -128---127), short occupies 2 bytes, int occupies 4 bytes, long occupies 8 bytes
Float type: Float takes 4 bytes, double takes 8 bytes
Character type: Char occupies 2 bytes
Boolean type: Boolean occupies 1 bytes
Note: integers use the int type by default, and decimal uses the double type by default
2. Reference data type:
Classes class, interface interface, array []
3. Considerations for Using variables:
The variable is defined in the curly braces, and the range of the curly braces is the scope of the variable.
Two variables of the same name cannot be defined in the same scope.
No initialization values can be used directly.
It is recommended to define only one variable on a single line.
Six • Data type conversion (emphasis)
1. Implicit conversions: Small data types convert to large data types
The operation of this conversion will be done by default and does not require us to handle
Byte,short,char-int-long-float-double
Byte,short,char do not convert to each other, they participate in the operation first converted to int
2. Cast: Large data types convert to small data types
Manual completion
Format: Target type variable name = (target type) (data to be converted);
For example: byte B = 3;
b = (byte) (b + 3);
(Interview questions) Characters in the Java language char can store a Chinese character? Why?
OK. Because the Java language uses Unicode encoding. Each character in the Unicode encoding occupies two bytes. Therefore, characters in Java can store a Chinese character.
Seven · operator
1. Character and string participation operations: strings and other types of data when using the + number operation, the string is concatenated with other types of data, returning the concatenated new string
2. (emphasis) arithmetic operator:/division operation, the result is quotient. % takes the remainder operation, the result is the remainder, the ++,--operator precedes the operand, the operand is increased by 1 or the self-decrement 1,++,--operator after the operand, first participates in the assignment operation, then the operand increases 1 or self-subtract 1
3. (focus) Assignment operator: +=,-=, such as this operator with a cast function, the left of the assignment operator must be a variable
4. = Assignment operator, the right side of the result is assigned to the left variable, = =: comparison operator to determine whether the data on both sides are equal, the returned result is a Boolean type (True\false)
Question: Does the sting type belong to the basic data type in 8? What is the one that belongs to?
Basic syntax in Java (i)