Basic data types in Java and their encapsulation classes

Source: Internet
Author: User

There are two types of data in Java, basic data types and reference data types, and the creation of reference data types is

You need to go to the new object, where the memory of the object is allocated to the heap, and the stack saves a reference to that object.

But for some simple data creation, the new approach is not very effective, so the JVM defines a set of basic

A description of the data type that stores the value directly into the stack without creating an object in the heap.

Java needs to determine the size of each of the basic data types, and the size of the space they occupy is fixed

, which is one reason Java has a high portability, the following is the 9 basic data types defined in Java and their encapsulation classes:

Because the basic data types are non-object-oriented, Java provides encapsulation classes for basic types, allowing us to manipulate the basic data types in an object-oriented manner.

These classes also encapsulate a number of practical methods that we can use.

At this point, some small partners will find void is also the original data type?? and the encapsulation class void?? Let's look at the code for the Void class:

Package java.lang;/** * This passage means that the void class is a placeholder class that cannot be instantiated, and it holds a reference to the class object that identifies the Java keyword void.  * the {@code  Void} class is an uninstantiable placeholder  class to hold a * reference to the {@code  class} object  representing the Java keyword * void. * *  @author    unascribed *  @since    JDK1.1 */public finalclass Void {     /**     *     * the {@code   class} object representing the pseudo-type corresponding to      * the keyword {@code  void}.     * This code can be interpreted as returning the encapsulated class void of the void base data type, which appears in the source code of the other wrapper classes      * and the Getprimitiveclass () method is native, Can not be implemented in Java, for the moment so understand      */   &Nbsp;public static final class<void> type = class.getprimitiveclass ("Void" );     /*     * the void class cannot be  instantiated.     */    private void ()  {}}

It is therefore understandable that the void class may itself have no effect but is itself a placeholder class. That is, the void class itself is just a placeholder class and cannot be

instantiated, used in generics as placeholders. For the basic data type void, it should mean ' nothing ', such as a return value, which means no return value ...

Should be able to understand that


Basic data types in Java and their encapsulation 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.