Related Summary of Java programming (i) __ programming

Source: Internet
Author: User
Tags wrapper
Java Programming Related summary (i)

Java Programming related Summary is a continuous update of the series, is my own years of work to use the Java experience of a summary, is also a new understanding of the temperature, because a lot of the foundation of things after so many years, peacetime work will be forgotten, so read the book, on the Internet, check the information, It is also a record of their own notes, after a period of time to see is also pretty good, but also hope to help the people are learning, this series will summarize some: object-oriented programming Ideas Java basic Syntax some interesting framework analysis The whole idea of actual combat project code optimization and performance tuning of several other missing things and additional object-oriented programming Ideas

    One day a friend suddenly asked me what boxing is (automatically converts the base data type to a wrapper type), what is a unboxing (automatically converts the wrapper type to the basic data type), I forgot to check the background data to understand that the basic type of data to the packaging type of data automatic conversion process, in fact, there was also a little impression, But dare not say, because usually uses many but the concrete concept may forget. So I had this idea early on, writing something to keep track of my knowledge, and checking what I had forgotten.
    in the same situation, then what is the object? What is a class. What is an inner class. What is an interface. What is an abstract class. What the bag is.
    These basic concepts may be understood by every peer, but it may be that many people will hesitate to describe them in specific language.

The purpose of the programming language
The ultimate goal of all programming languages is to provide an abstract approach, as written in the "Feel in Java". So first you have to understand what is abstract , the abstraction is not seen in person, need to make full use of thinking. Abstraction is the extraction of common and essential characteristics from many things, and discards its non essential features. For example, apples, bananas, pears, grapes, peaches and so on, their common characteristic is fruit. The process of drawing the fruit concept is an abstract process. To abstract, you have to compare, you cannot find a common part without comparison.

The birth of a programming language is to solve some of the same types of problems, the abstraction of these requirements, but also because of some limitations, in their own domain may be very convenient to use, but encountered other problems will appear very clumsy, and later many "imperative" language (such as Fortran,basic and c) is also an abstraction of assembly language. These languages have made great strides compared to assembly language, but their abstract principles still require us to focus on the structure of the computer rather than the structure of the problem itself. The programmer must establish a connection between the machine model (located in the "solution Space") and the problem model that is actually resolved (in the "Problem Space"). This process requires people to pay more attention, and because it is out of the scope of the programming language itself, resulting in the program code is difficult to write, and to spend a large cost of maintenance. The resulting side effect is a perfect "programming method" discipline. Because different types of requirements are born in many languages, for programmers is a burden, this way to motivate programmers to keep learning. and the object-oriented program design idea has taken a big step on this basis.

Object-oriented is a new method of program design, or it is a novel program design Code (paradigm), its basic idea is to use object, class, inheritance, encapsulation, message and other basic concepts to program. To construct the software system from the objective objects in the real world, and to use the natural way of thinking as far as possible in the system construction. Everything is an object, can be when he is a new variable, can also be used as a stand-alone computer, he saved data, can also operate on their own. Theoretically, all conceptual components can be presented from the problem to be solved and then expressed as an object in the program.

It's a collection of objects that look at the program in terms of object-oriented thinking. Through the message, each object knows what to do, think about it, this scene is actually like human society. Everyone has a clear division of labor, but there are differences between people, are independent individuals, have their own personality things. In a program, you can also use object-oriented thinking to solve the problem.

By clarifying the object-oriented idea, it's easier to understand what the object is and what class it is, and then make some theoretical summary: the basic concept of the object

An object is an entity that is used to describe an objective thing in a system, and it is a basic unit that forms a system. An object consists of a set of properties and a set of services that operate on this set of properties.

An active object is a set of attributes and a package of services that at least one service can execute proactively (called an active service) without receiving messages. Basic concepts of classes

A class is a collection of sets of objects with the same attributes and services that provide a unified, abstract description of all objects belonging to the class, including the two main parts of the property and service. In an object-oriented programming language, a class is a separate program unit that should have a class name and include a description of the property and two main parts of the description of the service. News

A message is a service request to an object that should contain the following information: The object ID of the service, the service identification, the input information, and the answer information. Services are often referred to as methods or functions. Three main characteristics of object-oriented

Encapsulation, inheritance and polymorphism.

Encapsulation :
First, attributes can be used to describe the characteristics of the same class of things, which can be used to describe the operations that a class of things can do. Encapsulation is the commonality of things that belong to the same category (including attributes and methods) grouped into one class for ease of use.
A. Concept : Encapsulation, also known as information hiding, refers to the use of abstract data types to encapsulate data and data-based operations together to form an indivisible independent entity in which data is protected within the abstract data type, hiding internal details as much as possible, Only some external interfaces are retained to make contact with the outside. Other parts of the system communicate and interact with this abstract data type only through authorized operations that are encapsulated outside the data. That is, users do not need to know the implementation details of the internal methods of the object, but they can access the object based on the external interface (object name and parameters) provided by the object.
B. Benefits :
1. A professional division of labour has been achieved. By encapsulating code that implements a particular function as a separate entity, programmers can invoke it when needed, thus achieving a professional division of labor.
2. Hide the information and realize the details. By controlling access, you can hide information that you do not want the client programmer to see, such as a customer's bank password that needs to be kept secret, and can only develop permissions on that client.

Inheritance :
Is the acceptance of personality and methods of commonness, and the attribute and method of individuality.
Concept : A class inherits another class, then the inherited class is a subclass, and the inherited class is the parent class.
Objective: To implement the reuse of code.
Understanding : The relationship between subclasses and parents is not a parent-child relationship in everyday life, but a special and generalized relationship between subclasses and the parent class, which is a is-a relationship, and subclasses are more detailed classification of the parent class. such as Class dog extends animal, can be understood as dog is a animal. Note that when designing inheritance, to allow a class to inherit, the parent needs to be properly open access, follow the principle of the Richter substitution, that is, to modify the closure of the extended open, that is, open-closed principle.
results : The inherited subclass automatically owns the properties and methods of the parent class, but it is particularly noted that the parent class's private properties and construction methods cannot be inherited. In addition, subclasses can write their own properties and methods to implement extensions of functionality, and subclasses can also copy the method of the parent class, which is the override of the method.

polymorphism:
The concept of polymorphism is developed and is based on encapsulation and inheritance.
Polymorphism is the implementation of a unified behavior at the level of abstraction, and at the level of the individual (concrete), this unified behavior will carry out its own characteristic behavior because of the morphological characteristics of the individual. (For an abstract thing, the internal individual can find its own behavior to perform.) )
concept : The same thing, call it the same method, the parameters are also the same, but the behavior of performance is different.
Understanding : Subclasses appear as parent classes, but do things in their own way. Subclasses that appear as parent are required to transition upward (upcast), where upward transitions are automatically implemented by the JVM and are safe, but downward transitions (downcast) are unsafe and require casting. When a subclass appears as a parent, its own unique properties and methods cannot be used. Abstract class Concepts

If a class contains an abstract method, the class is called an abstract class, and the abstract class must be decorated with the abstract keyword before the class. Because an abstract class contains methods that do not have a specific implementation, you cannot create an object with an abstract class.

Here's a question: In the Java programming idea, you define an abstract class as "a class that contains abstract methods," but later you find that if a class does not contain abstract methods, it is also an abstract class if it is modified in abstract. This means that an abstract class does not necessarily have to contain abstract methods. Personally think this is a matter of concern, because if an abstract class does not contain any abstract methods, why also design as an abstract class. So remember this concept for a moment, without having to delve into why.

An abstract method is a special method: it has only declarations, but no concrete implementations. Package

Consists of classes developed by a set of support programs.


Interface

A collection of method bodies, an extension of an abstract class. footnotes

Reprint please indicate the source. 1. This blog is updated synchronously in the personal blog site: www.klsstt.com. ↩

Related Article

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.