Questions
Let's start by throwing a question: Why does Java need a basic type?
The scene at the beginning of the problem did not remember, but a look at the problem: Java is object-oriented, claiming that everything is an object, and why there are basic types.
First come to the conclusion
For performance + inertia
Resolution process
First understand the Java data composition: Java Basic data type has eight kinds of
The simple point is that the base data type + the reference data type.
Next, why do you want the basic data type?
Because of this, the performance of the pursuit.
So, why is the stack faster than the heap? In fact, this is a game, to flexibility (heap, dynamic allocation of memory space), it is necessary to abandon the speed, to speed (stack, speed, strict restrictions in and out of the way), it is necessary to sacrifice flexibility.
See here: What is the difference between stacks and heaps? Why is the stack speed fast and the heap slow?
But Java has been developing for so many years, so it is not a matter of time to think about this speed difference.
Check carefully, found that the first appearance of this thing, has been used down Bai, so that object-oriented code, there is a trace of the silk discord.
Finally, the boxed and basic types:
-
The base type has a corresponding boxing type, but when declaring it, the statement determines whether it is an object:
int a = 0; // 基本类型Integer b = 1; //自动装箱Integer c = new Integer(3); // 对象声明
-
Can be automatically boxed does not mean that the basic type, such as
String str = "str";
Why Java requires a basic type