当前位置:网站首页>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);
}
}
边栏推荐
- 有奖征文 | 2022 云原生编程挑战赛征稿活动开启!
- MySQL basic queries and operators
- Leetcode systematic question brushing (3) -- binary tree, binary search
- 【Unity】Timeline学习笔记(七):自定义片段(Clip)
- On the non recursive and recursive implementation of finding the nth Fibonacci number respectively
- Technical aspects passed easily, HR: those with only three years of experience in large factories are not worth 20K
- 【C语言进阶】——剖析入微数据在内存中的存储[上]
- Alibaba P8 architect talk: seven knowledge points (including interview questions) that must be learned well to become an architect
- 多线程的使用
- [machine learning notes] regularization: ridge regression
猜你喜欢

Interviewer: the actual record of algorithm question brushing.pdf I can't even answer it

.net MVC understanding

数字滤波器(四)--模拟滤波器转化为数字滤波器

Three ways to dynamically call WebService.Net

Use of multithreading

Jerry ac692n --- prompt tone compression and modification

leetcode系统性刷题(一)-----链表、栈、队列、堆
![[advanced C language] - function pointer](/img/73/95380bb719f609e80de56985ed68fd.png)
[advanced C language] - function pointer

leetcode系统性刷题(二)------贪心、回溯、递归

Mysql 优化总结
随机推荐
【C语言笔记分享】字符函数和字符串函数(建议收藏)
Three ways to dynamically call WebService.Net
leetcode系统性刷题(一)-----链表、栈、队列、堆
1.2-进制转换
Jerry ac692n --- prompt tone compression and modification
Point cloud processing -- binary tree
LeetCode--45. 跳跃游戏Ⅱ(贪心)
怎样将IDEA与码云进行绑定
有奖征文 | 2022 云原生编程挑战赛征稿活动开启!
Can‘t use an undefined value as an ARRAY reference at probe2symbol
中南大学研究生复试机试题
【C语言进阶】——函数指针
编译原理学习笔记2(语法分析介绍)
多线程(线程池ThreadPoolExecutor)
C#中virtual(虚方法)的理解以及和abstract(抽象方法)的区别
Prize essay solicitation | the 2022 cloud native programming challenge draft activity is open!
【Unity FPS】教程 | 使用Unity制作第一人称角色控制器
Tips--SCI论文写作中的小技巧
[p5.js learning notes] basic knowledge of code drawing
【p5.js学习笔记】局部变量(let)与全局变量(var)声明