In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what are the differences between int and Integer in java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Recently interviewed a lot of candidates, found that many people do not pay much attention to the basics, even more than ten years of work, more than ten pages of project experience of the old programmer, learned a lot of framework, but a lot of Java-related basic knowledge is unable to answer. Many people will answer that they only know how to use it, but never look at how it is implemented.
We all know that as qualified programmers, poor basic skills will lead to many weird problems in your program that are difficult for you to diagnose, such as excessive overhead (frequent GC causes program stutters or OOM), and the weird scene generated by the Integer cache mechanism (described in more detail below), so we want to write an article about the interview series and summarize the common and easy interview questions. Today, from the interviewer's point of view, I would like to talk to you about some of the basic questions of the interview and guide you as much as possible on how to give a satisfactory answer to the interviewer.
Basic answer
Int is one of the eight basic data types (boolean, byte, short, char, int, float, double, long). It occupies 4 bytes and takes up a range of 32 (4 * 8) powers of plus or minus 2. Although Java claims that everything is an object, the basic data type is an exception.
Integr is the wrapper class of int, which is introduced in JDK 1.5. it provides practical functions such as string conversion, mathematical operation, generics, automatic unpacking and so on, which greatly simplifies the difficulty of programming.
Talk about the value cache range of Intger
The following is a typical example, which is also a pit that many people have stepped on. The procedure is as follows (it is recommended that you practice on the machine)
Integer A1 = 127, b1 = 127 false Integer a2 = 128, b2 = 128 × System.out.println (A1 = = b1); / / trueSystem.out.println (a2 = = b2); / / reasons for the wrapper class caching mechanism
You can think about why the above strange situation occurred, and then we can take a look at the source code of Integer.valueOf.
/ / Integer.valueOf source code public static Integer valueOf (int I) {if (I > = IntegerCache.low & & I)
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.