当前位置:网站首页>Difference between package type and basic type
Difference between package type and basic type
2022-06-24 10:23:00 【Ugly and ugly】
Java There is 8 Basic types of data in , Respectively :
6 Number types :byte、short、int、long, These four types are integer numbers ;float、double, These two types are floating point numbers ;
1 Kind of boolean type :boolean, namely true or false;
1 Types of characters :char.
this 8 The corresponding packaging types of the three basic types are :Byte、Short、Integer、Long、Float、Double、Boolean、Character.
| Basic types | Packaging type | byte | digit | The default value is | Range |
|---|---|---|---|---|---|
| byte | Byte | 1 | 8 | 0 | -128~127 |
| short | Short | 2 | 16 | 0 | -32768~32767 |
| int | Integer | 4 | 32 | 0 | -2147483648~2147483647 |
| long | Long | 8 | 64 | 0L | -9223372036854775808 ~ 9223372036854775807 |
| float | Float | 4 | 32 | 0F | 1.4E-45 ~ 3.4028235E38 |
| double | Double | 8 | 64 | 0D | 4.9E-324 ~ 1.7976931348623157E308 |
| boolean | Boolean | 1 | 8 | false | false、true |
| char | Character | 1 | 'u0000' | 0~65535 |
about boolean type , Official documents do not clearly define , It depends on JVM The specific implementation of the manufacturer . Logically, it means to occupy 1 position , But in practice, we will consider the factor of efficient computer storage . in addition ,Java The storage space occupied by each basic type of will not change with the change of machine hardware architecture like most other languages . The invariance of the amount of storage space occupied is Java One of the reasons why programs are more portable than programs written in most other languages .
in addition ,Java Use in long、float、double Type of data, it is best to add an identification after the value L、F、D perhaps l( A lowercase letter L)、f、d, Otherwise, the value will be parsed as integer data . also char Type is marked with single quotation marks , What is marked in double quotation marks is a string .
The difference between basic types and packaging types
(1) For member variables , If packing type is used , If the value is not assigned, the default value is null, There are default values for basic types
(2) The packaging type can be used for generic , And the basic type can't be .
(3) Local variables of basic data types are stored in Java In the local variables table in the virtual machine stack , Member variables of the basic data type ( Not by static modification ) Store in Java In the heap of the virtual machine . The wrapper type belongs to the object type , Almost all object instances exist in the heap .
(4) Compared to object types , Basic data types take up very little space .
It is a common misconception that basic data types are stored in the stack . If the member variable of the basic data type is not static Embellished words , It's in the pile . Generally speaking, it is not recommended to use static Modify member variables of basic types , The packing type corresponding to the basic data type should be used .
This article references from :Java Basic and common knowledge & Interview question summary ( On ) | JavaGuide
边栏推荐
猜你喜欢
随机推荐
3.员工的增删改查
3. addition, deletion, modification and query of employees
涂鸦智能携多款重磅智能照明解决方案,亮相2022美国国际照明展
学习整理在php中使用KindEditor富文本编辑器
线程的六种状态
Appium自动化测试基础 — 移动端测试环境搭建(一)
分布式 | 如何与 DBLE 进行“秘密通话”
自定义kindeditor编辑器的工具栏,items即去除不必要的工具栏或者保留部分工具栏
Go language development environment setup +goland configuration under the latest Windows
H5网页如何在微信中自定义分享链接
包装类型的缓存机制
Leetcode - 498: traversée diagonale
Engine localization adaptation & Reconstruction notes
leetCode-1089: 复写零
Impdp leading schema message ora-31625 exception handling
记录一下MySql update会锁定哪些范围的数据
The great charm of cookies
JMeter接口测试工具基础— 使用Badboy录制JMeter脚本
411 stack and queue (20. valid parentheses, 1047. delete all adjacent duplicates in the string, 150. inverse Polish expression evaluation, 239. sliding window maximum, 347. the first k high-frequency
2022全网最全最细的jmeter接口测试教程以及接口测试流程详解— JMeter测试计划元件(线程<用户>)









