Java Object-oriented _ wrapper class access modifier

Source: Internet
Author: User

In Java, there is a design principle of "all objects," the basic data types in Java completely do not conform to this design idea, because eight basic data types are not reference data types, so in order to solve such problems in Java, jdk1.5 introduced eight kinds of basic data types of wrapper classes.

There are two main types of eight packaging categories :

Number:integer, short, Long, Double, Float, Byte are all subclasses of number that represent a digit.

Object:character, Boolean are the direct subclasses of object.

1  Public classTEST5 {2 3     /**4      * @paramargs5      */6      Public Static voidMain (string[] args) {7         //TODO auto-generated Method Stub8         intnum=10;9Integer num2=10;//Auto-Boxing, creating a new objectTen         intnum3=1+num2;//Automatic Unpacking One         //manually unpacking, calling the Intvalue method A Num2.intvalue (); -     } -  the}

Transformational operations

In a wrapper class, you can change a string to a specified base data type and generally use more when you enter data.

Convert string to int data in integer class: public static int parseint (Strings)

Changing a string into float type data in the Float class: public static float parsefloat (Strings)

Note: The string must consist of a number in a transition operation, or an error will occur

enjoy meta mode: it uses shared objects to minimize memory usage and to share information to as many similar objects as possible;

It is suitable for a large number of objects just to repeat thus resulting in the use of large amounts of memory that cannot be received. Usually some of the states in an object can be shared.

It is common practice to put them in an external data structure and pass them on to the element when it is needed.

Use shared technology to effectively support a large number of fine-grained objects

1  Public classTEST5 {2 3     /**4      * @paramargs5      */6      Public Static voidMain (string[] args) {7         //TODO auto-generated Method Stub8         //Transformational Operations9String s= "200";Ten Integer.parseint (s); One          A         //caches integers within a byte in an integer constant pool, which avoids the constant creation of fine-grained objects, resulting in memory consumption -Integer a=12; -Integer b=12; theSystem.out.println (a==b); -     } -  -}

OO principles:

1. Opening and closing principle: a software entity such as classes, modules, and functions should be open to extensions and closed for modification.

2. Synthesis/Aggregation multiplexing principle: Some functions of a new object have been implemented in a created object, so try to use the functionality provided by an existing object to make it part of the new object and not recreate it

3. Dependency inversion principle: The high-level module should not rely on the lower layer module, both should rely on its abstraction; abstraction should not depend on detail; detail should depend on abstraction

4. Interface Isolation principle: The client should not rely on the interface it does not need; the dependency of one class on another should be based on the smallest interface

5. Dimitri rule: One object should keep a minimum of knowledge of other objects

6. The Richter replacement principle: All references to base classes must be able to transparently use objects of their subclasses

7. Single principle of responsibility: do not have more than one cause of class changes, that is, a class is responsible for only one responsibility

Java Object-oriented _ wrapper class access modifier

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.