Thinking in Java (viii)-containers, exceptions, I/O, rtti

Source: Internet
Author: User

The maximum efficiency of the object group is still the traditional Array
Considering the efficiency, Java performs a boundary check at runtime.
The container class can only hold the reference, and the objects it holds are all object classes. The element type in the container is not fixed.
Array can generate an array that directly holds the basic type value. Therefore, array is divided into primitive array and object array.
Collection represents a group of independent elements, and map represents a group of key-value objects that are correct. The inheritance systems of the two represent different implementations.
You can compare the element size in a container by implementing comparable or comparator.
As for Vector... Not recommended

The basic philosophy of Java: poorly structuredProgramUnable to execute
Therefore, Java exception mechanism is available.
The type and contained information of the exception object are used to indicate error-related information.
Exceptions in Java all adopt the termination mechanism, that is, once an exception is generated, the entire program is terminated.
Writing your own exception classes must inherit from an existing exception type

In general, I/O in Java is a little too complicated and makes people suffer...
Let's write some typical applications.
1. input files with buffer function
Bufferedreader
2. Get input from memory
Stringreader
3. Get formatted input from memory
Datainputstream
4. output to file
Printwriter
5. Data Storage and recovery
Dataoutputstream

There are two other good functions: serialization and tokenizing.

Rtti (Run time type identification)
The traditional mechanism assumes that you have all type information during the compilation and execution phases.
The reflection mechanism allows you to find information related to the class during execution.

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.