1. Special characters
a) \ n newline
b) \ t tab
<------------------------------------------------------------------------------------------------->
2. 8 basic data types
Byte 1 byte
short short integer 2
int int 4
long long integer 8
char char 2
boolean Boolean 1
float float 4
double Double-precision floating-8
Autochanger long a = 100; 100 (int) ---- long
Cast int I = 10;
byte b = (byte)i;
Cast might lose data.
Reference types (String ... array of objects)
<------------------------------------------------------------------------------------------------->
3. trinocular operation
int a = 5>4?10:100;//a=10 |
expression? Values: Value 2 |
1 expression is true value or the value 2 |
<------------------------------------------------------------------------------------------------->
4. If
if the {} may be omitted, and if omitted, if the first one is belonging to the if * recommendation is not omitted
|
if (condition) { // Code Block } |
The results must be boolean results conditions The result is true, the code block is executed Note: js the if condition true i.e. non-digital 0 |
<------------------------------------------------------------------------------------------------->
5. Switch
l Switch the type of expression? char int short bety
l break the switch usage later Case;
l default location? You can omit any position can be
l case if the same can not be
l switch , and if usage scenarios (different)
break:
Used in Switch : out of the switch, to prevent the penetration of
Used in the loop: out of the current cycle
the Continue : the end of this cycle, the next cycle into the
return statement:
after execution return statement, which the latter will no longer execute code.
<------------------------------------------------------------------------------------------------->
6. while 与 do while
while: the first determination condition is again performed.
od-while: performing a first determined.
No statement about this syntax while-do! ! !
<------------------------------------------------------------------------------------------------->
7. code debugging
l break point : break the code position is about to be executed.
F6 n- : Single step
<------------------------------------------------------------------------------------------------->
8. Memory
Sub-heap and stack
<------------------------------------------------------------------------------------------------->
9. classes and objects
A Class classification i.e., abstract a defined
II. Object is an objective reality, occupy space
Class is a group having the same characteristics (attributes) and behavior (methods) abstract definition
The object is a class concrete (instantiate new xxx)
<------------------------------------------------------------------------------------------------->
10. Nomenclature
1. Pascal nomenclature, capitalize the first letter of each word, java general application in the class name
, such as: GirlFriend, MyHomeWorld, YourName ...
2. hump nomenclature, the first letter of the first word lowercase, capitalize the first letter of each word behind
such as: GirlFriend, myHomeWorld, yourName
Java applications in general properties and methods
3. Hungarian notation, each capital letters, with an underscore spaced between words
such as: GIRL_FRIEND, MY_HOME_WORLD, YOUR_NAME.
java is generally used in a static constant, many other applications on the database fields.
<------------------------------------------------------------------------------------------------->
11. Members and local variables
Examples of the method: a method belonging to the object
Not static modification, by its object name . Call the method name ()
Class methods : Method belong to the class of
With a static modification (also called static methods) can be directly through the class name . Call the method name (), you can
By object name . Method name () call
static : static, the class will be loaded when loading
Modifying member (member variables, member method)
Modification method, which is a static method (class method) can be directly invoked by class name
Static methods can not be used in non-static variable,
Modified variable that is static , all shared objects (only one copy of the variable)
When members of the same name and local variables, use local variables priority
Member variables have default values, local variables no default, you must be assigned an initial value before the local variables
The scope of member variables: effective in the whole class
Local variable scope: only in the definition of the variable {} within the valid.
<------------------------------------------------------------------------------------------------->
12. Super usage:
( . 1 ) Super. Properties Property Access parent class
( 2 ) Super. Method ( .. ) method call parent class
( 3 ) Super ( ...) calls the constructor of the parent class
l In a subclass configured with Super (..) call the constructor of the superclass, Super (..) to be placed in the first one, therefore, the this (..) and Super (..) does not appear in the same configuration .
l In the configuration in the first subclass have an implicit default Super (), indicates that the call parent class constructor without parameters, so that the new time subclass object, first performs configuration of the parent class.
L When no parent class constructor with no arguments, the subclass structure must be added, and parameters are configured in a first configuration call the parent class.
<------------------------------------------------------------------------------------------------->
13. inheritance: the extends ( keyword )
A subclass inherits the properties and methods of the parent class
A class can inherit from a parent class (single inheritance)
Subclass can not inherit the parent class private members
Subclass can not inherit the parent class constructor
Child and parent class is not the same package, using the default access member can not be inherited
<------------------------------------------------------------------------------------------------->
14. The access control modifier:
|
This class |
Package with other classes |
Descendant class |
Cross-package |
P ublic ( public ) |
√ |
√ |
√ |
√ |
P rotected ( protected ) |
√ |
√ |
√ |
X |
The default ( Friendly ) |
√ |
√ |
The same package may access descendant class |
X |
Private ( private ) |
√ |
X |
X |
X |
The I S A is an inherited
L IKE A as an implement interface
Inheritance benefits
Improve the reusability of code
Provide the basis for polymorphism
<------------------------------------------------------------------------------------------------->
15. rewrite (overwrite)
When the parent class method can not meet the needs of sub-class, sub-class will re-write the name of a parent class method, the same method parameter list.
Rewrite specific rules:
Like the method name, the same parameter list, the return value of the same type (subclass method's return type can be a parent class method returns a subclass of the type), modifiers, modifiers strict than the parent class (large throw exception than the parent class )
<------------------------------------------------------------------------------------------------->
16. The Final usage
Modified class can not be inherited
Modification methods can not be overridden
Modifying variables The variables are constant, immutable
Final when modifying reference types, the address can not be changed, but you can change the contents of the address
final A a = new A();
|
<------------------------------------------------------------------------------------------------->
17. abstract class, an abstract method
When the method body of a method is not clear, we simply delete the method body of this method, together with the abstract keyword modification, the method is an abstract method. Class where the method should be defined as an abstract class.
When ordinary class inherits an abstract class, the general class of abstract class must override the abstract methods.
An abstract class can not be instantiated (not new object)
Abstract class has a constructor method
Abstract class ordinary member variable
Ordinary methods can abstract methods and an abstract class.
<------------------------------------------------------------------------------------------------->
18. Polymorphic
Of the various forms of a thing.
Dogs can be called animals:
Animal ani = new Dog (); // parent class object reference to point to a child
ani is a reference (address), the type of reference is the parent class
new Dog () new is an object subclass
Dogs can also be called a dog :
Dog dog = new Dog()
And more tense
Ordinary member variables: compile and run all see = what is left of the reference type
If a variable reference on the left is the parent class type, the visit is the parent class
If a variable reference on the left is a subclass of the type of visit is a subclass of
Ordinary members of the method: run to see = the right new is what type of object
If a new class of object which is which class method invocation
Compile Look left.
Static methods: run-compile all see = left
What is left is the type of approach is called class.
Static member variables: compile and run all look = left
<------------------------------------------------------------------------------------------------->
<------------------------------------------------------------------------------------------------->
19. Transformation:
Dog dog1 = (Dog) pet; // downward transition (the references cited parent class into subclasses)
// compile correctly executed throw an exception ClassCastException
// Penguin penguin = (Penguin)pet;//
// compile correctly executed throw an exception ClassCastException
Four four = four new ();
Its sound = (his) way;
Polymorphic benefits:
Program to improve the scalability, maintainability.
Polymorphic forms of:
Method subclass references to the parent class object, overwriting, overloading, vararg
public void show(Object... nums){ for (Object num : nums) { System.out.println(num); } }
|
Object: root of all classes, all class directly or indirectly inherits Object Class |
<------------------------------------------------------------------------------------------------->
20. Interface:
Interface: particular abstract class can also be understood as a capability, a specification (constraint)
A specification (constraint): Constraint All abstract method implementation classes must implement the interface
Ability: Want to have some kind of ability, as long as there is the interface to achieve this capability.
/**
* 接口中的变量都是静态常量
* 在接口中定义一个变量,默认会加上public final static
* 接口中的方法都是抽象方法(jdk1.8之前)
* 定义的方法默认会加上public abstract
* 类和类可以是继承extends关系,单继承
* 类和接口 是类 实现implements接口,可多实现
* 接口和接口 接口继承接口,并且可以多继承接口。
*
* 普通类实现接口必须实现接口中的所有抽象方法
* 抽象类实现接口可以不用实现接口中的方法
*
* jdk1.8及以上
* 接口中可以有static 或default修饰的普通方法
*/
<------------------------------------------------------------------------------------------------->