Java Fifth Week study summary

Source: Internet
Author: User

20145307 "Java program design" Fifth week study summary textbook Learning content Summary C8

Use try, catch to package System.in.read (), declare throws Java.io.IOException.

• If the parent exception object is caught before the subclass exception, the chunk of the catch subclass exception object will never be executed.

The exception listed in catch brackets must not have an inheritance relationship, or a compilation error will occur.

• After a partial error is processed in the catch block, the exception can be thrown again using throw.

• When a handle object exception cannot be handled using try, catch processing, the client side of the method can be processed by the link information that was called at the time, using the throw declaration to throw the exception type or parent class.

• If you use inheritance, a method of a parent class declares throws some exceptions, and the subclass can redefine the method when it: ① does not declare throws any exception ②throws some exceptions declared in the method by the parent class ③throws the parent class that declares the exception in the subclass ④throws the parent class in the method that declares the exception in ⑤throws parent class. Under the multiple method invocation, the exception point may be in a method, if you want to know the origin of the exception, as well as the stack propagation under the multiple method call, you can take advantage of the stack trace automatically collected by the exception object to obtain the relevant information, such as calling the Printstacktrace () of the exception object.

· Fileutil in the scanner with FileInputStream to read the document, in fact, the scanner object has a Close method, You can turn off scanner related resources and collocation fileinputsream. The assertion is that an execution point in the decision program must be or is not a state, so it cannot be used as a judgment like if, and assert should not be part of the program execution process.

• If you want to finally perform the action of closing the resource, try, catch syntax can be paired with finally, regardless of whether there is an exception in the try block, if a finally block is written, then the finally block will be executed.

• If the program is written first return. And there is a finally block, then this chunk will be executed first and then returned with the return value.

• Attempt to close resource syntax: An object that wants to attempt to automatically close a resource is written in parentheses after the try, and if no catch is required to handle any exceptions, you can not write or compose finally and try to close the resource yourself.

• Try to close the resource syntax of the applied object, you must manipulate the Java.lang.AutoCloseable interface

• Attempting to close resource syntax can also close more than two object resources at the same time, as long as the middle is separated by semicolons

C9

· Javase provides APIs to meet a variety of requirements, and the behavior of collecting objects is defined in the java.collection, which can both collect objects and expel objects.

• If your phone has an index order, you can use an array.

· List is a collection that collects objects and preserves the order of objects in the cell by index

· Arraylistarraylist characteristics: Arrays in memory will be continuous linear space, according to the index random access speed, if the operation of such requirements, such as sorting, you can use ArrayList, can get better speed performance.

· LinkedList uses the link structure when manipulating the list interface.

• If there are identical objects in the collection process, the collection is no longer repeated, and if there is such a requirement, the set interface's operand can be used.

· The concept of hashset is to open space in memory, where each space will have a hash code. The queue inherits from collection, so it also has the collection add (), remove (), Element () methods, but the queue defines its own offer (), poll () and peek (), etc. One of the main differences is that when a method such as add (), remove (), element () fails, an exception is thrown, and a specific value is returned when a method operation such as offer (), poll () and Peek () fails.

• If an object has an operation queue and is intended to be used in queues with limited queue length, it is generally advisable to use the offer (), poll (), and Peek () methods. LinkedList not only operates the list interface, but also operates the queue behavior, so the LinkedList can be used as a queue.

• The front and tail of the queue are manipulated, the object is added to the front end and the object is fetched, the object is added to the end and the object is fetched, and the sub-interface of the deque defines such behavior Java.util.ArrayDeque operates the Deque interface and can use Arraydeque to manipulate a stack with limited capacity. Generic Syntax: The class name has corner brackets <>, which means that this class supports generics. The object that is actually joined is the type of the client declaration.

• Anonymous class syntax, the syntax of the lambda expression omits the interface type and method name,-> the left side is the parameter column, and the right is the method body, when using a block in a lambda expression, if the method must have a return value, you must use return in the chunk. The Interator () method is promoted to the new Java.util.Iterable parent interface.

· The collections sort () method requires that the ordered object must manipulate the Java.lang.Comparable interface, which has a CompareTo () method that must return a number greater than 0, equal to 0, or less than 0 The collections sort () method has another overloaded version that accepts the operands of the Java.util.Comparator interface, and if this version is used, the order is determined by the compare () definition of comparator.

• In the Java specification, the order-related behavior, usually either the object itself is comparable, or the other specifies that the comparator object tells how to sort, to get the corresponding value according to a key, The Java.util.Map interface can be used in advance to establish the key value corresponding data, and then to obtain the value, as long as the corresponding key can be quickly obtained. The commonly used map operation classes are JAVA.UTIL.HASHMAP and Java.util.TreeMap, which inherit from the abstract class Java.util.AbstractMap.

· Map also supports generic syntax, such as an example of using HashMap:

• If you use TreeMap to establish a key value corresponding, the part of the key is sorted, provided that the object that is the key must manipulate the comparable interface, or the object that specifies the comparator interface when the TreeMap is created.

The properties class inherits the map interface from the hashtable,hashtable operation, and the properties naturally have map behavior. Although you can also use the put () set key value corresponding, get () method to specify the key retrieval value, but the general properties of SetProperty () specifies the string type of key value, GetProperty () specifies the string type of the key, retrieving the value of the string type, Typically called property names and property values.

• If you want to get all the keys in the map, you can call map keyset () to return the set object. Since the keys are not duplicated, it is a matter of course to return with the set operation, and if you want to get all the values in the map, you can use values () to return the collection object.

• If you want to get the key and value of the map at the same time, you can use the EntrySet () method, which returns a set object, each of which is an map.entry instance. You can call Getkey () to get the key and call GetValue () to get the value.

Problems in code debugging and the resolution process

This week I did not beat the code, just a simple reading summary of knowledge points, Ching Ming holiday a day in advance to start the actual study of 89 chapters.

Java Fifth Week 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.