Java Learning Note 1-object-oriented features

Source: Internet
Author: User
Tags abstract definition uppercase letter


Object-oriented Programming (OOP): To make programming more hierarchical, increase the reusability of common modules, so that programmers focus more on specific business implementation and technological breakthroughs. At the same time, it also allows programmers to consider the framework in advance, such as the design of the class, can have higher requirements for image thinking.


5 basic features for programming methods:

1. All things are objects;

2. The program is a combination of a lot of objects, through message passing, each object knows what to do;

3. Each object has its own storage space, can accommodate other objects;

4. Each object has a type;

5. All objects of the same class can receive the same message.


Scope Current class Same package Descendant class Other Package
Public
Protected X
Friendly X X
Private X X X

Class: Some common common properties can be implemented in a class, avoiding repeated implementations in multiple places, where each class is equivalent to a type, and the shape can be a common class for all shapes.


Interface (Interface): Through the interface of the class to operate/Invoke the concrete implementation/action of the class, there can be a common interface and implementation to create, delete the Shape class.


Inheritance (extrends):

Subclasses have attributes that are not private to the parent class, methods;

Subclasses can have their own properties and methods, that is, subclasses can extend the parent class;

Subclasses can implement the methods of the parent class in their own way;

Java class inheritance is a single inheritance, but the interface can use the keyword implements to implement multiple inheritance;

The subclass calls the parameterless constructor of the parent class by default, but if there is no default (parameterless) parent class constructor, the subclass must display the constructor (with parameters) for the specified parent class, and must be the first thing to do in the subclass constructor;

Inheritance increases the coupling between classes (the disadvantage of inheritance, the high degree of coupling will cause the link between the code), with caution with inheritance.

After the inheritance type supports the upward transformation, such as B inherits a, then the instance of B also belongs to type A.


Dynamic binding/Polymorphism: When both inheritance and upward transformation exist, the function implementation follows the polymorphic principle for the actual invocation, in order: This.show (O), Super.show (O), This.show ((Super) O), Super.show (( Super) O).


Final class: Use the keyword final definition to indicate that the class cannot be inherited, and that the methods and variables inside the final class are the final properties by default.


Abstract class: Using the keyword abstract definition, abstract classes can only be used after inheritance, cannot be directly instantiated.


Interface: Using the keyword Interface definition, the interface can not be instantiated, the interface is not constructed method, the interface method is implicitly abstract method, the interface method is not implemented in the interface, only by implementing the interface of the class to implement the method in the interface.


Java collection classes: Set, List, Map, Queue.


Single structure: All classes in Java are ultimately inherited from the "Object" base class.


Look down: equivalent to coercion type conversion, be sure to confirm security before use.


Generics: defined using only one uppercase letter, and placed in <>, generics are mostly defined without specifying explicit types, but are specified when instantiated, reinforcing code reusability.


Garbage collector: Java supports automatic memory allocation and recovery mechanisms, which can have a certain impact on performance.


Exception handling: Try, catch, and finally mechanisms.


Multithreading: Java supports multithreading, and can be self-allocated during multi-processor processing, using a resource lock or synchronized keyword for the use of shared resources.


This article is from the Android Learning Notes blog, so be sure to keep this source http://sylan215.blog.51cto.com/681991/1914762

Java Learning Note 1-object-oriented features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.