Why Java requires a basic type

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.