[Java] Introduction to Java programming basics: variables and data types

1 JAVA data type

Basic data type
Reference data type
Custom data type
Insert picture description here
Insert picture description here

8 basic data types:

byte 字节型 1   -128~127
short  短整型 2
int 4
long 8
float 4
double 8
char 字符型 1  0~65535
boolean 1(作为数组中的某个元素)或4(作为单独的变量)

Computer storage data:
registers (Java cannot directly control and process)
Stack space: high access efficiency; first-in-first-out; small storage space; JVM stores all basic types of data in the stack space.
Heap space: the lowest access efficiency; random storage locations Allocation; large storage space; heap space for arrays, strings, objects, etc.

2 Definition and function of variables

Variable
Constant
Literal quantity: The quantity stored in a variable or constant: such as integer 1234, string "abc"

Variable management basic type data: use variables instead of obscure memory addresses to facilitate manipulation of data in memory.
Variable management reference type data: variables are placed in stack space, reference type data is placed in heap space, and variables in stack space are stored in addresses and addresses It is the address of a piece of memory in the heap space, where the real data is stored.

3 Naming, definition and initialization of variables

Naming rules:
First letter: English letters, $, underscore, composed of letters, numbers, and underscores.
See the name to know the meaning.
Chinese is not recommended. The
first letter is not recommended to be capitalized.
Camel case naming method

4 Variable scope

Leave the code block, the variables defined in the code block will be recycled by the JVM

5 Packaging classes of basic data types

Byte
Short
Integer
Long
Float
Double
Character
Boolean

Some practical methods and constants are encapsulated in the
wrapper class ; the wrapper class can define the element type in the collection.

Methods and constants:

Integer.MIN_VALUE  	int 类型的最小值 -231次方
Integer.MAX_VALUE  	231次方,-1
int Integer.parseInt(String sInteger);10”转成10
String Integer.toBinaryString(int value); 	十进制转二进制,返回String类型
String Integer.toHexString(int value); 		十进制转十六进制,返回String类型

Guess you like

Origin blog.csdn.net/qq_30885821/article/details/108631901
Recommended