Java Data types
The Java language is a strongly typed language that defines specific data types for each data and allocates different sizes of memory space in memory.
First, the JVM management of memory
1. Stack memory
Call the method name, some basic data types declared in the method
2. Heap Memory
New keyword New object, reference data type
3. Method area
Static variables, constants, classes of information
Note that the int and float types are 4-byte, 32-bit, but their range is different and int is more accurate.
Second, Java has three different representations of integers
A. Decimal: 0-9, full 10 in one
B. Eight binary: 0-7, full 8 in one, start with 0
C. 16 binary, 0-9,a-f, full 18 in one, start with 9X
Three, the basic conversion of the binary
A. Decimal to binary: Except 2 to take the remainder
B. Binary to decimal: by power of 2
C. Eight binary, binary mutual transfer: One variable three bit, three bit variable one
Iv. binary representation of negative numbers
corresponding integers binary inverse plus one
Exercise 1: Convert the binary number 1101.101 to a decimal number
Exercise 2: Convert decimal integer 105.625 to a binary integer
Parse: integer part from bottom to top take remainder part, fractional part take whole number from top down
Exercise 3: Convert 1011101001.110101B to hexadecimal number
Parse: integer part from right to left number of 4 numbers for a group, not enough bit of complement 0
Number of decimal parts from left to right 4 numbers for a group, not enough for the complement 0
Example code:
1 PackageCom.sanlianxueuan;2 3 Public classDemo02 {4 5 /**6 * Java data type7 */8 Public Static voidMain (string[] args) {9 //byte typeTen byteAge = 20; One //byte age2 = n;//Maximum range exceeded A //byte age = true;//data type not compatible - System.out.println (age); - the //Integral type - ShortNumber1 = 10; - intNumber2 =100; - LongNumber3 = 1000; + System.out.println (number1); - System.out.println (number2); + System.out.println (NUMBER3); A at //floating Point Type - floatNumber4 = 123.435f; - DoubleNumber5 = 0.124; - DoubleNumber6 = 0.124e3;//Scientific Counting method: 0.124*10^3 - System.out.println (NUMBER4); - System.out.println (NUMBER5); in System.out.println (NUMBER6); - to //Boolean type + BooleanNumber7 =true; - System.out.println (number7); the * //Character Type $ Chardata1 = ' A ';//The character type must be enclosed in single quotation marks.Panax Notoginseng //Unicode encoding used by character char type in Java - //coding; gb2312 the //GBK-----GB Code + //16 binary represents the range of Unicode encoding: \U0000-\UFFFF A Chardata2 = ' \u0041 '; the CharDATA3 = 65; + System.out.println (data1); - System.out.println (data2); $ System.out.println (data3); $ - - the } - Wuyi}
Java Data types