Put the knowledge of Java in retrospect, or else forget it.
Basic data type: 4 classes of 8
Integer type
BYTE 1-128~127
Short 2
int 4
Long 8
Floating point Type
Float 4
Double 8
Character type
Char 2
Boolean type
Boolean 1
Different value ranges for memory space
Byte memory space 8
Short memory Space 16
int memory Space 32
Long Memory Space 64
Float Memory Space 32
Double Memory Space 64
1: When defining a long or float type variable, add either L or F.
integers are type int by default, and floating-point numbers are double by default.
Byte,short at the time of definition, they are actually receiving a value of type int.
This is self-made a data detection, if they are no longer within the scope of the error.
Problem with 2:byte value -128~127
One byte 01111111 127
BYTE B1 = 127;
byte b2 = (byte) 128; -128
byte B3 = (byte) 129; -127
byte b4 = (byte) 130; -126
Range of Byte: 128 ~ 127
127 01111111
-127:11111111
+1
------------------------
10000000
-128:10000000 (the highest bit is the sign bit, also the value bit) only at the critical time
3: Conversion of data type to the default conversion of small data types to large data types
Byte,short,char--INT--long--float--double
Long:8 bytes
Float:4 bytes
A: Their underlying storage structure is different.
The range of data represented by B:float is larger than the range of long
Long:2^63-1
float:3.4*10^38 > 2*10^38 > 2*8^38 = (2^3) ^38 = 2*2^114 > 2^63-1
4:java character Char in a language can store a Chinese character? Why?
OK. Because characters in the Java language occupy two of bytes.
The Java language uses Unicode encoding.
Constant: The amount of the value that does not change during program execution
Classification:
Literal constants
String constants
Integer constants
Decimal constants
Character constants can only be single characters
Boolean constant True and False
An empty constant array
Custom Constants
Binary: X-binary is every x into one
Binary consists of 0, 1 components 0b
Octal consists of 0-7 components 0
decimal integers are decimal by default
Hexadecimal by 0-9,a-f (can be uppercase) 0x
Binary conversion
Convert decimal in any binary
The method of position right expansion
Decimal conversion to arbitrary binary
In addition to the base fetch, until the quotient is zero, the remainder is reversed
Fast Conversion
8421 yards binary vs. decimal conversions
Octal grouping method for binary fast conversion
Binary fast conversion hexadecimal grouping method
Original code, anti-code, complement
There is a binary operation in the bottom of the computer
The data is calculated using the binary complement of the data.
The display uses the binary source code of the data.
The original inverse of the positive number is the same, the highest bit is the sign bit 0 The remaining bits are the value bits
Negative original code highest bit sign bit 1, remaining bit is value bit
The inverse code is the highest bit, the rest of the bits are reversed by bit
Complement anti-code +1
Variable:
The amount at which the value can change within a certain range during program execution
Equivalent to the unknown in mathematics
Define the format:
Data type variable name = initial value;
Constants of the same type
Implicit conversions exist in Java (default conversion)
(1): The Boolean type cannot be converted to another data type
(2): byte,short,char-int-long-float-double
(from the range of the small to the large range turn)
If an int type participates in an operation, the result must be an int type
If there is a long join operation, the result must be a long type
If a float participates in the operation, the result must be a float type
If there is a double to participate in the operation, the result must be double type
(3): Byte,short,char is not converted, they participate in the operation first converted to int type
Note: Large type turn small type may lose precision.
public class Datatyepdemo {public static void main (string[] args) {byte A = 3;int b = 4;int C = a+b; System.out.println (c);}}
There are also coercion type conversions
public class DataTyepDemo1 {public static void main (string[] args) {byte a =3;int b = 4;byte c = (byte) (A+B); System.out.println (c);}}
You find that the character corresponding to the int type should have a one by one corresponding relationship
Within a table
Ascii
' 0 ' 48
' A ' 97
' A ' 65
public class DataTypeDemo2 {public static void main (string[] args) {System.out.println ("Hello" + ' a ' +1); System.out.println (' a ' + 1 + "Hello"); System.out.println ("-------------"); System.out.println ("5+5=" +5+5); System.out.println (5+5+ "=5+5");}}
Results:
Helloa1
98hello
-------------
5+5=55
10=5+5
Considerations for using Variables
A: Scope issues
The variable is defined in the curly braces, and the range of the curly braces is the scope of the variable.
Two variables of the same name cannot be defined in the same scope.
B: Initialization value issue
No initialization value can be used directly
C: It is recommended to define only one variable on a single line
Multiple can be defined, but not recommended
Variable definition Format
Variable name of data type = initialization value;
Data type variable name;
Variable name = initial value;
public class Datetypenoticedemo {public static void main (string[] args) {int a = 10;int B = 10; System.out.println (a); System.out.println (b);}}
public class Datatypetest {public static void main (string[] args) {byte b = (byte) 130; System.out.println (b);}}
/* Analysis: 130 int type 4 bytes 32bit original code 00000000 000000000 00000000 10000010 coercion is an arithmetic complement Get after casting complement 00000000 000000000 00000000 10000010 cast 10000010 --------complement 10000001 --------Anti-code 11111110 ---------original code -126*/
public class DataTypeTest2 {public static void main (string[] args) {Float f1 = (float) 12.345; In this 12.345 constant is a double type of 8 bytes//made a strong turn after the assignment to the float type variable System.out.println (F1); float F2 = 12.345f; Here 12.345 constants are the direct assignment of the float type System.out.println (F2);}}
Put in front of operand
Add (Subtract) first and then participate in the operation
Put behind the operand
First participate in the operation and then add (Subtract)
public class DataTypeTest3 {public static void main (string[] args) {int a = 10;int b = 10;int c = 10;a = b++; A ten b c 10c =--a; A 9 b one c 9b = ++a; A ten B 9a = c--; A 9 b C 8system.out.println ("A:" +a); System.out.println ("B:" +b); System.out.println ("C:" +c);}}
Comparison operators
public class Operatordemo {public static void main (string[] args) {int a = 32;int B = 23; System.out.println (A==B); System.out.println (A>B); System.out.println (A!=B); System.out.println (B>=a);}}
This article from the "Clear Sky" blog, declined reprint!
Java eight basic data types store numeric values, characters, and Booleans