Identifier: Declares the so-called class name, variable name, and so on.
Rules:
- Can be composed of letters, numbers, underscores _ and dollar sign $;
- Cannot begin with a number;
- Cannot use Java keywords;
- to have meaning;
- Capitalize the first letter of the class name;
- Use the Hump name method (e.g. Javascore).
There are two ways to define variables:
Data type
1. Variable name = value
Name variables while declaring them
Data type variable name
2. Variable name = value
Declare the variable, and then assign the variable as needed
What is a variable?
For example:
hotel room is variable
Room number room number is variable name
Room type room type is data type
The people who live live are the numbers.
The process of using variables:
- declare a variable;
- Assigned value;
- Use
Data type: base data type, reference data type (String)
Basic data type:
Values: integers, floating-point numbers
Non-numeric: boolean, character
Integers (byte, short, int, long)
Floating-point numbers (float, double)
Boolean "Boolean,true (True), False (False)"
Data conversion:
1. Same type;
2. Automatic conversion (low can automatically turn high), cast (High turn low (low type) can be converted);
Operator: + 、-、 *,/,% (remainder), = (Assignment operator)
Logical operator 1. "| |" : Or, take one of the two
- "&&" short circuit and both are satisfied.
Relational operators:! = (not equal to), >= (greater than or equal), <= (less than equals);> (greater than) < (less than) = (equals)
Scanner input = new Scanner (system.in);
(Receive keyboard input)
Int num =input.nextint (); [Convert int value]
(Next not only with int but also with other)
For example:
- Nextlong;nextdouble, wait.
Capitalize the first letter of the word after 2.next
Getting Started with Java Chapter II