当前位置:网站首页>2.2- data type
2.2- data type
2022-07-28 17:52:00 【night_ du】
Constant
Definition
- In the process ⾏ In the process, its value cannot be sent ⽣ change
- Constant means we ⽣ Living ⽤ The numerical , word ⺟ etc.
- Constant ⽆ The law is changed ,⼀ Dan change , Its meaning is also changed
classification
- word ⾯ Value constants
- ⾃ Define constants (⾯ Learn again from the object part )
word ⾯ Classification of value constants
- character constants : ⽤ The content enclosed in single quotation marks ‘a’
- String constant : ⽤ What is enclosed in double quotation marks “abc” “ufc”
- Integer constant : All integers 1 0 3
- ⼩ Number constant : be-all ⼩ Count 1.2
- Boolean Literals : ⽐ More special , Only true and false
- Null constant : null( The array section will talk about )
System.out.println(" Character type constant :" + 'a');
System.out.println(" String type constant :" + "abc");
System.out.println(" Integer constant :" + 1);
System.out.println(" Floating point type constants :" + 12.32);
System.out.println(" Boolean type constants :" + true + "\t" + false);
Variable
Definition
- In the process ⾏ In the process of , Within a certain range, you can send ⽣ change
- in other words , Its value can be changed , At different times , Same as ⼀ Variables can represent different values
- With variables , We make ⽤ Just get up ⾮ Always flexible
- In computer memory ⼀ Block storage space , Is the basic unit for storing data
technological process
Declare variables first , Then assign a value to the variable
Statement ⼀ A variable
data type Variable name ;
Assign values to declared variables
Variable name = value
Declare the entry of variables ⾏ The operation of assignment
data type Variable name = value
Declare multiple variables of the same type and initialize at the same time – It can be disassembled
data type Variable name 1, Variable name 2, Variable name 3, Variable name 4 = valueThe first ⼀ The second assignment operation is called initialization
public static void main(String[] args) {
int n; // Statement int Variable of type ( Only integer ), Unassigned
n = 10; // To the variable n assignment
int m = 20; // Statement int Variable of type , assignment
int x = 1, y = 2, z = 3; // Declare more than one int Variable of type
int a, b, c = 10;
}
data type
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-FMlALZtu-1645533840481)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831142857741.png)]](/img/0c/1211f58607a97973512d7a7274dd53.png)
byte 、 character 、 Character set and encoding method
- Bytes make up characters , Characters are the data we can see
- A character set is a set of characters
- The encoding method is the rule for characters to form a character set
Common coding methods
ASCII code :⼀ Ge Ying ⽂ word ⺟( Regardless of ⼤⼩ Write ) Occupy ⼀ Bytes of space ,⼀ Among them ⽂ Chinese characters occupy two bytes .⼀ individual ⼆ Hexadecimal number
Word sequence , As ⼀ Digital units ,⼀ General 8 position ⼆ Hexadecimal number , Conversion for ⼗ Base number . most ⼩ value 0, most ⼤ value 255. Such as ⼀
individual ASCII Code is ⼀ Bytes .UTF-8 code :⼀ Ge Ying ⽂ The character is equal to ⼀ Bytes ,⼀ Among them ⽂( Including traditional Chinese ) Equal to three bytes .
Unicode code :⼀ Ge Ying ⽂ Equal to two bytes ,⼀ Among them ⽂( Including traditional Chinese ) Equal to two bytes .
Symbol : Britain ⽂ Punctuation ⼀ Bytes , in ⽂ Punctuation takes up two bytes . give an example : Britain ⽂ Full stop “.” Occupy 1 Bytes of ⼤⼩, in ⽂ Full stop “.” Occupy 2
Bytes of ⼤⼩.GBK code ⽅ The formula is medium ⽂ Two bytes , Britain ⽂ Occupy 1 Bytes .
The conversion relationship of information units between different orders of magnitude
1B(byte, byte )= 8 bit;
1KB(Kibibyte, kilobytes )=1024B= 2^10 B;
1MB(Mebibyte, Megabytes , Megabytes , abbreviation “ mega ”)=1024KB= 2^20 B;
1GB(Gigabyte, Gigabyte ,⼗ Gigabytes ,⼜ call “ Gigabit ”)=1024MB= 2^30 B;
Basic data type
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-TWcwUx83-1645533840482)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831144316675.png)]](/img/30/60031280a82e0696781dd8dfdd03b0.png)
Integer types :
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-J6914Uri-1645533840483)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831144417151.png)]](/img/a7/2be9aeacf5f7775c045d864cc25950.png)
Create basic data type variables :
byte b = 10;
short s = 20;
int i = 30;
long l = 1000000000000L;
double d = 12.22;
float f = 5.1f;
boolean b1=true;
Lack of precision
public static void main(String[] args) {
double a=1.0;
double b=0.9;
System.out.println(a-b);
double c=(1.4-0.5)/0.9;
System.out.println(c);
}
Java The default of medium integer type is int , Floating point type defaults to double , double The accuracy of the ⽐float want ⾼, So if we're going to double Turn into float can
It can cause the problem of losing accuracy . So we're giving float When assigning a variable of type , want ⽤f Indicate the type of value
Use BigDecimal Deal with the lack of accuracy :
BigDecimal b1=new BigDecimal("1.0");
BigDecimal b2=new BigDecimal("0.9");
System.out.println(b1.subtract(b2));
Character type
char Two bytes 0~65535( No negative number )
ASCII: American Standard Code for information exchange
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-0exWUHYS-1645533840484)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831163537936.png)]](/img/b6/a33bb455da6089edc5e50f89553099.png)
- Unicode: In the field of computer science ⼀ Industry standard , Include character set .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-EEaK46pQ-1645533840484)(C:\Users\night_du\AppData\Roaming\Typora\typora-user-images\image-20210831163603439.png)]](/img/29/e6b647782084f251d966e2aebb9abd.png)
public class CharDemo {
public static void main(String[] args) {
//Acsll code
char a = 97;
System.out.println(a);
//Unicode
char b='\u4f01';
System.out.println(b);
}
}
Boolean type
Type conversion
Automatic type conversion
Assign a value or variable representing a small data range to another variable representing a large data range
Cast
Assign a value or variable representing a large data range to another variable representing a small data range
Format : Target data type Variable name =( Target data type ) Values or variables ;
Example :int k =(int)88.88;
public class TypeTranslateDemo {
public static void main(String[] args) {
// Automatic conversion
byte b = 10;
int i = b;
System.out.println(i);
// Strong go
int x = 5;
byte y = (byte) x;
System.out.println(y);
}
}
边栏推荐
- Point cloud processing -- binary tree
- 点云处理---kd-tree
- 电工学数电部分自学笔记1.25
- Collection集合
- PCA reports error in eigen (crossprod (t (x), t (x)), symmetric = true): 'x' has infinite value or missing value
- 【C语言进阶】——剖析入微数据在内存中的存储[上]
- PyTorch中grid_sample的使用方法
- Understanding of virtual (virtual method) in C and its difference from abstract (abstract method)
- Technical aspects passed easily, HR: those with only three years of experience in large factories are not worth 20K
- Tips--SCI论文写作中的小技巧
猜你喜欢
随机推荐
QT编写串口助手
Encapsulation, inheritance, polymorphism
电工学自学笔记1.21
MySQL与IDEA连接
MySQL and idea connection
Grid in pytorch_ How to use sample
[unity tilemap] tutorial | basic, rule tile, prefab brush, tilemap Collider
Database performance analysis and optimization (internal training materials of Aite future team)
leetcode系统性刷题(五)-----动态规划
分支与循环(for与do-while)
abstract、static、final
【C语言笔记分享】——动态内存管理malloc、free、calloc、realloc、柔性数组
Hgu95av2. Online installation failed
如何使用IDEA将项目上传到码云
进程、线程、信号量和互斥锁
2.1-运算符
【Unity Tilemap】教程 | Basic、Rule Tile、Prefab Brush、Tilemap Collider
Interviewer: the actual record of algorithm question brushing.pdf I can't even answer it
USB virtual serial port (CDC) limit speed test
【C语言进阶】——剖析入微数据在内存中的存储[上]




![[p5.js learning notes] local variable (let) and global variable (VaR) declaration](/img/37/82cdf73eb6527fb2da5bc550c33223.png)




