2 java study notes constants, variables, operators.

First, the constant
1. Definition: Value program executes the same amount of
2, Category: literals and custom constants
Normal Expression 3, constants: binary, octal, decimal, hexadecimal.
Following breakdown: Here Insert Picture Description
two, variable
1, definition: A change occurs in an amount within a certain range
of data type variable name = variable value;: 2 format
Note : not initialized assignment can not be used directly; a scope can define a variable.
3, the data type classification: basic data types and the reference data types
Here Insert Picture Description
4, data type conversion, and cast into an implicit type conversion
(1), an implicit conversion: short byte char is first converted to an int operator involvement, if any long float double would be transformed into long flaot double; boolean not involved in operations.
(2), cast Type: Format: target data type variable name = (destination data type) (converted data); (. Try not to use casts conversion, because of loss in accuracy may be present)
Note : Integer type Default int, and the default is a decimal type double
float 5 + B = 5.5; // no compiler error by 5.5 turn to a double precision float has lost
5, and a string of characters involved in computing
System.out.println ( 'a') ; / / output a
System.out.println ( 'a' +. 1); / / output 98
ASCLL corresponding to three values:'a'97,' A'65, '0'48.
+ is referred to as a character string in a string participation connector
System.out.println ( "=. 5. 5 +" + +. 5. 5); / / . 5 = 55. 5 +
System.out.println (. 5. 5 + + "+ =. 5. 5"); / / 10 + =. 5. 5
III operator
1, the definition: constant and variable symbols called operators operate.
2, Category: below
Here Insert Picture Description
note
(1), to give only an integer division integer. If you want a decimal, use the float
(2), is the quotient obtained by dividing the operation, acquired% is the remainder of a division operation
symbol% result of the operation depends on the participation of operation is the symbol of left
3, from plus (+) and decrement (-) usage
alone: in front of and behind the same effect as the operand.
Use involved in computing:
in front of the operands, the first increment or decrement, and then participate in operation.
Operand placed behind the first operation involved in, and then increment or decrement.
For example: X = int. 4;
int Y = (X ++) +1+ (the -X-) +2+ (10 * X);
X =. 6, Y = 55

. 4, the basic usage of the assignment operator
(1), the basic assignment operator: = = right data assigned to the left.
(2), extended assignment operator: + =, - =, * =, / =,% =, + = do addition to left and right, and then assigned to the left.
(3), the assignment operator requires data on the left must be a variable
5, logical operators
Logical operators are: & (and), | (or), (non), ^ (exclusive OR), && (shorted), || (or short circuit)!
Connecting the boolean logical operators are generally used for expression of or value. Note : In Java we wish to express a number greater than 3 and less than 6, may not be written 3 <x <6, should be written as x> 3 & x <6.
Difference and logical operators && &: The ultimate result of the same, has a short circuit && effect. The left is false, the right is not executed.
6, Bitwise Operators
Bitwise operators are: & (and), | (or), ^ (exclusive or) ~ (bitwise), << (shift left), >> (shift right), >> > (unsigned right shift)
Note : bit operation is performed directly on the two's complement arithmetic.
&, |, ^, Usage - the
conclusion: & There 0 0; | there is a 1; ^ same is 0, the different is 1; ~ bitwise 0 to 1 1 to 0
^ features: a data another two XOR data bits, the number itself is not altered.

7, the ternary operator
format :( relational expression)? Expression 1: Expression 2;
flow: Calcd relational expression, if true, the result of the operation is the expression 1; if false, the result of operation is the expression 2;

Published 24 original articles · won praise 11 · views 2066

Guess you like

Origin blog.csdn.net/weixin_43791069/article/details/84541556