Java Study Day5

JavaSE day5:

An array (Continued)
1, multi-dimensional arrays (Learn)
Java is a multi-dimensional array of elements (array) types of reference data, it is possible to have a stepped array, i.e. the number of elements in the array may be different peer
two, classes and objects
1. question:
What is the class? (Eg: bicycle design)
What is the object? (Eg: a vehicle, bicycle)
Why mechanism to design classes and objects? (OOP)
state + Behavior
property method
2, the three characteristics of object-oriented - encapsulation, inheritance, polymorphism
1) encapsulation: The so-called package, i.e. the objective things packaged as an abstract class, and the class you can put their data and methods allow only trusted class or object manipulation of unreliable information hiding. In a nutshell is, the internal operation invisible to the outside (protective)
2) Inheritance: Inheritance refers ⼀ kinds of capacity: it can make all the features Using an existing class, and re-write the original class without having extend the functions in these circumstances.
3) Polymorphism: polymorphism refers to the so-called same manner ⼀ instances of the class have different forms in different situations. Of polymorphism so that objects having different internal structures can share the same external interface.
Object-oriented extensions noun: OOA - OOA; OOD - object-oriented design; OOP - Object Oriented Programming
3, Syntax
1) the class definition syntax
modifier (modifier) class class name {
1, attribute (optional)
2 The method (optional)
3, the constructor (the constructor If not defined, the system automatically generates a constructor with no parameters) to allow overloading
}
EG: the HelloWorld {...} public class
. 1> how to define the properties
modifiers variable type variable name;
Default:
2> how to define a method
modifiers method return type name (parameter list) {
achieved
}
EG: public static Rotate (int [] a, int K) {...}
. 3> The method of how to define the configuration (if not expressly written, the system will automatically add a constructor parameter absent; has no complement)
modifier class name (parameter list ) {
}
syntax 2) constructed object | object instantiation syntax
create object | instance (verb)
the class name of the variable name = new class name (argument list)
reference type - class references
as long as there opens a new keyword to memory
a public file can have only one class, the class name and the file name to be consistent with
a class bytecode .class generates a file
object is stored in the main attribute, the method can also find the class corresponding to the object region in
the object (reference data types) must be called after instantiation, or will cause NullPointerException (runtime error), will not compile-time error
Eg: the p-the Person = null;
// define a point not Person type of any reference object (reference class type)
Person Person new new = P (...);
// defines an object type Person
// define a reference to an object of type Person type Person (reference class type)
garbage space: there is no point to the stack memory heap memory space
due to the anonymous object does not have any points to stack space, so use ⼀ times after becoming space junk.
4, object instantiation process
1) new computation object keyword required memory size, open space, is initialized to 0x0
P = the malloc (the sizeof (the Person));
Memset (P, 0x0, the sizeof (the Person));
2) call construction methods, attributes initialization
3) constructor call ends and returns a pointer to the new object reference
Person tmp = new object;
5, the property how to access object (internal | external)
method (internal how to call objects | external)
1 ) method call the class attributes and methods of the internal (in the class access the class)
properties: direct access to by attribute name (attribute name appears with this) naming occlusion.
method: directly through the method name to call
2) external (in other access class class method calls the class attributes and methods)
properties: property name of the referenced object.
method: method name referenced object (argument list).
6, the other (calling attention to distinguish between two )
1) nested calls
System.out.println (Arrays.toString (rotate (new int [] {1,2,3,4,5}, 3)));
broken down as follows:
int [] = TMP1 new new int [ ] {1,2,3,4,5};
int [] TMP2 = Rotate (tmp1,3);
String of Arrays.toString TMP3 = (TMP2);
System.out.println (TMP3);
2) call chain (temporarily can not have a good example)
. 7, the this key use word
1) configured to call other methods in the constructor, call statement must appear in the first row (the form: this (parameters))
2) or by the method of this access attribute (typically it occurred appears when naming occluded) (this. method name (parameter))
is the current reference 3) this represents the object (current object)
common property and common method, in fact, are bound with a hidden object
standard keyboard input stdin
to stdout screen
standard error stderr screen

Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5
Java Study Day5

Guess you like

Origin blog.51cto.com/14235507/2422526