Special case: Java main type

Source: Internet
Author: User

There are a series of classes that need special treatment, and they can be imagined as "basic", "primary", or "primary" (primitive) types, which are frequently used in programming. Special treatment is due to the fact that creating objects with new (especially small, simple variables) is not very effective because new objects are placed in the heap.

For these types, Java has adopted the same approach as C and C + +. That is, instead of creating a variable with new, you create an "automatic" variable that is not a handle. This variable holds the specific value and is placed on the stack to be accessed more efficiently.


Java determines the size of each of the major types. As in most languages, these sizes do not change as the structure of the machine changes. This immutable size is one of the reasons why Java programs have a strong ability to migrate.

①: To Java 1.1 only, 1.0 version does not.

Numeric types are all signed (plus and minus), so you don't have to bother looking for a type that doesn't have a symbol.
The main data type also has its own "wrapper" (wrapper) class. This means that if you want a non-dominant object in the heap to represent that main type, you need to use the corresponding wrapper. For example:
char c = ' x ';
Character C = new Character (' C ');
You can also use it directly:
Character C = new Character (' X ');
The reasons for doing so will be explained in later chapters.

1. High-precision Digital
Java 1.1 adds two classes for High-precision computing: BigInteger and BigDecimal. Although they can be roughly divided into "wrapper" types, there is no corresponding "main type".
These two classes have their own special "methods" that correspond to the actions we perform against the main type. That is, things that can be done to int or float can do the same for BigInteger and BigDecimal. Only method calls must be used, and operators cannot be used. In addition, the speed of the operation is slower because of the more involved. We sacrificed speed, but in exchange for precision.
BigInteger supports integers of arbitrary precision. In other words, we can accurately represent an integer value of any size, while no information is lost during the operation.
BigDecimal supports fixed-point digits of arbitrary precision. For example, it can be used for accurate currency calculations.
Refer to the online Help documentation for the builder and method you can use to invoke these two classes.

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.