当前位置:网站首页>Wow, it's so rich.
Wow, it's so rich.
2022-06-25 07:08:00 【grace. free】
It's in 2022 One morning in, Zhuge thirteen met two people : Zhang San and Zhang Sanfeng .
Yes , Zhang San is the outlaw maniac , Zhang Sanfeng is the old man with a long beard .
Someone asked , What's the relationship between them , As you can see , They are both human beings , And the name contains Zhang San , That's it .
Many people ask Java Follow JavaScript What does it matter , They are both a programming language , And the name contains Java, That's it .
JavaScript It's a weakly typed language , No matter how it is used var、const still let Can store any type of data .
Java Is a strong type of language , Each variable must specify a type ( as for JDK10 Supported by var Modify local variables , Let's talk about it , What I'm talking about now is JDK8)
Many friends who have just graduated will be asked in the interview :Java There are several basic data types ? What are they ? What are their characteristics ? How many bytes ?
Ask someone who has just graduated this question , Mainly to investigate his basic skills .
Let's have a brief talk next Java The base type
One 、Java There are several basic types
Java Yes 8 Basic data types , Respectively :
- 6 Number types :
Integer type : byte、short、int、long
floating-point :float、double - 1 Types of characters :char
- 1 Middle boolean type :boolean
Two 、 Briefly introduce this 8 Type of data
2.1 byte
byte The data type is 8 position 、 The signed , An integer represented by a binary complement ( The computer indicates that the complement is used , As for why , And what is the original code 、 Inverse code 、 Complement code , This is the knowledge of College , Forget the , Wait for me , The next one is about )
minimum value -128 (-2^7)
Maximum 127 (2^7 -1)
The default value is 0
Example : byte b = 10, byte by = -2;
byte Type is used in large arrays to save space , Of course, mainly with int To compare ,int Occupy 4 Bytes , One value is byte Of 4 times , But we must pay attention to the scope , If the value range is not byte Within the maximum and minimum range , Let's not use byte According to the .
How to calculate the maximum and minimum , We will also write this separately in the next article , Actually short、int、long similar
2.2 short
- short The data type is 16 position 、 A signed integer represented by a binary complement
- The minimum is -32768 (-2^15)
- The maximum is 32767 (2^15 -1 )
- The default value is 0
- Example :short s = 1888, short sh = - 1999;
- short Data types can also follow byte Save space as well , One short The space occupied is 2 individual byte size , But it's half int size
2.3 int
- int The data type is 32 position 、 A signed integer represented by a binary complement
- The minimum is -2147483648 (-2^31)
- The maximum is 2147483647 (2^31 -1 )
- The default value is 0
- We usually write code , It's all direct use int type , Because now computer memory is not a big problem , We mainly focus on the realization of functions , But we need to know byte、short、int The amount of memory occupied by , And data range , no need , But you don't have to know .
2.4 long
- long The data type is 64 position 、 A signed integer represented by a binary complement
- The minimum is - 9223 372 036 854 775 808 (-2^63)
- The maximum is 9223 372 036 854 775 807 (2^63 -1 )
- The default value is 0L
- Be careful : We'll use it again long Type data must be added after the value L( Case insensitive , But it's better to use capital letters , A lowercase letter “l” And figures “1” Easily misread )
- Example : long a = 19234034L, long b = -123243434L;
- We use... In our program long type , Generally, it means time stamp 、 Self increasing id、 amount of money ( The amount does not need to be fload、double stay Java We usually use long Store points or use Bigdecimal Storage element )
2.5 float
- float The data type is single precision 、32 position 、 accord with IEEE 754 Standard floating point numbers ( What is? IEEE 754 standard , And why fload、double Cannot represent an exact value , For example, currency , We will also talk about in the following article )
- fload Memory can be saved when storing large floating-point arrays ( And double Compared to just )
- The default value is : 0.0f
- Example : fload f = 232.3f; To add f
2.6 double
- double The data type is double precision 、64 position 、 accord with IEEE 754 Standard floating point numbers
- The default type of floating-point number is double type , That's why we define float You need to add f
- double And float equally , Cannot represent an exact value
- The default value is \u0000 Empty space
- Example :double d = 23.1,double d2 = -23343.3434;
2.7 char
- char The type is a single 16 Bit unicode character
- minimum value \u0000 It's empty To an integer, that is 0
- Maximum \uffff To an integer, that is 65535
- char The data type can store any character
- Example : char e = ‘B’,char r =‘ Love ’ Attention WOW , Here is the single quotation mark , Rarely in Java I see single quotation marks in
2.8 boolean
boolean Information representing a person
Only two values : true false
The default value is : false
Example : boolean flag= true;
boolean How much space does the type take up Logically speaking, it means true or false 0 and 1 One bit It means
however Java The virtual machine specification says : Use alone boolean After compilation, it will be converted to int Type is 4 Bytes , If it is boolean Array words , After compilation, it will be converted to byte Type is 1 Bytes . This depends on the specific virtual machine implementation , Whether it is according to the specification .
There are many new entrants. Look at these types , This is also a must for entry ,
边栏推荐
- StreamNative Platform 1.5 版本发布,集成 Istio、支持 OpenShift 部署
- 基於 KubeSphere 的分級管理實踐
- Event registration | Apache pulsar x kubesphere online meetup is coming
- lotus v1.16.0-rc2 Calibration-net
- 燕京啤酒何以至此?
- Cloning and importing DOM nodes
- [Shangshui Shuo series] day 4
- Americo technology launches professional desktop video editing solution
- Clearing Magento log data - clearing Magento log data
- [acnoi2022] the structure of President Wang
猜你喜欢

深入解析 Apache BookKeeper 系列:第三篇——读取原理
![[he doesn't mention love, but every word is love]](/img/28/0c3ddad3dc9b1ef8d0618164f39e53.png)
[he doesn't mention love, but every word is love]

Ctfhub web - divulgation d'informations - traversée du Répertoire

アルマ / 炼金妹

In depth analysis of Apache bookkeeper series: Part 3 - reading principle

48 张图 | 手摸手教你微服务的性能监控、压测和调优

原子Alpha开发板--SD卡和emmc烧录工具

基于 KubeSphere 的分级管理实践
![[tool sharing] a software that pays equal attention to appearance and skills](/img/c0/2c648752163d88e16e357e8a096354.png)
[tool sharing] a software that pays equal attention to appearance and skills

Understand ZBrush carving software and game modeling analysis
随机推荐
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
Ht513 I2S input 2.8W mono class D audio power amplifier IC
Unity获取资源路径
Derivation of COS (a+b) =cosa*cosb-sina*sinb
Solar orbiter captured the full picture of the largest prominence eruption in history
Americo technology launches professional desktop video editing solution
分布式锁中的王者方案 - Redisson
Blue Bridge Cup SCM module code (external interrupt) (code + comment)
レ / leilei
In depth analysis of Apache bookkeeper series: Part 3 - reading principle
48 张图 | 手摸手教你微服务的性能监控、压测和调优
Kubernetes cluster dashboard & kuboard installation demo
How to realize the stable output of 3.3v/3.6v (1.2-5v) voltage of lithium battery by using the voltage rise and fall chip cs5517
Want to self-study SCM, do you have any books and boards worth recommending?
100 times larger than the Milky way, Dutch astronomers found mysterious objects in deep space
Uncaught TypeError: Cannot read properties of undefined (reading ‘prototype‘)
[从零开始学习FPGA编程-43]:视野篇 - 后摩尔时代”芯片设计的技术演进-2-演进方向
Blue Bridge Cup SCM module code (nixie tube) (code + comments)
赚够钱回老家吗
lotus v1.16.0-rc2 Calibration-net