These two days have learned the basic data types and operators.
Sharing the learning process and writing ~
Data types are divided into basic data types and reference data types, and there are 4 classes of 8 basic data types:
Integral type: Byte,short,int,long
Float type: float and double
Character type: Char
Boolean type: Boolean (only True and false two values, used as a condition for judging)
Reference data types have arrays, classes, and interfaces.
Variables: can be re-assigned while the program is running, declaring the variable to request a memory space for the computer (its request space size corresponds to the data type)
public static void Main (string[] args) {
/* Integral type: Byte,short,int,long
Byte:1 bytes ( -2^7~2^7-1) ===>-128~127
Short:2 bytes ( -2^15~2^15-1) ===>-32768~32767
Int:4 bytes ( -2^31~2^31-1) ===> approximately 2.1 billion
Long:8 bytes ( -2^63~2^63-1)
Note the problem:
5555555555 the default int type, you must add l to represent the declared variable as a long type
3.14 default is double type, 3.14f is float
Floating-point type: float,double
Float:4 bytes, single-precision floating-point type, accurate to 7 digits after the decimal point
Double:8 bytes, double-precision floating-point type
*/
BYTE b=20;//range -128~127
System.out.println ("Byte--->b=" +b);
Byte b2=012;//octal, octal starting with 0
System.out.println ("Byte---> Octal b2=" +b2)//octal---> Decimal 10
byte b3=0x12;//16 binary, hex with 0 x beginning
System.out.println ("Byte---> Hex b2=" +b3)//Hexadecimal---> Decimal 18
Short s=300;//Range -32768~32767
SYSTEM.OUT.PRINTLN ("Short--->s=" +s);
int i=10000;//range approx. 2.1 billion
SYSTEM.OUT.PRINTLN ("Int--->i=" +i);
Long l=5555555555l;//5555555555 default int type, 5555555555L is a long type
System.out.println ("Long---->l=" +l);
float f=3.14f; 3.14 default is double type, 3.14f is float
System.out.println ("Float--->f=" +f);
Scientific counting method: 314e2=314*10^2
float f2=314e2f;//314e2 default to double type
System.out.println ("314e12==> of the scientific counting Method" +f2);
Double d=314e2;
System.out.println ("314e12==> of the double scientific counting Method" +d);
Double d2=1.123456789012345678;//Precision Rounding
System.out.println ("Double--->d2=" +d2);
Constants: Variables whose values cannot be changed while the program is running, declare constants in Java using Final, and once the variables are in the final decoration, the variable is a constant and cannot be re-assigned. Variable names are often capitalized (easy to differentiate from variables).
public static void Main (string[] args) {
/*
Constants: cannot be modified while the program is running.
Using the final decoration in Java, constants are generally named uppercase words or characters
3.1415926
*/
Final double pi=3.1415926;
pi=3.14; Constants cannot be re-assigned
Double r=5;
Double S=5*5*pi;
Double C=2*5*pi;
System.out.println ("The area of the circle is:" +s);
System.out.println ("The circumference of the circle is:" +c);
}
Type conversions:
Automatic conversions: Automatic type conversions: small-capacity data types can be automatically converted to large-capacity data types.
Byte--short--int--float--double
You can assign integer constants directly to type variables such as Byte, short, char, and so on, without forcing a type conversion, as long as it does not exceed its range of tables
Coercion type conversions, also known as styling, are used to explicitly convert a numeric type. Conversions made with the possibility of losing information are done through styling, but may result in reduced precision or overflow.
When a type is cast to another type, but beyond the scope of the target type, it is truncated to a completely different value.
That's the way it is now.
Java Beginner Chapter II