Plastic surgery:
Bytes 1 byte
Short 2 bytes
Int 4 bytes
8 bytes long
Characters:
Character 2 bytes
Floating point number:
Floating-point 4 bytes
Double 8 bytes
Boolean type:
Boolean 1 byte
2.java 7 adds binary integers.
Start with 0B or 0b.
Coding method of 16-bit Unicode for Chinese characters in 3.java. The format is' \ uxxxxx', where xxxx represents a hexadecimal integer.
Positive infinity, negative infinity and zero are specified in 4.java.
Positive infinity = positive number divided by 0.
Negative infinity = negative number divided by zero.
Divide 0.0 by 0.0 or root a negative number to get a non-number.
5. Boolean types can only be true and false in java.
There are no multidimensional arrays in 6.java.
It seems that multidimensional arrays in C language are not real arrays, such as a[3][4], a[0] a[ 1] a[2] are real and contain addresses, just like dynamically allocated arrays in C language.
int [][] b = new int[3][4]
Package compilation method in 7.Java
Hello.java will generate a directory tree under the current directory.
The name of the running java package. Category name
The field of an object in 8.Java polymorphism is not polymorphic, such as parent class object = new subclass (), and the object. The field belongs to the called parent class, even if the subclass overrides the field.
9. Examples of operators
Format: refers to the variable name instanceof of the class name (or interface). Classes, subclasses and instances used to judge whether the previous object is the implementation class of the latter object. If true, it returns false.
Conversion between basic data types and corresponding encapsulation classes in10.java.
int a = 1;
Integer A = new integer (a);
a = a . int value();
So are other types.
1 1. singleton class example
The copy code code is as follows:
Quasi-simplex
{
Private static single instance;
Private Singleton(){}
Public static singleton getInstance ()
{
if(instance == null)
{
instance = new Singleton();
}
Returns an instance;
}
Public static void main(String[] args)
{
singleton s 1 = singleton . getinstance();
singleton S2 = singleton . getinstance();
system . out . println(s 1 = = S2);
}
}
Initialization of member variables decorated by 12.final
Class field: The initial value must be specified in the static initialization block or when the field is declared.
Instance field: You must specify an initial value, or declare it in the constructor in the non-static initial block, or declare it when you declare the field.
13. The final variable must be initialized explicitly, and the system will not initialize the final variable implicitly.
14.java will use the constant pool to manage the used string direct constants, for example: String a = "java system stores the constant string" java "in the constant pool. When String b = "java "is executed again; A == b is true.
15.final method cannot be overridden, and final class cannot inherit.
If the private method is the same as final private.
If it appears in a subclass through the method of final decoration, it is newly defined by the subclass and has nothing to do with the parent class.
16. immutable class: the fields of this class are immutable after creation. Java provides eight basic variable wrapper classes, and string is an immutable class.
17. immutable classes of cached instances
The copy code code is as follows:
Category cache memory
{
private static int MAX _ SIZE = 10;
Private static cache immutable [] cache = new cache immutable [max _ size];
private static int pos = 0;
Private final string name;
Private CacheImmutale (string name)
{
This. Name = name;
}
Public string getName ()
{
Returns the name;
}
Unique value Of public static cache of (string name)
{
for(int I = 0; I & ltMAX _ SIZE++i)
{
if(cache[i]! = null & amp& amp cache [i]. getName()。 Equal to (name))
Back to the cache [i];
}
if(pos == MAX_SIZE)
{
Cache[0] = new cache immutable (name);
pos = 1;
}
other
{
cache[pos++]= new cache immutable(name);
}
Back to the cache [pos-1];
}
Common Boolean equals (object object)
{
If (this == obj)
Return true
if(obj! = null & amp& ampobj . getclass()= = cache immutable . class)
{
cacheimmutable ci =(cacheimmutable)obj;
return name . equals(ci . getname());
}
Returns false
}
public int hashCode()
{
Returns name. hashcode ();
}
}
Common class CacheImmuteTest
{
Public static void main(String[] args)
{
cacheimmutable c 1 = cacheimmutable . value of(" Hello ");
cacheimmutable C2 = cacheimmutable . value of(" Hello ");
system . out . println(c 1 = = C2);
}
}
Using cached instances depends on the frequency of the object. If it is reused, the advantages outweigh the disadvantages. If you don't use it often, it will do more harm than good.
In addition, java.lang.Integer provided by java uses the caching mechanism to create numbers with values between-128- 127.
integer in2 = integer . value of(6);
integer in3 = integer . value of(6);
In2 == in3 is true;
18. Static and abstract cannot decorate a method at the same time, and there is no class abstract method.
19. A class can be another parent class and can implement multiple interfaces. The fields in the interface are public, static and final, and the methods are public abstractions.
20. When the method of non-static inner class accesses variables, the search order is: first in the method of inner class->; Internal class->; If none of them can be found in the external class, a compilation error will occur.
The copy code code is as follows:
Import java.util. *;
Common class variable
{
Private string prop = "instance variable of external class";
Private classroom
{
Private string prop = "instance variable of inner class";
Public invalid information ()
{
String prop = "local variable";
System.out.println ("field value of external class:"+discriminalvariable.this.prop);
System.out.println ("field value of internal class:"+this.prop);
System.out.println ("value of local variable:"+prop);
}
}
Public Invalid Test ()
{
in class in = new in class();
in . info();
}
Public static void main(String[] args)
{
New recognizable variable (). test();
}
}
2 1. Non-static inner classes cannot have static methods, static fields and static initialization blocks.
22. Access the inner class outside the outer class.
Access the non-static inner class: outclass. incolassvarname = newoutclass()。 new in class();
Access the static inner class: outclass. inclassvarname = newoutclass。 inclass();
The copy code code is as follows:
Import java.util. *;
dismiss a class
{
Have a class at ...
{
Public in ()
{
System.out.println ("non-static inner class constructor");
}
}
}
Public class creation instance
{
Public static void main(String[] args)
{
Get out. In in = new Out()。 New features in ();
/*
The above code can be written separately:
Get out. In;
Out Out = new Out();
In = out . new In();
*/
}
}
Class subclasses extend outward. In ...
{
//Displays the constructor that defines the subclass.
Public subclass (out)
{
//Display the transferred-in constructor through the transferred-out object.
out . super();
}
}
The copy code code is as follows:
Import java.util. *;
Class static output
{
Static class static
{
Public Static ()
{
System.out.println ("static inner class constructor");
}
}
}
Public class CreatStaticInnerInstance
{
Public static void main(String[] args)
{
Static output. Static input = new static output. static in();
/*
The above code can be written separately:
Static output. Static input;
In = new StaticOut. static in();
*/
}
}
Class subclass extends StaticOut. static
{
//There is no need to create an inner class instance.
}