inotgo.com

This video is interpretive , So I hope you have read the content of this knowledge point , And after writing the corresponding code , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning



5 branch 3 second
This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers



Step 1 : Encapsulation class   
Step 2 : Number class   
Step 3 : Basic type to encapsulation class   
Step 4 : Encapsulation class to basic type   
Step 5 : Automatic packing   
Step 6 : Automatic unpacking   
Step 7 : int Maximum value of , Min   
Step 8 : practice - Packing and unpacking   
Step 9 : answer - Packing and unpacking   

be-all Basic types , There are corresponding Class type
For example int The corresponding class is Integer
This kind of class is called encapsulation class
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; // Put a basic type of variable , Convert to Integer Object Integer it = new Integer(i); // Put one Integer Object , Convert to a basic type int int i2 = it.intValue(); } }
package digit;

public class TestNumber {

	public static void main(String[] args) {
		int i = 5;
		
		// Put a basic type of variable , Convert to Integer Object  
		Integer it = new Integer(i);
		// Put one Integer Object , Convert to a basic type int
		int i2 = it.intValue();
		
	}
}
Digital encapsulation classes include
Byte,Short,Integer,Long,Float,Double
These classes are abstract classes Number Subclasses of
Number class
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; Integer it = new Integer(i); //Integer yes Number Subclasses of , So print true System.out.println(it instanceof Number); } }
package digit;

public class TestNumber {

	public static void main(String[] args) {
		int i = 5;
		
		Integer it = new Integer(i);
		//Integer yes Number Subclasses of , So print true
		System.out.println(it instanceof Number);
	}
}
Step 3 :

Basic type to encapsulation class

edit top fracture
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; // Convert base type to encapsulation type Integer it = new Integer(i); } }
package digit;

public class TestNumber {

	public static void main(String[] args) {
		int i = 5;

		// Convert base type to encapsulation type 
		Integer it = new Integer(i);
		
	}
}
Step 4 :

Encapsulation class to basic type

edit top fracture
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; // Convert base type to encapsulation type Integer it = new Integer(i); // Convert encapsulation type to base type int i2 = it.intValue(); } }
package digit;

public class TestNumber {

	public static void main(String[] args) {
		int i = 5;

		// Convert base type to encapsulation type 
		Integer it = new Integer(i);
		
		// Convert encapsulation type to base type 
		int i2 = it.intValue();
		
	}
}
There is no need to call the constructor , Through = Symbol automatic hold Basic types Convert to Class type It's called packing
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; // Convert base type to encapsulation type Integer it = new Integer(i); // Automatic conversion is called packing Integer it2 = i; } }
package digit;

public class TestNumber {

	public static void main(String[] args) {
		int i = 5;

		// Convert base type to encapsulation type 
		Integer it = new Integer(i);
		
		// Automatic conversion is called packing 
		Integer it2 = i;
		
	}
}
There is no need to call Integer of intValue method , Through = It is automatically converted to int type , It's called unpacking
package digit; public class TestNumber { public static void main(String[] args) { int i = 5; Integer it = new Integer(i); // Convert encapsulation type to base type int i2 = it.intValue(); // Automatic conversion is called unpacking int i3 = it; } }
package digit;
 
public class TestNumber {
 
    public static void main(String[] args) {
        int i = 5;
 
        Integer it = new Integer(i);
         
        // Convert encapsulation type to base type 
        int i2 = it.intValue();
        
        // Automatic conversion is called unpacking 
        int i3 = it;
         
    }
}
int The maximum value of can be through its corresponding encapsulation class Integer.MAX_VALUE obtain
package digit; public class TestNumber { public static void main(String[] args) { //int Maximum value of System.out.println(Integer.MAX_VALUE); //int Minimum value of System.out.println(Integer.MIN_VALUE); } }
package digit;
 
public class TestNumber {
 
    public static void main(String[] args) {

    	//int Maximum value of  
    	System.out.println(Integer.MAX_VALUE);
    	//int Minimum value of     	
    	System.out.println(Integer.MIN_VALUE);
         
    }
}
Step 8 :

practice - Packing and unpacking

edit top fracture   Wrong posture , get half the results with double the effort ! Click to see the correct posture for the exercise
1. yes byte,short,float,double Carry out automatic unpacking and automatic packing

2. byte and Integer Whether automatic unpacking and automatic packing can be carried out between

3. Through Byte obtain byte Maximum value of
Step 9 :

answer - Packing and unpacking

edit top fracture
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Before looking at the answers , Try to finish it yourself first , See the answer when you encounter a problem , The harvest will be more
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Viewing this answer will cost 3 Points , You currently have a total of Point integral . It doesn't cost extra points to see the same answer . Points increase method Or One time purchase JAVA Base total 0 One answer ( Total required 0 Integral )
Account not activated Account not activated , Limited functionality . Please click activate
This video is interpretive , So I hope you have read the content of this answer , Watch with questions , Only in this way can we gain more . It is not recommended to watch the video at the beginning

2 branch 11 second This video uses html5 Play mode , If it cannot be played normally , Please upgrade your browser to the latest version , Recommend Firefox ,chrome,360 browser . If thunderbolt is installed , Play the video and show the direct download status , Please adjust Thunderbolt system settings - Basic settings - Start - Monitor all browsers ( Remove this option ). chrome of Video download Plug-in will affect playback , as IDM etc. , Please close or switch other browsers


package digit; public class TestNumber { public static void main(String[] args) { // 1. yes byte,short,float,double Carry out automatic unpacking and automatic packing byte b = 1; short s = 2; float f = 3.14f; double d = 6.18; // Automatic packing Byte b1 = b; Short s1 = s; Float f1 = f; Double d1 = d; // Automatic unpacking b = b1; s = s1; f = f1; d = d1; // 2. byte and Integer Whether automatic unpacking and automatic packing can be carried out between Integer i1 = b; // You can't put byte Direct automatic packing into Integer b = new Integer(1); // You can't put Integer Automatic unpacking into byte // 3. Through Byte obtain byte Maximum value of System.out.println(Byte.MAX_VALUE); } }


The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .


Q & A area    
2021-07-12 2021-7-12-AM-10-00
Daydream home




2021-7-12-AM-10-00
import java.lang.*;
public class TestNumber {
   byte a = 12;
   Byte a1 = new Byte(a);
   Byte a2 = a;
   byte a3 = a1.byteValue();
   byte a4 = a2;

   short b = 21;
   Short b1 = new Short(b);
   Short b2 = b;
   short b3 = b1.shortValue();
   short b4 = b2;

   float c = 6.33f;
   Float c1 = new Float(c);
   Float c2 = c;
   float c3 = c1.floatValue();
   float c4 = c2;

   double d = 5.33;
   Double d1 = new Double(d);
   Double d2 = d;
   double d3 = d1.doubleValue();
   double d4 = d2;

   byte aa = 123;
   // You can put the small one to the big one 
   Integer aa1 = new Integer(aa);
   byte aa2 = aa1.byteValue();
   int bb = 1234;
   // You can't put the big one to the small 
//   Byte bb1 = new Byte(bb);

    Byte aa3 = aa;

    public static void main(String[] args) {
        System.out.println(Byte.MAX_VALUE);
    }
}
 
               


1 One answer

Ayuaa
Answer time :2021-08-13
package Basis.practice9.Study1; /*1. yes byte,short,float,double Carry out automatic unpacking and automatic packing *2. byte and Integer Whether automatic unpacking and automatic packing can be carried out between *3. Through Byte obtain byte Maximum value of */ public class Mycode { public static void main(String[] args) { System.out.println("byte max = "+Byte.MAX_VALUE);//byte max = 127,min = -128 System.out.println("short max = "+Short.MAX_VALUE);//byte max = 32767,min = -32768 byte b0 = 1; var B0 = new Byte(b0); byte b1 = B0;// Automatic unpacking Byte B2 = b0;// Automatic packing short s0 = 1; var S0 = new Short(s0); short s1 = S0; short S1 = s0; int i0 = 1; var I0 = new Integer(i0); int i1 = I0; Integer I1 = i0; // Integer I2 = b1; // You can't } }



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-05-05 Numbers and strings - Packing and unpacking - practice
Mono




1. yes byte,short,float,double Carry out automatic unpacking and automatic packing 2.byte and Integer Whether automatic unpacking and automatic packing can be carried out between 3. Through Byte obtain byte Maximum value of
 yes byte,short,float,double Carry out automatic unpacking and automatic packing 
package digit;
  
public class TestNumber {
  
    public static void main(String[] args) {
 		byte i = 5;  //short,float,double With int Same type , Pro test is effective 
		
		// Convert base type to encapsulation type 
		// There is no need to call the constructor , Through = The symbol automatically puts   Basic types   Convert to   Class type   It's called packing 
		Byte i2 = new Byte(i);
		// Automatic packing 
		Byte i1 = i;

		// Automatic unpacking 
		// There is no need to call Integer of intValue method , Through = It is automatically converted to int type , It's called unpacking 
		//byte i4 = i2.byteValue();
		Byte it3 = i2; 
 
    }
}

byte and Integer Whether automatic unpacking and automatic packing can be carried out between 
package digit;
  
public class TestNumber {
  
    public static void main(String[] args) {
 		byte i = 5;  
		
		// use byte The type is encapsulated into Integer Type is feasible , Packing and unpacking are feasible 
		// Convert base type to encapsulation type 
		// There is no need to call the constructor , Through = The symbol automatically puts   Basic types   Convert to   Class type   It's called packing 
		int i2 = new Integer(i);
		// Automatic packing 
		int i1 = i;

		// Automatic unpacking 
		// There is no need to call Integer of intValue method , Through = It is automatically converted to int type , It's called unpacking 
		//byte i4 = i2.byteValue();
		int it3 = i2; 		 
    }
}

 Another paragraph 
package digit;
  
public class TestNumber {
  
    public static void main(String[] args) {
 		int i = 5;  
		
		// use int The type is encapsulated into Byte Type is not feasible , Encoding validation has been performed 
		// Convert base type to encapsulation type 
		// There is no need to call the constructor , Through = The symbol automatically puts   Basic types   Convert to   Class type   It's called packing 
		Byte i2 = new Byte(i);
		// Automatic packing 
		Byte i1 = i;

		// Automatic unpacking 
		// There is no need to call Integer of intValue method , Through = It is automatically converted to int type , It's called unpacking 
		//byte i4 = i2.byteValue();
		Byte it3 = i2; 		 
    }
}

 Through Byte obtain byte Maximum value of 
package digit;
  
public class TestNumber {
  
    public static void main(String[] args) {
 
        //byte Maximum value of 
        System.out.println(Byte.MAX_VALUE);
          
    }
}

public class TestNumber {
  
    public static void main(String[] args) {
 		int i = 5;  
		
		// use int The type is encapsulated into Byte Type is not feasible , Encoding validation has been performed 
		// Convert base type to encapsulation type 
		// There is no need to call the constructor , Through = The symbol automatically puts   Basic types   Convert to   Class type   It's called packing 
		Byte i2 = new Byte(i);     // Constructor Byte(int) Type undefined 
		// Automatic packing 
		Byte i1 = i;  // Type mismatch , Not from int Convert to byte

		// Automatic unpacking 
		// There is no need to call Integer of intValue method , Through = It is automatically converted to int type , It's called unpacking 
		//byte i4 = i2.byteValue();
		Byte it3 = i2; 		 
    }
}


3 One answer

szy000178519
Answer time :2021-10-15
zlllll
Answer time :2021-07-04
XYyXxx
Answer time :2021-05-10
byte and Integer No packing is allowed between



The answer has been submitted successfully , Auditing . Please My answer Check the answer record at , thank you
answer Or code please Fill in at least one , If you have a problem , Please ask again , Otherwise, the webmaster may not see





2021-03-08 What are the application aspects of packing and unpacking
2020-12-17 Is this ellipsis
2020-11-21 Excuse me, boss , I typed it according to the code , Why can't it be implemented ?


Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 24 Previous questions , please Click to view

Please... Before asking questions land
The question has been submitted successfully , Auditing . Please My question Check the question record at , thank you
about JAVA Basics - Numbers and strings - Packing and unpacking Your questions

Try to provide Screenshot code and Abnormal information , Help to analyze and solve problems . You can also enter this station QQ Group communication : 496725845
Ask questions and try to provide complete code , Environment description , The more conducive to the recurrence of the problem , The faster your question can be answered .
Have questions about the code in the tutorial , Please provide which step , Which line is in doubt , This makes it easy to quickly locate the problem , Improve the speed at which questions are answered
In the thousands of questions that already exist , A considerable proportion , Because of the use of and webmaster Different versions of the development environment Resulting in , For example jdk, eclpise, idea, mysql,tomcat Wait, the version of the software is inconsistent .
Please use the same version as the webmaster , You can save yourself a lot of learning time . The webmaster sorted out the software versions used in teaching , It's all here , Convenient for everyone to download : /k/helloworld/helloworld-version/1718.html

Upload screenshot