[Java] "Java programming ideas" knowledge points summary (adhere to gradually update) __ algorithm

Source: Internet
Author: User
Tags constant exception handling inheritance touch

1th Chapter

1. Abstraction and object: programming languages provide abstract mechanisms, and the complexity of solving problems depends on the type and quality of abstraction. "Type" means "what is abstracted".

Models should be modeled only on issues to be resolved. An object-oriented approach provides a tool for representing elements in a problem space, and the elements in the problem space and their representations in the solution space are called "objects".

Programs can be applied to a particular problem by adding new types of objects, and when you read the code that describes the solution, you are also reading the presentation of the problem. This is a more flexible and powerful language abstraction.

2. Five basic features of object-oriented languages:

1 Everything is Object 2) program is a collection of objects, by sending message interaction (call) 3) Each object is composed of 4 of other objects (classes)

5 All objects of a particular type can receive the same message

Object has state (internal data), behavior (method), and identity (unique address)

3. Interface: A class describes a collection of objects with the same attributes (data elements) and behavior (functionality), which is actually a data type. interface determines the request that can be made to a particular object. The code that satisfies these requests must be in the program, which together with the hidden data constitutes the implementation. Each possible request has a method associated with it.

4.UML: Unified modelling Language, Unified Modeling Language-each class is represented by a box, the class name is at the top of the box, the data member is described in the middle of the box, and the method is at the bottom of the box. Typically, only the class name and public methods are shown in the UML design diagram.

5. Service provider:1 Invoke or create an object that provides the ideal service to solve problem 2 improve object cohesion: High cohesion is one of the basic quality requirements of software design, which refers to the "combination" of all aspects of a software component. Avoid putting too many features in the same object.

6. Access control: program developers are divided into class creators (those who create new data types) and client programmers (those who use data types in their applications), and class creators build classes that expose only the necessary parts to client programmers and hide other parts. Reason: 1 so that the client programmer can not touch the part of the 2 that they should not touch the interface and implementation of the separation, the library designer could change the way the class internal work without affecting the client programmer.

Access rights: 1 public--anyone available 2) private--only class creator and type internal methods can access 3 protected--inherited classes can access 4 default access rights--do not work with any of the preceding specified words, usually called package access, under which permissions Class can access other class members in the same package, outside of the package, as if it were specified as private.

7. Combination and Inheritance

Using existing classes to synthesize a new class, called a combination (composition), if a combination occurs, called an aggregation (aggregation), the combination is considered to be a "has-a" (owning) relationship. The combination is simpler and more flexible, and the combination should be considered first when creating new classes.

A base type contains attributes and behaviors that are shared by all exported types, and subclasses replicate the interfaces of the base class and have the same type as the base class. The behavior of changing the methods of an existing base class is called overlay (overriding).

8. polymorphism

Treat an object as its generalization type object, and you can write code that is not dependent on a particular type (interacting only with the base class). This requires late binding on the function invocation mechanism: The invoked code is not determined until run time. The process of seeing an exported class as its base class is called upward Transition (upcasting):

9. Single Root inheritance structure

All classes in Java are ultimately inherited from a single base class: Object

All objects in a single inheritance structure have a common interface, so they all end up with the same basic type; All objects have some functionality; There is no deadlock because the object type cannot be determined.

10. Containers: storing objects, determining space size at runtime

1 different containers provide different types of interface and external behavior 2 different containers for some operations have different efficiency

11. Parameterized Type: JavaSE5 Previously, containers stored objects had only Java common type object. Objects placed in a container will lose their identity. Changing back to the original type requires a downward transition: The transition error occurs with Run-time exceptions, so it is necessary to remember in some way what type it is.

Create a container that holds a particular type, called a parameterized type mechanism. Called Generics in Java.

12. Object creation and destruction

Storage: 1 placed on stack or static storage area, explicit storage allocation and release (C + +) 2) dynamically created in a memory pool called heap (heap): How many objects, lifecycles, and specific types are determined at run time

Java fully adopts dynamic memory allocation method. Provides a "garbage collector" mechanism that automatically discovers when an object is no longer in use and then destroys it.

13. Exception Handling

Java places exception handling directly in the programming language, an object that is "thrown" from an error location and handled by the corresponding type of exception handler "capture". Exception handling is like a parallel to the normal execution of a program, and another path that is executed when an error occurs. does not interfere with normal execution code. Java built-in exception handling and forced to use. It is the only acceptable way to report errors.

14. Concurrent

The problem is divided into several parts that can be run independently to improve the response ability of the program. A part of the stand-alone operation is called a thread, and the concept described above is called concurrency.

Pitfalls: Sharing resources. Multiple concurrent tasks accessing the same resource can cause problems. Workaround: A task locks a resource, completes its task, and then frees the resource lock so that other tasks can use the resource.

2nd Chapter

1. Reference manipulation object: can be created independently, there is not necessarily an object associated with it. Sending a message to a reference to an unrelated object returns a Run-time error. The safe approach is to initialize the reference simultaneously: String s= "DLSL".

2. Where data is stored

1) Register 2 stack (in general RAM): Stack pointer Move down allocate new memory, move up free memory 3 heap: A Universal memory pool (also located in RAM) that holds all Java objects. The compiler does not need to know how long to store data to live. The storage allocation is automatic.  4 constant storage: Inside the program code; Rom: string pool, all literal constant strings and constant expressions with string values are automatically memory qualified, placed in a special static storage area 5 non-RAM storage: The data is completely alive outside of the program example: Stream object--converted into byte streams sent to another machine Persistent objects--stored on disk and restored to regular RAM objects when needed.

3. Basic data type: directly store "value", do not create a variable without new, not a reference, not placed in the heap, and placed on the stack, more efficient.

The size of the Java base data type does not vary with the hardware architecture:


boolean--storage space size is not explicitly specified and is defined only as literal value TRUE or false

4.Java Array

Java ensures that the array is initialized and cannot be accessed outside its scope. When you create an array object, you actually create a reference array, and each reference is automatically initialized to a specific value: null. You must specify an object for it before using any reference, and if you attempt to use a reference that is still null, the runtime will make an error. Therefore, array errors can be avoided in Java.

An array of base data types: The compiler ensures that the array is initialized to zero all of the memory in the array.

5. Class base data type member default value

The basic data type variables are used only as members of the class, and Java ensures that their default values are given, ensuring that those that are primitive type members are initialized to prevent program errors. But these initial values may be incorrect or even illegal, so it's best to explicitly initialize the variables.

This method of ensuring initialization does not apply to "local" variables: int x; may be any value and will not be automatically initialized to zero. An appropriate value should be given before use, otherwise Java will return an error at compile time.

6. The basic composition of the method: name, parameter, return value and method body.

Method names and parameter lists (collectively, method signatures) uniquely identify a method.

7. Parameter list: The Passing object is actually passing the reference, the basic data type is the exception: The pass is a value. Returns: If the return type is not void, the compiler forces a return value of the correct type.

8.static Keywords

When you create a class, you want to assign only a single storage space to a particular domain, and you want a method that is not associated with any object of the class that contains it.

Because the static method does not need to create any objects, you cannot simply call other non-static fields or methods without specifying their objects.

9. Comments and embedded Documents

Link code and documents, use a special annotation syntax to mark documents, and a tool to extract annotations: javadoc--parses special annotation tags, extracts adjacent class names or method names, and outputs an HTML file.

All Javadoc commands can only appear in the/**, ending with the/* Independent document tab at the beginning of @, at the top of the comment line. In-line document labels can appear anywhere and at the beginning of @, but are enclosed in curly braces.

Javadoc can only document comments for public and protected members, and private annotations are ignored. Can be included through the-private tag.


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.