The current Java version has not been used and may use goto const in the future.
Second, the identifier
1. Identifier concept
Consists of an alphanumeric underscore $
Cannot start with a number
Avoid keywords and reserved words
case sensitive
Cannot contain spaces such as book name ----> book_name
2. Naming convention
Lowercase package name
If the class name has only one word, the first letter is capitalized. For multiple words, the first letter of each word is capitalized
Interface name and similar name
The first letter of the variable name and method name is lowercase. When there are multiple words, only the first letter of the first word is lowercase
Constant names are capitalized such as MAX_VALUE
When naming, try to be aware of the name book_name book_price
Three, variables
1. Variable concept
Used to save data in memory
Declare before use
Only valid within the range of {}
{
{
int x=0;}
x=1;//语法错误,x在中间的{}中才有效}
2. Variable classification
Basic data type
Reference data type
byte
class (String belongs to class
short
interface
int
Array[]
long
float
double
char
boolean
8 types
3 types
Member variables
Local variable
Declare in the class body
Declare in the method body
Instance variable
Formal parameters
Class variable static modification
Local variables defined in the method
Local variables in code blocks
Has a default value
Need to display initialization
Types of
Occupied bytes
Representation range
byet
1
-128~127
short
2
-215 ~ 215-1
int (default type)
4
-231 ~ 231 -1
long
8
-263 ~ 263 -1
3. Conversion of basic data types
Small capacity will automatically be converted to large capacity type (byte char short)—int—long—float----double
Byte short char will not be converted into each other when calculating it will be converted to int first
The boolean type cannot be calculated with other data types
When using forced type conversion, you need to add a forced conversion symbol, but the accuracy may be reduced
int a=3;short b=(int)a;
Four, base
1. Binary classification
Binary: 0b/0B starts with 2 and enters 1
Decimal: 1 2 3 4…
Octal: Start with 0
Hexadecimal: 0-9 and AF(af) beginning with 0x/0X
2. Several encodings
Original code: Convert a number into a binary positive number, the highest bit is 0, and the highest bit of a negative number is 1.
Inverse code: The inverse code of a positive number is the same as the original code. The inverse code of a negative number is inverted on the basis of the original code except for the highest bit.
Complement code: the complement of a positive number is the same as the original code's complement, and the complement of a negative number is based on the complement of +1
3. Base conversion
Decimal -> Binary multiplied by a power of 2
Binary -> Decimal divided by 2 to take the remainder
Octal -> Binary every 1 bit is represented by three binary digits 011=001001
Hexadecimal—>Binary Each bit is represented by four binary digits 11=00010001