Introduction to Objects Knowledge point 1

Source: Internet
Author: User

Object: We will actually solve the problem (in the problem space, where the problem exists, such as a business) and its representation in the program (build machine model, located in the solution space, where the problem is modeled) called the object

1.8 Single-Root inheritance structure

A. In all OOP languages except C + +, all classes eventually inherit from a single base class. In Java, this ultimate base class is called object. This is the single inheritance structure

B. All objects in a single inheritance structure have a common interface, so they are all the same basic types in the final analysis

C. The single-root inheritance structure makes the garbage collector's implementation much easier, and the garbage collector is one of the important improvements in Java relative to C + +.

1.9 Containers

A. Container

To solve the problem of "how many objects and how long does it take to solve a problem", we can create an object type (wrapper class) that holds a reference to other objects, called a container (also a collection).

B. Parameterized type

Create a container that knows the type of object you are saving, so you don't need to move down and eliminate the possibility of making mistakes (the downward transformation may be unsafe). This solution is called a parameterized type mechanism, which is called generics in Java.

1.10 creation and lifetime of objects

There are two ways to create an object:

This is the way--1 is used in C + +. Creating objects in a stack or static storage area allows you to determine the storage space and life cycle of an object when writing a program, providing maximum execution speed. This approach places storage allocation and deallocation in a limited space, but also at the expense of flexibility, because you must know the exact number of objects and their life cycles and types when you write your program.

Java--2. Dynamically create objects in the heap of memory pools. This way knowing the runtime knows how many objects, lifecycles, and types are needed. -Dynamic memory allocation method,

"for languages that allow objects to be created on the stack, the compiler can determine when an object survives and can automatically destroy it, but if you create an object on the heap, the compiler knows nothing about his life cycle"——— just read this feeling good contradiction AH 0 0, "the language of the object created on the stack, (such as C + +)", said it can determine the time the object survived and automatically destroy it, I think the C + + compiler can identify the object of the programmer to determine the life cycle to automatically destroy!

1.11 Exception handling, handling errors

Java was built with exception handling at the outset and forced to use it.

1.12 Concurrent Programming

  To improve the responsiveness of the program by cutting the problem into multiple, independently functioning parts (tasks). In a program, these separate parts are called threads, and the concepts described above are called concurrency.

shared Resource Vulnerability : A problem occurs if there are multiple parallel tasks to access the same resource. To solve this problem, the shared resource must be locked during use, so the whole process is that a task locks a resource, completes its task, and then releases the resource lock so that other tasks can use the resource

Concurrency in Java is built into the language.

Introduction to Objects Knowledge point 1

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.