20145311 Java Programming 5th Week of study summary

Source: Internet
Author: User
Tags finally block throwable try catch

20145311 "Java program Design" 5th Week study summary textbook study content summary eighth 8.1 syntax and inheritance structure 8.1.1Try, catch

All errors in Java are packaged as objects, and you can do some processing after a try catch represents the wrong object (you can display errors or resume normal processes).

8.1.2 Exception Inheritance Schema

An error wrapper is an object that can be thrown, and all design error objects are inherited from the Java.lang.Throwable class (Java.lang.Error, java.lang.Exception for two of its subclasses). Generally, when error throws, it is basically not handled. If a method declaration will throw a throwable or subclass instance, not error and runtimeexception and its subclasses, it must be handled with a try catch.
Exception and its sub-objects, not less than runtimeexception or its child objects, are called Check exceptions (compiled by the compiler), and the program thinks you have the ability to handle errors and you need to deal with them. At the same time should pay attention to the timing of the error, whether it can be processed in time.
If the parent exception object catches before the subclass exception object, then the chunk of the catch subclass exception object will never be executed, so pay attention to the order of snapping.
You can use multiple snaps to simplify the program (note that there are no inheritance relationships).

8.1.3Throw or Catch

If an exception occurs in the method design process, and you do not have sufficient information to know how to handle it, you can throw an exception and let the client calling the method handle it. After a partial error has been processed, you can use throw to throw the exception again, but you must use the throws declaration on the method (the exception is being inspected)

8.1.4

After the partial exception is processed, you can re-throw the exception, in order to display the error more accurately, you can customize the exception by

8.1.5Stacktrace

Printstacktrace can be used to track errors and use StackTrace. Use the Fillinstacktrace () method to reload the exception stack, set the starting point to be the place to throw the exception, and return the Throwable object.

8.1.6assert

Used to determine if a program executes a time point or whether it is in a specific state, or not, to stop the program from modifying it.
Assertion commonly used in several cases:
1, pre-condition preparation (private method) 2, the call method after the commitment effect 3, the Assert object at a time point under the State 4, replace the annotation 5, the assert will not be executed to the part of 6, can not have the status of default

8.2 Exception and resource management 8.2.1finally

If there is an error in the try block, the finally block is bound to be executed if there is a finally block. Also note that if the program process returns first with a finally chunk, then the finally chunk is executed first and then the return value.

8.2.2try-with-resources

Automatically trying to close a resource is to help you close the resource instead of using exception handling, and when you use this syntax, do not attempt to write your own program code to close the resource.

8.2.3java.lang.autocloseable

An interface that is manipulated by the try with resources syntax.

Nineth Chapter 9.1collection9.1.1collection Architecture

Record the index order of each object and retrieve the object by index, such behavior is defined in Java.lang.list, and if you want the object to be non-repeating, it is defined by Java.util.Set; If you use Java.lang.Queue as a queue. (The requirements for different collection objects operate on different interfaces, inheriting different classes).

9.1.2List

Keep the collection object in an indexed fashion, one of the operation classes is Java.lang.ArrayList
The difference between ArrayList and LinkedList: (one is the sequential storage structure, one is the chain storage structure, each has advantages and disadvantages)
ArrayList: Arrays are contiguous storage spaces in memory and do not fit in the index order, but are accessed faster.
LinkedList: Low storage efficiency, not suitable for sorting, but fewer actions required to adjust the index order.

9.1.3Set

You can use the set interface to manipulate objects when there are requirements that do not collect the same objects. In Java, the Hashcode () and the Equals () method are called when the object is judged to be duplicated, and two methods are best to operate simultaneously.

9.1.4Queue

When the object is collected, the end is added, the object is obtained from the front segment (a bit like a stack, advanced post-out, LIFO), the queue itself defines the offer, poll, peak and other methods (each has its own function)
If you need to operate on the front and end of the queue, you can use some of the behaviors defined in deque.

9.1.5Generics

When designing an API, you can specify that a class or method supports generics, so that objects are re-played as a type, making the syntax more concise.

9.1.6Lambda

The lambda syntax expression omits the interface type and method name,-> left-hand column, the right is the method body

9.1.7Interable Interator

Iterator () The Java.util.Interator method returns the operand of the interface, which can be used Hasnext () to see if there is no next object, interable can be used in the enhanced for () loop, and the feeling is that the above structure has been made a uniform, convenient from the inside value output.

9.1.8Comparable Comparator

Collection provides a sorted algorithm, but must have an index, so the sort () method accepts the action object of list.
Comparator: The interface used for sorting

9.2map9.2.1map Operation class 9.2.2 access key value

HashMap, TreeMap for two common operation class: establish the key value corresponding, you can use the puts () method, the key will not repeat, HASHMAP key value is established, the key is unordered, want to order can use TreeMap.

Problems in teaching materials learning and the solving process

After-school exercises:
Ch8:c C b ACD ACD CD B a A A

CH9:CD AB C D d A ABC c c CD

Problems in code debugging and the resolution process

Other (sentiment, thinking, etc., optional)

These two chapters don't feel good to understand, exception handling this and the Nineth chapter seems to be the data structure in Java, more complex than before, a lot of classes, many kinds of syntax, inheritance architecture also obviously become abstract, there are many things with the API, to be good at checking Api,java in the class too much, do not need to remember all, But it will be checked and used. The program is through continuous learning, a little piece of patchwork out.

Learning progress Bar

Lines of code (new/cumulative Blog volume (Add/accumulate) Learning time (new/cumulative) Important growth
Goal 5000 rows 30 Articles 400 hours
First week 150/200 2/2 15/20
Second week 400/500 3/4 32/35
Third week 800/1000 4/5 55/60

Week Four 1000/1300 5/6 75/80
Week Five 1700/2000 6/7 90/95 I didn't learn much this week.
Resources
    • Java Learning Notes (8th Edition)
    • Java Learning Note (8th Edition) Learning Guide
- ...

20145311 Java Programming 5th Week of study summary

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.