JAVA Basics - Learning Summary - Grammar Basics

Identifier Concepts and Naming Rules

 

JAVA constants - immutable variables

 

program execution

From now on, you should remember that the memory is divided into four areas, code segment, data segment, stack, heap, when actually executed, the code is first put into the code segment, the virtual machine finds the relevant main method, and then starts crackling. The crackling execution will involve the other three memory areas during the execution process. Because memory needs to be allocated in different areas during execution.

 

Java variables

1. A variable in java is the smallest storage unit in a program, and its elements include variable name, variable type, and scope .

2. Each variable in a java program belongs to a specific data type, which must be declared before use, and then assigned.

 

 Scope of JAVA variables

Any variable declared inside curly braces, no one will know it outside the curly braces. (Why can't we say method and class, because in if statement and loop statement, no one will know it after the statement).

 

Classification of JAVA variables

 Note: the parameters of the method are local variables

 

JAVA data type division

 

The basic data types include four types and eight types, which are distinguished according to the size of the space occupied in the memory. When the size is the same, the layout in the memory may be different (the arrangement of 0101 is different);

 

char type;

 Java characters are encoded in Unicode, and each character occupies two bytes, so it can be represented by hexadecimal encoding (encoding problem: no matter what is in the computer, it is represented by 0101, and each 0 and each 1 are called bits (bits). ), a byte occupies 8 bits, all characters can be represented by 0101, but different characters may occupy different numbers of 0101, a byte can represent up to 2^8 characters, so it cannot represent Chinese, Unicode All languages ​​in the world are included.)

 

integer type;

 

There are no unsigned integers in JAVA, all integers are signed, so the representation range of the int type is -2^7-2^7-1.

 

floating point type

There is an error in the internal representation of floating-point numbers in the computer, and the situation is complicated and needs to be further studied.

 

Basic data type conversion

字符型在计算机内部也是数字,所以也可以进行运算,

long a = 123;// 相当于把一个int类型转换为long类型;

float a = 12.3;// 相当与把一个double转换为float,需要加上强制转换负符;

long l = 3000000000000;// 必须加L,3000000000000超出了int类型的表示范围;

int类型占四个字节,要想转换成byte类型,就把三个字节咔嚓砍掉,剩下的字节是几就是几;但是double转换成float不行,计算机内部有专门表示小数点的位,直接砍掉内部的格式就不对了.

float类型转换成long类型,直接把小数部分咔嚓砍掉.

 

运算符

int i = j++;先赋值再运算;

int i = ++j;先运算在赋值;

三目: (boolean表达式) ? y : z;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324676225&siteId=291194637