Small class object knowledge summary

About the class object I have a little bit at work, there are some small sum, are some of the more basic knowledge, we hope to be able to discuss 5012.

The first is the concept JavaOO of four:

 

OO: object-oriented

OOP: Object-Oriented Programming

OOA: Object-Oriented Analysis

OOD: Object-Oriented Design

Java the language is an object-oriented language that object-oriented and process-oriented differences Where is it?

Object-oriented: I was around this software is done by what part of, or that which objects have to do.

Process-oriented: I want to solve the problem, what do I do, he's completed the process of how to solve the problem issues.

The so-called object-oriented in the end what is it?

1. find the object: the object can be any person appearing in the problem domain / or physical things, the simple point that is the "stuff"

2. After the problem domain objects have been found, we will write a class to describe the properties and behavior of each object.

3. The property is one thing that means the target value data.

What is the behavior of an object can do, or what we want to do these objects.

Everything object, the object due to concerns arising.

Class is an abstract object, the object is an instance of the class

Class is a collection of objects with the same attributes and behavior.

 

Here I put some of my summary distributed to you for informational purposes only, hope to have inadequate provision can be made:

 

Class is composed by the properties and behavior.

File name must be the same as the common name the class name

final named constant, all uppercase

Is a class attribute value of the data body, which is in the form of constant and variable properties Properties

 

Variable properties: declaration syntax uses the syntax of variables, just one more than the average variable access modifier before

In effect, all objects of that class are themselves provided with the movable property, but each object can have different values

 

Constant Property: declaration syntax uses a syntax constants, just more access modifier

In effect all the objects of that class will automatically have this property, but the value of the same, and can not be changed.

 

Essence class definition is to define a data type.

Class is a data type is much more complex than the basic data types, attributes and behavior of his composition,

It may be a plurality of attributes, and each have their own data types.

Class behavior is carrying method, various operations can be accomplished directly belonging to the target class.

Public class TestStudent{

public static void main(String[]args){}

Student stu = new Student();

Data type variable name = generated object syntax, try new keywords, back to keep the class name ()

Default initial value of the property: basic data type is 0, the reference data type is null.

Student stu only variable in a 4-byte memory

This variable holds true just about to the Student object reference also known as "object name space"

new student () - which will produce a new Student object includes an integral storage space each attribute, the size of this space is determined by the sum of the size of the object property body.

The relationship between classes and objects:

Template class is not used directly, the object is actually present in the concrete, so called Object and "instance" of a class. Object generated by the operation of the class known as "instantiated".

 

Object properties and methods of operation:

Object plus. "" Operators

. "" When the operator appreciated that it be understood as "de"

The name → stu.name stu

this age 的 → stu.aga

The destruction of the object by the Java garbage collection (GC) to complete.

He has its own algorithm rules, procedures ape is no way to control change

Not referenced by any variable, while the object is not in use. (The definition of garbage collection)

There is a basic rule in a number of garbage collection algorithms: he will take the initiative does not refer to the object pointed to recovery

and so:

1. If you want an object to be recovered in the program on the way, then we can take the initiative to put its point of reference assigned to null.

2. The null pointer exception: properties and methods attempt to call an empty object,

3. If the object reference variables (object name space) is a local variable, then when the end of the module executes it belongs, the life cycle of this variable on coming to an end, the variable will disappear. So there is no object it points to a reference point It will be recycled.

4. The program code may generate an ape only the intersection between garbage collection and code level, this code is System.gc ();

Note: The role of this code is not active garbage collection calls, but call garbage collection, but the garbage disposal will be decided by his own algorithm.

 

///

Garbage collection is a virtual machine thread, when the virtual machine is relatively free, clean up of useless objects in space, the developers can not directly intervene in garbage collection, but you can call System.gc () to accelerate the garbage collection rate.

 

A total of three access modifier keyword, four cases

Now we just master two public (public), private (proprietary)

public property or method may be modified at any position accessible

modified private property or method, may be accessed in this class

Java-based variable attributes official specifications should be defined as private, and then provide get / set methods allow external operation. Value or assignment.

get method is called: accessor

set method is called: Modifier

Both in format and naming, both standards.

 

When the global and local variables of the same name, will use local variables default

In this case, especially to the global variable (the current class of objects), it is necessary in the global variable Front + "this." Operation

At this time, this is equivalent to each object in life to say "I" refers to the current object.

Recommendation: When all access current properties and behavior of objects in this class are to develop the habit of writing this

 

Benefits: in development, this, there will be tips that can improve development efficiency.

         Regardless of when to add list, and when without

 

Class among EDITORIAL who is who to call something else. I remember being called back to fight brackets

 

 

Guess you like

Origin www.cnblogs.com/lyslyslyslyslys/p/12018499.html