The difference between 1.this and super
This and super can only be used in non-static methods, not in static methods, such as Static,final
This: can only be used in a method body, equivalent to a pointer in C, to a member variable, this action in asubclass
Private String password; Public void First () { System.out.println ("This cannot appear in a static method");} Public void second () { this. First (); This . Password;}
Super: Invokes the constructor of the parent class, or is used internally by a non-static member of a class. e.g. Super.method ()
Must be written on the first line of the constructor
classFatherclass { Public intvalue; Public voidf () {value= 100; System.out.println ("Fatherclass value =" +value); }}classChildClassextendsfatherclass{ Public intvalue; Public voidf () {Super. f (); Value= 200; System.out.println ("Childclass.value=" +value); System.out.println (value); System.out.println (Super. Value); }}
The difference between int and integer in 2.java
(1). int is the underlying data type, and integer is a complex data type, and integer is a class
The int variable is initially 0,integer NULL when the class is initialized
(2). Initialize
int i = 1; Integer i = new integer (1);
(3). When adding data in ArrayList and HashMap, only integer is used,
and the generic definition does not support int: such as:list<integer> list = new arraylist<integer> (); Yes list<int> list = new arraylist< Int> ();
ArrayList al=New= 1; integer NI=new integer (n); Al.add (n) ; // can not Al.add (NI); // can be
int is simply used to perform some subtraction operations or to pass as parameters
An integer can be used for object manipulation
(4). Other functions are similar
Float float;double double;string String
Basic data types |
Packing class |
Byte |
Byte |
Boolean |
Boolean |
Short |
Short |
Char |
Character |
Int |
Integer |
Long |
Long |
Float |
Float |
Double |
Double |
(5). int and integer type conversions
The first type is:
//int goes to integerinti = 0; Integer Test=NewInteger (i);//Integer to intInteger Wrapperi =NewInteger (0); inti =Wrapperi.intvalue (); //due to the presence of autoboxing, it can be used directlyinti = 0; Integer Test=i; //valueof can also be type-converted and more efficient, there is a caching mechanism Public StaticInteger ValueOf (inti)inti = 0; Integer Test= Integer.valueof (i);
Java Basics (i)---this,super and integer