Detailed explanation of java basic data types and encapsulation types (difference between int and integer)

Int is one of the eight primitive data types provided by Java.

Java provides encapsulated classes for each primitive type, Integer is an encapsulated class provided by Java for int (that is, integer is a Java object, while int is just a basic data type). The default value of int is 0, while the default value of integer is null, that is, integer can distinguish the difference between unassigned and 0, while int cannot express unassigned. For example, to express the difference between not taking the exam and an exam score of 0, you can only use integer. In JSP development, integer The default value of GER is null, so when El expression is used to display in the text box, the value is a blank string, while the default value of int is 0. Therefore, when El expression is used to display in the text box, the result is 0. Therefore, int is not suitable for the type of form data in the web layer.

In Hibernate, if oid is defined as integer type, hibernate can judge whether an object is temporary according to whether its value is null. If oid is defined as int type, its unsaved value attribute needs to be set to 0 in the HBM mapping file.

In addition, integer provides several integer related operation methods, such as converting a string into an integer. Integer also defines constants representing the maximum and minimum values of integers.

Int is the basic type.

Integer is a reference type..

For example, int a = 5; Integer b = 5

For a, you can only use it for calculation.. Such as addition, subtraction, multiplication and division..

B you can do a lot of things because it is an object. It has many methods. You can use it like a string object. java. Lang. integer is a class Its operation is through the method of the class

Int is one of the 8 basic data types in Java by default Is not an object of class

Int is the basic data type, and integer is a class that encapsulates int.

Variables declared as int do not need to be instantiated, and variables declared as interger need to be instantiated (because classes need to be instantiated)

Int is the basic type, and integer is the wrapper class, that is, the class.

Integer is a more advanced data type than int. why do you use int in Java instead of integer in VB

Int is a numerical type facing the bottom of the machine and a data type of primitive type, while integer is the warpper class of int, which is an object-oriented object type, that is, OOP. Int is generally only used in numerical calculation, while integer is used in other places of Java where objects are to be used, such as key and value of map, element of list and set. If you want to save numerical information, you should wrap int as an integer object.

Java provides two different types: reference type and primitive type (or built-in type). Int is the primitive data type of Java, and integer is the encapsulated class provided by Java for int. Java provides encapsulated classes for each primitive type.

Primitive type encapsulation class Boolean Boolean char character byte byte short int integer long long float float double double

Reference types and primitive types behave completely differently, and they have different semantics. Reference type and primitive type have different characteristics and usages. They include: size and speed, which type of data structure this type is stored in, and the default value specified when reference type and primitive type are used as instance data of a class. The default value of object reference instance variables is null, while the default value of original type instance variables is related to their types.

Int is generally enough as a numeric parameter

Integer is generally used for type conversion

The above is a detailed explanation of java basic data types and encapsulation types (the difference between int and integer) introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message. Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>