1. Variables: Variables are a basic unit for storing data, and different variables are independent of each other.
2.Java Data type:
1) Boolean type:
Boolean: Boolean, 8-bit, numeric range: True,false
2) Character type:
Char: Character type, 16-bit, range 0~65535, e.g. ' a '
3) Numerical Type:
Byte:8 bit, value range: 128--127, e.g. 12,100,-20
Short:16 bit, value range: 32768--32767, e.g. 154,-134,1234
int: integer, 32 bit, value range: 2147483648--2147483647
Long:64 bit, value range:-2 of 63 square-2 63 square-1
FLOAT: single-precision floating-point, 32-bit, value range 1.4E-45--3.4e+38,-1.4e-45---3.4E+38
Double: dual-precision floating point, used to store numeric values with decimals, 64 bits. 4.9E-324--1.7e+308,-4.9e-324---1.7E+308 such as -3.145,3.568
4) String type
String: Used to store a string of characters such as "Zhang San", "A4 paper"
3. Declaration and use of variables:
Data type variable name;//Declaration of variable
Variable name = value;//Assignment of variable
such as: int A;
A = 20;
We can also declare variables and assign values to them at the same time.
Data type variable name = value;
such as String name = "Zhang San";
4. Variable naming rules:
Must begin with a letter, an underscore "_", or a "$" symbol.
Variables can include numbers, but they cannot start with a number.
In addition to the underscore "_" and "$", no special characters can be protected.
You cannot use Java keywords such as int class public, and so on.
5. Data type conversions:
Arrogance becomes smaller: auto-convert (implicit conversion)
Getting bigger from childhood: casting (Explicit conversion)
6. Relational operators:
: Greater than >=: greater than or equal to
<: Less than <=: less than or equal to
= =: equals! =: Not equal to
The result is either true or false
7. Conditional operators:
Conditions? Expression 1: Expression 2: The condition is judged, if the condition is true, enter expression 1, otherwise input expression 2.
8. Logical operators:
&: Only both sides are true and the result is true. Otherwise, it is false.
|: If both sides are false the result is false, otherwise it is true
^: xor: And or a little different.
On both sides, the result is false.
The result is different on both sides, true
& and && difference: &: Regardless of the left result, the right side participates in the operation.
&&: Short circuit with, if the left is false, then the right side is not a parameter and operation.
| and | | Difference: |: Regardless of the left result, the right side is involved in the operation.
|| : Short circuit or, if the left is true, then the right side does not participate in the operation
Getting Started with Java 2---variables, data types and operators