In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "What is the difference between int and Integer in Java". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "What is the difference between int and Integer in Java"!
Java is a strongly typed language, so all attributes must have a data type. Just like Metro, you need a membership card to go shopping.
PS: Java 10 has local variable type derivation, you can use var to replace a specific data type, but in the bytecode stage, Java variables still have a clear data type, and local variable type derivation has many limitations and imperfections, and it is not the current mainstream application version, so it is not discussed in depth here.
To understand the difference between int and Integer, start with Java's basic data types.
1. Basic data types
In Java, there are eight primitive types: four integers, two floating-point types, one char for Unicode encoding, and one boolean for true and false values.
4 types of integers: int, short, long, byte
2 types of floating point: float, double
Character type: char
True or false type: boolean
Basic data types refer to atomic data types that cannot be subdivided. Values of this type are stored directly in memory. Data can be accessed directly through memory addresses, and this memory area can only store values of this type. int is a commonly used basic data type in Java.
2. Packaging and its role
Because Java is designed so that everything is an object, there are many cases where you need to operate as an object, such as hashCode() to get a hash value, or getClass() to get a class.
2.1 The role of packaging
In Java, each basic data type corresponds to a wrapper class, and the wrapper class corresponding to int is Integer. The existence of wrapper classes solves the problems that basic data types cannot do, such as generic type parameters, serialization, type conversion, and high-frequency interval data caching.
Base Type Wrapper Type Integer ShortByteLongFloatDoubleDoubleBlecharCharacteristbooleanBoolean 3, int and Integer Difference
The difference between int and Integer is mainly reflected in the following aspects:
The data types are different: int is the base data type, and Integer is the wrapper data type;
Default values are different: int defaults to 0, while Integer defaults to null;
The way to store in memory is different: int directly stores data values in memory, while Integer actually stores object references. When new an Integer, it actually generates a pointer to this object.
Instantiation is different: Integer must be instantiated to be used, int does not;
Variables are compared differently: int can use == to compare two variables for equality, while Integer must use equals to compare two variables for equality.
Thank you for reading, the above is "Java int and Integer difference is what" the content, after the study of this article, I believe we have a deeper understanding of Java int and Integer difference is what this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.