I. List of packing classes
Basic data types
Packing class
Byte
Byte
Short
Short
Int
Integer
Boolean
Boolean
Char
Character
Long
Long
Float
Float
Double
Double
1) in these eight cla
public class Basetypeclasstest {/** Common class* 1, the basic type of encapsulation class: In the Java language, eight basic types correspond to a wrapper class.** Byte ====>>> byte* Short ===>>> Short* int =====>>> Integer* Long
Java offers two different types: reference type (or package type, Warpper) and original type (or built-in type, Primitive). int is the raw data type of Java, and integer is the wrapper class provided by Java for Int. Jav
Original type wrapper class the number of bytes that the original type occupiesShort Short 2 bytesint Integer 4 bytesA long long 8 bytesFloat Float 4 bytesDouble Double 8 bytesByte byte 1 bytesChar Character 2 bytesBoolean Boolean This test-build environment depends onEight types of default valuesBase type default valueBYTE 0int 0Short 0Long 0LDouble 0.0dFloat 0.
Basic data type Object wrapper classAccording to the Java object-oriented principle, everything is an object, which includes the basic data types.BYTE byteShort ShortInteger intLong LongBoolean Booleanfloat floatDouble DoubleCharacter CharNext, take int as an example to explain:In the Java.lang package, the integer classThe integer class wraps a primitive type in
Why do I need a wrapper class?Java is not a purely object-oriented language. The Java language is an object-oriented language, but the basic data types in Java are not object-oriented. However, we often need to transform the basic data into objects in practical use, which is
For more operations on the basic data types, more convenient operation, Java provides the corresponding class type for each of the basic data types. Wrapper class Type:BYTE byteShort Shortint IntegerLong Longfloat floatDouble DoubleChar CharacterBoolean BooleanUsed for conversions between the base data type and the str
Java 1.3 introduces a new feature named "Dynamic Proxy Class", which can be used to dynamically create wrapper Classes for "implementations of known interfaces. Before the advent of version 1.3, when I first heard of the dynamic proxy class I was proposing, I thought it was just an eye-catching feature. Although it is
, when values from –128 to 127 are boxed into an integer object, they are reused in memory, so in the example, i3 and I4 actually refer to the same object.If the value from –128 to 127 is exceeded, the boxed integer object is not reused, which is equivalent to creating a new integer object each time it is boxed, so in the example, I1 and I2 refer to different objects.In addition, when the auto-boxing function is not used, as in the case of ordinary class
Java provides a total of eight basic data types, namely: Byte,short,int,long,float,double,boolean,char. Their corresponding packaging classes are in the Java.lang package, respectively, corresponding to: Byte,shortInteger,long,float,double,boolean,character.When you have to use objects or reference data types in some places (collection classes), the basic data types cannot be used because their storage principles and reference data types are completel
1. In different ways, the base type does not apply the new keyword, and the wrapper type needs to use the New keyword to allocate storage space in the heap;2. Different storage methods and locations, the basic type is to store the value of the variable directly on the stack, and the wrapper type is to put the object in the heap, and then by reference to use;3. Different initial values, the initial value of
1. The wrapper class object is immutable.2.==, when the wrapper class and the basic type use = = comparison, the packaging class will be automatically disassembled for the basic type and then compare3. Boolean,byte,char that is less than or equal to fixed-address
1, an overview of the integerRequirement 1: put 100 binary, octal, hexadecimal calculation of this dataRequirement 2: Determine whether a data is within the range of int.First you need to know how big the int is?In order to perform more operations on the basic data types and to operate more conveniently, Java provides the corresponding class type for each of the basic data types. The
the complex inheritance of the C + + developers have also brought greater trouble, in order to avoid the risk, Java only allow single inheritance, There can be only one parent class, but you can implement the same interface for multiple classes.Conversion is a relationship that must first be judged whether it is a parent, a subclass, and the parent-child class i
Packing class:Conversions between basic types and wrapper classesBoxing: The basic type is converted into a wrapper class, so that it has the nature of the object, but also can be divided into manual boxing and automatic boxing.int i=10;Integer x=new integer (i); Manual BoxingInteger y=i; Automatic BoxingUnpacking: In contrast to boxing, the
Question: Why do I need a wrapper class?The wrapper class value is the base data type, because the base data type cannot create the object and call the method, and the package wrapper class is available. For example, common data t
Instantiation of wrapper classesAll the packaging classes are immutable.Instantiation method:Construction methodIn addition to the character class, other packagesInteger (int x)Integer (String x)NumberFormatException exceptionThe parameters for the Boolean constructor method are not distinguishedUppercase and lowercaseTwo construction methods are provided for the
%linux_wrapper_home%/lib, the pre-packaged project Jar package is also placed here.9. Upload the%wrapper_home%/src/bin/sh.script.in file to the%linux_wrapper_home%/bin directory and rename it as (recommendation: the class name of the main method in the Java project). Open the file and modify two places:App_name= "Enter your project name"App_long_name= "Enter your project name".10, open the%linux_wrapper_hom
Topic:
integer i = 42 long l = 42l; double d = 42.0
The following is trueA. (i = = L)B. (i = = d)C. (L = = d)D.i.equals (d)E.d.equals (L)F.i.equals (L)G.l.equals (42L)Answer: Gparsing:Comparisons of the same type, such as Integer and Int,long, are automatically removed when compared with long = =, and are compared between different types, and if one is a non-wrapper class, the box is a
1, guess the number of small games Packagecn.jiemoxiaodi_02;ImportJava.util.Scanner;/*** Guess number games * *@authorHuli **/ Public classGuessnumberdemo { Public Static voidMain (string[] args) {intNumber = (int) (Math.random () * 100) + 1; while(true) {System.out.println ("Please enter the number you guessed:"); String Line=NewScanner (system.in). nextline (); intValue =Integer.parseint (line); if(Number >value) {System.out.println ("Your guess is small."); } if(Number = =value) {
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.