Understanding java-1.7 Single root inheritance and collection from the beginning

Source: Internet
Author: User

In this chapter we will briefly introduce the single inheritance and the container.

1. Single Root inheritance

Concept:

A single inheritance, which means that all classes inherit from the same inheritance pattern as the base class

Advantages:

(1) All objects have a common interface, which in the final analysis is the same basic type.

Package Com.ray.ch01;public class Jack extends Object {}

In fact, when we create a new class, it inherits the root class of object by default, so when we create a new class, we can also write it like this. Let's test it down here.

Package Com.ray.ch01;public class Jack {public static void main (string[] args) {Jack Jack = new Jack (); System.out.println (Jack instanceof Object);}}

Output:

True

(2) A single inheritance structure ensures that all objects have certain functions.


As you can see, the Jack object is equipped with all the methods in object.

(3) A single inheritance structure makes it much easier to implement the garbage collector.

Because it is a single inheritance, the algorithm for calculating the use of objects becomes much easier.


2. Collection

(1) Why do I need a collection?

Because there is no way to predict how many objects need to be stored during normal programming, if you use a simple array that does not meet such requirements, there is a collection that can be self-expandable.

(2) Type

Storage sequence list, associative array map, single storage set, etc.

(3) Select

Because different collections meet different needs, they must be chosen according to the business. For example:

When most of you just need to read, then choose ArrayList more appropriate, it is characterized by easy to read, insert difficult

When you are inserting data in most cases, you should choose LinkedList, which is suitable for random storage, but low random read performance


2.1. Generics

Since a collection is just a storage object, there can be a variety of problems and exceptions for a downward transformation that often occurs in a business scenario, so Java introduces a generic concept that controls each collection just to put specific objects.


Summary: This section provides a simple introduction to single inheritance and collections, and the collections and generics are expanded in detail in later chapters.


This chapter is here, thank you.

-----------------------------------

Directory




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Understanding java-1.7 Single root inheritance and collection from the beginning

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.