The basic data type of Java and the relationship of the wrapper class

Source: Internet
Author: User
Tags constructor integer wrapper

Java is an object-oriented language where classes in Java Connect methods to data and form self-contained processing units. However, you cannot define the base type (primitive type) in Java, and you can connect the related methods to treat the base type as an object. Java provides wrapper classes for each of the basic types so that we can convert these basic types to objects. These packaging categories are: Boolean,byte,short,character,integer,long,float,void and so on.

It is worth noting that Java can handle basic types directly, but in some cases we need to treat them as objects, and then we need to convert them into wrapper classes. All packaging classes (wrapper class) have a common approach, they are:

(1) A constructor that has a basic value parameter and creates a wrapper class object. If you can use the integer wrapper class to create the object, the integer obj=new integer (145);

(2) A constructor that has a string parameter and creates a wrapper class object. such as new Integer ("-45.36");

(3) A toString () method that generates a string representation, such as obj.tostring ().

(4) The Equals () method for comparing two objects of the same class, such as Obj1.eauqls (OBJ2);

(5) The Hashcode method of generating the HA dilute table code, such as Obj.hascode ();

(6) A Parsetype method that converts a string to a basic value, such as Integer.parseint (Args[0));

(7) A Typevalue method for generating the basic value of an object, such as Obj.intvalue ();

In certain occasions, the use of Java packaging classes to solve problems, can greatly improve the programming efficiency.

Related Article

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.