Source: Hi learning network sensitive and eager Forum www.piaodoo.com welcome to learn from each other
1. The basic data types
Plastic:
byte 1 byte
short 2 bytes
int 4 bytes
long 8 bytes
character:
char 2 bytes
Float:
float 4 bytes
double 8 bytes
Boolean:
boolean 1 byte
2.java 7 new binary integer
Begin with 0b or 0B
When 3.java 16-bit Unicode character encoding format is '\ uXXXX', where xxxx represents a hexadecimal integer
4.java specified in the positive infinity, negative infinity and zero
Positive infinity = a positive number divided by 0
Negative infinity = a negative number by zero
0.0 divided by 0.0, or get a non-negative number on a prescription
5. In java only boolean true and false
6. No multi-dimensional array in java
Multidimensional array appears as C language are not true arrays, such as a [3] [4], a [0] a [1] a [2] are real, the address is loaded, dynamic languages, and c assigned to the same array
int [][] b = new int[3][4]
The method of the tape 7. Java compiler package
javac -d. Hello.java will generate in the current directory tree
Run java package name. Class name
filed in state 8. Java objects do not have multiple polymorphic = new parent class object as a subclass (), is the parent class of the object .field call, even if the covering subclass field.
9. instanceof operator
Format: instanceof reference variable name class name (or interface) in front of him determines whether the object is a class object behind, subclasses, instance of a class, and return true, whether the person returns false
Conversion between the basic data types and the corresponding packages 10. Java classes
int a = 1;
Integer A = new Integer(a);
a = A.intValue();
Other types is the same.
Example 11. Single (Singleton) Class Examples
class Singleton
{
private static Singleton instance;
private Singleton(){}
public static Singleton getInstance()
{
if(instance == null)
{
instance = new Singleton();
}
return instance;
}
static void main public (String [] args)
{
the Singleton Singleton.getInstance S1 = ();
the Singleton Singleton.getInstance S2 = ();
System.out.println (== S1 S2);
}
}
12.final modified member variable initialization problem
Specifies the initial value when the initial block to be static or declare the Field: Class Field
Example Field: initial value must be specified, or when the constructor declared non-static blocks or declared the initial FIeld
13.Final variables must be explicitly initialized, the system does not implicitly initialized variable final
14.java constant pool will be used to manage the once used directly string constants, for example: String a = "java";, the system constant string "java" constant pool exists, when executed again String b = "java"; a == b is true
15.final method can not be rewritten, final class can not be inherited
If private and final private method is the same
Ruoguo appeared in the subclass with the final modification of the method, that is a subclass of the new definition, there is no relationship with the parent
16. immutable class: After you create Field of the class is immutable. java wrapper class provides eight basic variables and string are immutable class.
17. immutable class cache instance
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();
}
}
CacheImmuteTest class public
{
public static void main (String [] args)
{
CacheImmutale CacheImmutale.valueOf = C1 ( "the Hello");
CacheImmutale CacheImmutale.valueOf C2 = ( "the Hello");
System.out.println (C1 == C2) ;
}
}
depends on the frequency of use with an object cache instance, repeated use of it outweigh the disadvantages, if often used that would harm than good
There are java provided java.lang.Integer create value using caching mechanisms in a number between -128-127
Integer in2 = Integer.valueOf(6);
Integer in3= Integer.valueOf(6);
in2 == in3 is true;
18. static and can not abstract a modification of the method, the method is not an abstract class
19. A class may yet a parent class, implement multiple interfaces, interfaces Filed is public, static, final, and the public abstract method
20. The method of non-static inner classes to access a variable, the search order: first class within the internal method -> inner class -> If you can not find outside of class is a compilation error
import java.util. *;
DiscernVariable class public
{
Private String prop = "outer class instance variables";
Private class inclass
{
Private String prop = "inner class instance variables";
public void info ()
{
String prop = "local variable";
the System.out. println ( "outer class field values:" + DiscernVariable.this.prop);
System.out.println ( "inner class field values:" + this.prop);
System.out.println ( "local variable values: "+ prop);
}
}
public void Test ()
{
inclass in inclass new new = ();
in.info ();
}
public static void main (String [] args)
{
. DiscernVariable new new () Test ();
}
}
twenty one.Nonstatic inner classes can not have a static method, a static Field, static initialization block
22. In addition to the external access internal class class
Access nonstatic inner classes: outclass.Inclass varname = new outclass () new InClass ();.
Access static inner classes: outclass.Inclass varname = new outclass.Inclass () ;
import java.util. *;
Out class
{
class the In
{
public the In ()
{
System.out.println ( "nonstatic inner class constructor");
}
}
}
CreatInnerInstance class public
{
public static void main (String [] args)
{
. Out.In new new Out = in () the In new new ();
/ *
or more separate code can be written as:
Out.In in;
Out Out OUT = new new ();
in the in out.new = ();
* /
}
}
the extends Out.In SubClass class
{
// constructor display definition SubClass
public SubClass (Out OUT)
{
// In constructor call display by the object into the Out
out.super ();
}
}
import java.util. *;
StaticOut class
{
static class StaticIn
{
public StaticIn ()
{
System.out.println ( "static inner class constructor");
}
}
}
CreatStaticInnerInstance class public
{
public static void main (String [] args)
{
StaticOut.StaticIn in StaticOut.StaticIn new new = ();
/ *
or more separate code can be written as:
StaticOut.StaticIn in;
in = new new StaticOut.StaticIn () ;
* /
}
}
the extends StaticOut.StaticIn SubClass class
{
// class instance without creating internal
}
The original address is: http: //www.piaodoo.com/thread-13259-1-1.html stockings control www.txdah.com 131 outside www.buzc.org enjoyable learning can help to learn better!