当前位置:网站首页>Integer case study of packaging
Integer case study of packaging
2022-07-03 12:45:00 【Persia_ Pepper】
introduce
First of all, I wrote the title of learning Integer As a case study , Because I know a packaging class , Others can learn in simple terms ~
1. What is packaging :
Previously defined variables , Basic data types are often used ,
For basic data types , It's just a number , Add point attribute , Adding point method , Add a point constructor ,
The basic data types are encapsulated correspondingly , A new class is generated ,—》 Packaging .
int,byte…—> Basic data type
Packaging —> Reference data type
2. Corresponding relation :
Basic data type The corresponding packaging class Inheritance relationships
byte Byte ---》Number---》Object
short Short ---》Number---》Object
int Integer ---》Number---》Object
long Long ---》Number---》Object
float Float ---》Number---》Object
double Double ---》Number---》Object
char Character Object
boolean Boolean Object
3. There are already basic data types , Why package as a wrapper class ?
(1)java Language Object oriented language , I am best at operating various classes .
(2) I used to learn to load data —》 Array ,int[] String[] double[] Student[]
After learning, you can install data —》 aggregate , There is a feature , Only data of reference data type can be loaded
Integer Packaging
1. Direct use without guide package
2. Class inheritance :
3. Implementation interface :
4. This class is final modification , Then this class cannot have subclasses , uninheritable :
5. Wrapper class is the encapsulation of basic data types : Yes int Type encapsulation produces Integer
6. attribute
// attribute :
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
//“ Too much ” principle :
System.out.println(Integer.MAX_VALUE+1);
System.out.println(Integer.MIN_VALUE-1);
Running results :
2147483647
-2147483648
-2147483648
2147483647
7. Constructors ( Found no empty parameter constructor )
(1)int Type as a constructor parameter :
Integer i1 = new Integer(12);
(2)String Type as a constructor parameter :
Integer i2 = new Integer("12");
Integer i3 = new Integer("abcdef");
8. Packaging specific mechanism : Automatic boxing Automatic dismantling
// Automatic boxing :int--->Integer
Integer i = 12;
System.out.println(i);
// Automatic dismantling :Integer--->int
Integer i2 = new Integer(12);
int num = i2;
System.out.println(num)
(1) Automatic boxing Automatic dismantling It's from JDK1.5 New features in the future
(2) Automatic boxing Automatic dismantling : Fast type conversion between basic data types and wrapper classes .
verification :
You can customize the break point to test whether you enter valueOf In the method :
9. Common methods :
valueOf The bottom layer of the method :
Code :
public class Test04 {
// This is a main Method , It's the entrance to the program :
public static void main(String[] args) {
//compareTo: Only three values are returned : Or 0,-1,1
Integer i1 = new Integer(6);
Integer i2 = new Integer(12);
System.out.println(i1.compareTo(i2));// return (x < y) ? -1 : ((x == y) ? 0 : 1);
//equals:Integer Yes Object Medium equals Method is overridden , The comparison is the one encapsulated at the bottom value Value .
//Integer The object is through new Keyword created objects :
Integer i3 = new Integer(12);
Integer i4 = new Integer(12);
System.out.println(i3 == i4);//false because == Compare the addresses of the two objects
boolean flag = i3.equals(i4);
System.out.println(flag);
//Integer Objects are automatically boxed :
Integer i5 = 130;
Integer i6 = 130;
System.out.println(i5.equals(i6));//true
System.out.println(i5 == i6);
/* If the auto packing value is -128~127 Between , Then the comparison is the specific value No in , The comparison is the address of the object */
//intValue() : The effect will be Integer--->int
Integer i7 = 130;
int i = i7.intValue();
System.out.println(i);
//parseInt(String s) :String--->int:
int i8 = Integer.parseInt("12");
System.out.println(i8);
//toString:Integer--->String
Integer i10 = 130;
System.out.println(i10.toString());
}
}
Running results :
-1
false
true
true
false
130
12
130
边栏推荐
- (latest version) WiFi distribution multi format + installation framework
- How to stand out quickly when you are new to the workplace?
- Sword finger offer05 Replace spaces
- Solve the problem of VI opening files with ^m at the end
- 基于Linu开发的项目视频
- Idea packages the web project into a war package and deploys it to the server to run
- Xctf mobile--app1 problem solving
- [ArcGIS user defined script tool] vector file generates expanded rectangular face elements
- 2020-10_ Development experience set
- Xctf mobile--rememberother problem solving
猜你喜欢
GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
If you can't learn, you have to learn. Jetpack compose writes an im app (I)
剑指Offer07. 重建二叉树
最新版抽奖盲盒运营版
studio All flavors must now belong to a named flavor dimension. Learn more
云计算未来 — 云原生
Powerful avatar making artifact wechat applet
Method overloading and rewriting
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
Alibaba is bigger than sending SMS (user microservice - message microservice)
随机推荐
The solution to change the USB flash disk into a space of only 2m
Cloud Computing future - native Cloud
Adult adult adult
Exploration of sqoop1.4.4 native incremental import feature
【计网】第三章 数据链路层(2)流量控制与可靠传输、停止等待协议、后退N帧协议(GBN)、选择重传协议(SR)
Apache Mina Development Manual
Sqoop1.4.4原生增量导入特性探秘
Using swift language features, write a pseudo-random number generator casually
Swift bit operation exercise
基于同步坐标变换的谐波电流检测
4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
Airflow installation jump pit
2020-11_ Technical experience set
1-2 project technology selection and structure
启用MemCached的SASL认证
写一个简单的nodejs脚本
Differences between initial, inherit, unset, revert and all
Record your vulnhub breakthrough record
Keep learning swift
阿里大于发送短信(用户微服务--消息微服务)