当前位置:网站首页>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
边栏推荐
- 双链笔记·思源笔记综合评测:优点、缺点、评价
- 2021 autumn Information Security Experiment 1 (password and hiding technology)
- 1-2 project technology selection and structure
- Solve the problem of VI opening files with ^m at the end
- It feels great to know you learned something, isn‘t it?
- Glide question you cannot start a load for a destroyed activity
- 并网-低电压穿越与孤岛并存分析
- Enter the length of three sides of the triangle through the user, and calculate the area of the triangle, where the length is a real number
- Write a simple nodejs script
- 雲計算未來 — 雲原生
猜你喜欢
Differences between initial, inherit, unset, revert and all
Wechat applet pages always report errors when sending values to the background. It turned out to be this pit!
Eureka自我保护
4. 无线体内纳米网:电磁传播模型和传感器部署要点
Sword finger offer03 Repeated numbers in the array [simple]
最新版盲盒商城thinkphp+uniapp
The latest version of blind box mall thinkphp+uniapp
云计算未来 — 云原生
Use bloc to build a page instance of shutter
电压环对 PFC 系统性能影响分析
随机推荐
ImportError: No module named examples. tutorials. mnist
[ManageEngine] the role of IP address scanning
ORM use of node -serialize
Simple use and precautions of kotlin's array array and set list
阿里 & 蚂蚁自研 IDE
alright alright alright
1-1 token
Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
Openstack node address change
What is more elegant for flutter to log out and confirm again?
Export the entire Oracle Database
【综合题】【数据库原理】
Swift5.7 extend some to generic parameters
Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
电压环对 PFC 系统性能影响分析
Sword finger offer06 Print linked list from end to end
Ten workplace rules
剑指Offer04. 二维数组中的查找【中等】
How to convert a decimal number to binary in swift
初入职场,如何快速脱颖而出?