1, variable
l know Italian well-known: the amount will change. Is a data storage space.
l variable has three elements: variable name, variable type, variable value.
Identifier: a character string defining a set of names of various objects, generally divided into a user-defined identifier and system identifier.
Naming identifiers: the same variable naming conventions
2, the data type
l basic data types: four . 8 Species
v Integer ( Integer integer type)
- Byte byte 8
- Short integer short 16
- Int int 32
- Long integer long 64
v float ( a float real decimal)
- Single-precision float
- Double double
v Character ( char letter, Chinese, etc.)
v Boolean ( Boolean logic): A value of true or false
l complex data types: class, interface, array (eg: String )
NOTE: common data types
Char char single character for storage, such as: 'M'
Int int
Float float
String type String for storing a plurality of characters, such as: "the community service"
3, declaring and using variables
l Two-step: After the first assignment statement
For example: int Money;
Money=100;
l combined: declaration and assignment
For example: int Money = 100;
l variables used: System.out.println ( variable name );
Note: The variable names do not need quotation marks
4, variable naming rules
5, data type conversion
l automatic type conversions: small type to large type
- Rule 1 : If the operand is a double type, the whole expression can be promoted to double type.
- Rule 2 : the condition of automatic conversion
² to be compatible with two types: numeric types (integer and floating-point type) compatible with each other
² target type larger than the source type: for example: Double type is greater than int type
l cast
- Syntax: ( type name ) expression
NOTE: ascending order of data types , data type conversion data compatible with requirements.
Boolean (1) Byte (8 bit ) → Short (16 bit ) → int (32 bit ) → Long (64 bit )
↓ ↓
float (32 bit ) → Double (64 bit )
↓
char (32 bit )
6, the operator
l assignment operator: =
Syntax: variable name = expression;
Example: int Score; Score = 30;
Arithmetic operators l
- Plus: +
- Less:-
- Multiplication: *
- except:/
- Remainder:%
- Jerk: As a ++ ++ is a = a + 1 [a ++ ++ A equals]
- And reduction: - The a-- is a = a-1 [a-- equal --a]
E.g:
a ++ and a-- after the first use addition and subtraction
++ a and --a after the first addition and subtraction using
NOTE: Priority: Decrement from Canada> parentheses> multiply and divide> subtraction
l common relational operators
> Greater than <Less than
== equal ! = Not equal
> = Greater than or equal <= Less than or equal
Note: The object relational operators are used for the comparison operation, the result of a boolean operation, either true or false.
l logical operators
And && must meet all the conditions to be true
Or as long as a can ||
Non-! Condition is true, the result is false. (in contrast)
l operator precedence
Highest priority: parentheses, ie ()
Lowest priority: assignment operator, i.e., =
Priority: !> Arithmetic Operators> Comparison Operators> &&> ||
Note: When more operators, operators can not determine the order of execution can be used when the control bit sequence parentheses