1. Packaging classes convert basic type data to Objects 1.1 Each base type has a corresponding wrapper class in the Java.lang package2. What is the role of the packaging class?2.1 provides a series of practical methods2.2 Collection is not allowed to hold basic data type data, when storing numbers, use the wrapper typ
Packing Class (wrapper class)
The wrapper class is a wrapper for the native data type.
Because there are 8 native data types, there should be 8 wrapper classes.
All packing classes (8)
Java numberGenerally, when you need to use numbers, we usually use built-in data types, such as: Byte, int, long, double, and so on.For example: int i = 5000; float gpa = 13.65; byte mask = 0xaf;
1
2
3
1
2
3
However, in the actual development process, we often encounter situations where objects need to be used rather than built-in data types. To solve this problem, the
Packing classEverything in Java is an object, so many operations are for objects, and Java will automatically wrap the usual data types into objects of the corresponding classes.Support for automatic package and unpacking after jdk1.5Wrapper classes for common data typesPackingBoxing is the object that changes the base data type to the corresponding class.listnew ArrayList();//list的各种操作都是针对对象的list.add(5);//
Recently createdXiao DingdongAnd automatically run after the machine is started.Xiao DingdongSo I want to convert the Java class into a service to run it like tomcat.So I foundJava service wrapper.Here are some of the places I want to use.
Change the Java class to the third method of the Windows NT Service (using
One, polymorphic1. Polymorphism exists in inheritance and interfaces.2. The indeterminate behavior is placed in the parent class.3. Subclasses must override the indeterminate behavior in the parent class.Second, abstract class1. Keyword abstract.Example: Public abstract class shap{public abstract void View ();}2. An indeterminate behavior method is placed in an abstract
Introduction to basic types of packaging classesIn general, we often use meta-types in our programs, such asint data = 1;float data = 2.1F;However, in some scenarios it is not possible to use meta-types directly, such as if we want to create an int type of ArrayList, you cannot write directly:ArraylistBecause the type requirement in the ArrayList "So Java in order to solve this problem, put forward the packaging c
First, the basic type of JavaThe Java language provides eight basic types, including six numeric types (four integers, two floating-point types), one character type, and one Boolean type.
Integer type, including Byte, short, int, long, the default initial value is 0;
Floating point type, including float, double, default initial value is 0.0;
character type, char type, The default value is ", note the difference from" "," is the quotat
Basic type wrapper classThere are 8 basic data types in Java, but this data is basic data, it is difficult to do complex operation. What do we do?In the actual program use, the user input data on the program interface is stored as a string type. In the program development, we need to convert the string data to the specified basic data type according to the requirement, such as the age needs to be converted
Packing class
Java is an object-oriented programming language, and the appearance of wrapper classes is a better embodiment of this idea.
Second, the wrapper class as a class is a property has a method, the function i
("+"); float Floatvalue=new float ("21");Boolean booleanvalues=new Boolean ("true");Incoming strings conform to basic type requirementsSuch as: The following incorrect wordingFloat floatvalue=new Float ("abc");2.3. The Third Kindpublic static type ValueOf (type value)Short Shorvalue=short.valuesof ((short)); Integer intvalue=integer.valuesof (+); Character charvalue=character.valueof (' x '); Boolean booleanvalue=boolean.valueof (true);public static Type ValueOf (String s)Byte bytevalue=byte.va
The Java language is an object-oriented language, but the basic data types in Java are not object-oriented, which in the actual use of a lot of inconvenience, in order to solve this shortcoming, in the design of the class for each basic data type to design a corresponding class to represent, The classes that correspond
In order for the basic data type to have the properties of the object, Java provides a wrapper class for each of the basic data types, so that we can manipulate the basic data type like an object, and the wrapper class is in the Java.lang package.Correspondence between the b
Wrapper class, Math, date format processing
Packing class
Math:random (), round ()
Date format processing
Java advocates that thought is everything, but our basic data type is not a class, that is, there is no object concept, and
http://blog.163.com/bt_q/blog/static/11926672920104902636829/The Java language is an object-oriented language, but the basic data types in Java are not object-oriented, which in the actual use of a lot of inconvenience, in order to solve this shortcoming, in the design of the class for each basic data type to design a corresponding
Because you know that the objects in the collection are object types when you learn the collection, you need to force the type conversion to the target type when you remove it (not necessary to use a generic collection), such as int a = (Integer) arraylist.get (0); and then we'll find out, Why cast to Integer instead of int? What is the difference between an int and an integer?
1. Difference between basic type and packing class
int is the basic type,
Packaging (Wrapper Class) Wrapper classes are wrappers for native data types.Because there are 8 native data types, there should be 8 wrapper classes.All packaging Classes (8) are located under Java.lang.The 8 wrapper classes in Java
I. OverviewThere are 8 data types in Java, namely byte short int long boolean float double char, corresponding to this, there are 8 classes corresponding to each:BYTE byteShort Shortint IntegerLong LongBoolean Booleanfloat floatDouble DoubleChar CharacterWhat are the benefits of encapsulating a basic data type as an object?The basic data type wrapper class encaps
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.