1. Basic data types
Plastic:
Byte 1 bytes
Short 2 bytes
int 4 bytes
Long 8 bytes
Character:
Char 2 bytes
Floating point numbers:
Float 4 bytes
Double 8 bytes
Boolean:
Boolean 1 bytes
2.java 7 new binary integers
Start with 0b or 0B
3.java character characters 16-bit Unicode encoding, the format is ' \uxxxx ', where xxxx represents a hexadecimal integer
The 4.java stipulates positive infinity, negative infinity and zero.
Positive infinity = A positive number divided by 0
Negative infinity = A negative number divided by 0
0.0 divided by 0.0 or a nonnegative number.
5. Boolean types can only be true and false in Java
6. There are no multidimensional arrays in Java
Seemingly multi-dimensional arrays like C are not real arrays, such as a[3][4], a[0] a[1] a[2 are real, loaded with addresses, and are dynamically allocated in the C language.
int [[] b = new Int[3][4]
7. Java in the package with the compiler method
Javac-d. Hello.java will build the directory tree in the current directory
Run Java package name. Class Name
8. The filed of objects in Java polymorphism is not polymorphic, such as the parent object = new Subclass (), object. field is the parent class that is invoked, even if the field is overridden in a subclass.
9. instanceof operator
Format: Referencing variable name instanceof class name (or interface) he used to determine whether the preceding object was the class of the subsequent object, subclasses, instances of the implementation class, returned true, and no returns false
Transformation between basic data types and corresponding encapsulation classes in Java
int a = 1;
Integer A = new Integer (a);
A = A.intvalue ();
The same is true of other types.
11. Examples of single cases (singleton)
Copy Code code as follows:
Class Singleton
{
private static Singleton instance;
Private Singleton () {}
public static Singleton getinstance ()
{
if (instance = null)
{
Instance = new Singleton ();
}
return instance;
}
public static void Main (string[] args)
{
Singleton S1 = singleton.getinstance ();
Singleton s2 = singleton.getinstance ();
System.out.println (S1 = = s2);
}
}
12.final modified member variable initialization problem
Class field: The initial value must be specified in a static initial block or when the field is declared
Instance field: You must specify an initial value or declaration in the constructor in a non-static initial block or when declaring the field
The 13.Final variable must be explicitly initialized and the Final variable will not be implicitly initialized by the system
14.java uses a constant pool to manage the string direct constants that have been used, for example, string a = "Java"; , the system has a constant pool of constant string "Java", which executes string b = "Java" again; A = = B is True
15.final method cannot be overridden, final class cannot be inherited
If the private method is the same as final private
If the final-decorated method is present in a subclass, it is a subclass that is newly defined and has no relation to the parent class
16. Immutable classes: The field of the class is immutable after it is created. Java provides a wrapper class and a string of 8 basic variables that are immutable.
17. Immutable classes of cached instances
Copy Code code as follows:
Class Cacheimmutale
{
private static int max_size = 10;
private static cacheimmutale[] cache = new Cacheimmutale[max_size];
private static int pos = 0;
Private final String name;
Private Cacheimmutale (String name)
{
This. name = name;
}
Public String GetName ()
{
return name;
}
public static Cacheimmutale valueof (String name)
{
for (int i = 0; i < max_size; ++i)
{
if (Cache[i]!= null && cache[i].getname (). Equals (name))
return cache[i];
}
if (pos = = max_size)
{
Cache[0] = new Cacheimmutale (name);
pos = 1;
}
Else
{
cache[pos++] = new Cacheimmutale (name);
}
return cache[pos-1];
}
public boolean equals (Object obj)
{
if (this = obj)
return true;
if (obj!= null && obj.getclass () = = Cacheimmutale.class)
{
Cacheimmutale ci = (cacheimmutale) obj;
Return Name.equals (Ci.getname ());
}
return false;
}
public int hashcode ()
{
return Name.hashcode ();
}
}
public class Cacheimmutetest
{
public static void Main (string[] args)
{
Cacheimmutale C1 = cacheimmutale.valueof ("Hello");
Cacheimmutale C2 = cacheimmutale.valueof ("Hello");
SYSTEM.OUT.PRINTLN (C1 = = C2);
}
}
The use of a cached instance to see the frequency of an object, if repeated use of the advantages outweigh the disadvantages, if not often use the harm is greater than the benefits
There is also Java-provided java.lang.Integer to create a number between-128-127 using the caching mechanism of the
Integer in2 = integer.valueof (6);
Integer in3= integer.valueof (6);
in2 = = in3 is true;
Static and abstract cannot modify a method at the same time, there is no class abstract method
19. A class can be another parent class that implements multiple interfaces in which the filed is public, static, final, and is public abstract
20. Non-static internal class methods to access a variable, the search order is: First internal class within the method inside the-> class-> external class if you can not find a compilation error
Copy Code code as follows:
Import java.util.*;
public class Discernvariable
{
Private String prop = "Instance variable of external class";
Private Class Inclass
{
Private String prop = "Instance variable of inner class";
public void info ()
{
String prop = "local variable";
System.out.println ("field value of the outer class:" + DiscernVariable.this.prop);
System.out.println ("field value of the inner class:" + This.prop);
System.out.println ("Value of local variable:" + prop);
}
}
public void Test ()
{
Inclass in = new Inclass ();
In.info ();
}
public static void Main (string[] args)
{
New Discernvariable (). Test ();
}
}
21. Non-static internal classes cannot have static methods, static field, static initialization blocks
22. Access to internal classes outside of external classes
Accessing non-static inner classes: outclass. Inclass varname = new Outclass (). New Inclass ();
Access static inner class: Outclass. Inclass varname = new outclass. Inclass ();
Copy Code code as follows:
Import java.util.*;
Class out
{
Class in
{
public in ()
{
SYSTEM.OUT.PRINTLN ("Non-static internal class Builder");
}
}
}
public class Creatinnerinstance
{
public static void Main (string[] args)
{
Out.in in = new Out (). New in ();
/*
The above code can be written separately as:
Out.in in;
out = new Out ();
in = Out.new in ();
*/
}
}
Class Subclass extends Out.in
{
Display the constructor that defines the subclass
Public subclass (out)
{
The constructor that calls in is displayed by the transferred out object
Out.super ();
}
}
Copy Code code as follows:
Import java.util.*;
Class Staticout
{
Static Class Staticin
{
Public Staticin ()
{
SYSTEM.OUT.PRINTLN ("Static internal class builder");
}
}
}
public class Creatstaticinnerinstance
{
public static void Main (string[] args)
{
Staticout.staticin in = new Staticout.staticin ();
/*
The above code can be written separately as:
Staticout.staticin in;
in = new Staticout.staticin ();
*/
}
}
Class Subclass extends Staticout.staticin
{
No need to create an internal class instance
}