java self-learning finishing 4

The eight basic types of learning java today

In Java code, each variable must declare a type  

There are eight basic types of Java, basic types can be divided into three categories, character type char, boolean boolean and numeric types

Numeric types can be divided into integer types byte, short, int, long and floating point types float, double

byte: 8 bits, the maximum amount of stored data is 255, and the range of stored data is between -128 ~ 127. Example: byte a = 100, byte b = -50.

short: 16 bits, the maximum data storage capacity is 65536, and the data range is -32768 ~ 32767. Example: short s = 1000, short r = -20000.

int: 32 bits, the maximum data storage capacity is 2 to the 32nd power minus 1, the data range is negative 2 to the 31st power to positive 2 to the 31st power minus 1. Example: int a = 100000, int b = -200000.

long: 64 bits, the maximum data storage capacity is 2 to the 64th power minus 1, and the data range is negative 2 to the 63th power to positive 2 to the 63th power minus 1. Example: long a = 100000L, Long b = -200000L.

float: 32 bits, the data range is 3.4e-45 ~ 1.4e38, when direct assignment must add f or F after the number. Example: float f1 = 234.5f.

double: 64 bits, the data range is 4.9e-324 ~ 1.8e308, you can add d or D when assigning it or not. Example: double d1 = 123.4.

boolean: There are only two values, true and false. Example: boolean one = true.

char: 16 bits, store Unicode code, use single quotes to assign value. Example: char letter = 'A' ;.

-------------------------------------------------- ---------------------------------------------- The above are me I worked hard on the Internet ~~ (// ▽ //) ~~~~~~~~~~~~~~~~~~ `

Pay attention to learning how to use it ~ It ’s not about getting it back down ~ It may take a few look at the interview. In fact, it will be natural after a long time.

Ok, let's start using ~

Amount ~~ No, let's talk about variables before starting to use ~~~

Variables are actually similar to algebra ~~ For example, set X to 5 x is a variable

 

 

 

 

 

The code is executed from top to bottom, and the variable can be assigned repeatedly, but only the last one will be kept.    Note that = is the meaning of the assignment is not equal to

 

 

 

 

 

 

The above is just an example, you can try it yourself  

 Variables have scope, and I will say later ~

 

 

Oh, I suddenly remembered that there are reference types, the most commonly used is the Stringstring

Use the same    

String s = "我是字符串";

System.out.println(s);

There are constants. Constants are added with final

Constants cannot be assigned again after initialization when they are defined

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/cjb1/p/12750531.html