20145235 Java Programming 5th Week of study summary

Source: Internet
Author: User

Summary of learning contents of textbook 8.1 Syntax and inheritance architecture
    • The try and catch syntax executes the catch{} statement if the try{} statement appears with a catch () problem.
    • The wrong object is inherited from Java.long.Throwable, which is divided into Java.long.Error and java.long.Exception
    • The error is that the Java program is not able to recover
    • And the exception is divided into non-runtimeexception of the inspected exception and belongs to the runtimeexception exception
    • The exception being examined is the ability of the client that invokes the method to handle the
    • Non-inspected exception will occur when executing, also known as the execution period exception

Code Run Result:

Exception Inheritance Schema
  • Throwable defines methods for obtaining error messages, stack traces, and so on, with two subclasses: Java.lang.Error and Java.lang.Exception
  • Exception handling: Errors in the design of the program itself, it is recommended to use Exception or its subclass instances to behave, so it is often called error handling as exception handling
  • On the syntax and inheritance architecture, if a method declaration throws an instance of Throwable or subclasses, as long as it is not an instance of Error, Ava.lang.RuntimeException, or its subclass, you must explicitly use the try, catch syntax to handle it, or use the Throws declares that this method throws an exception, or it fails to compile
  • Inspected exception: Exception or its child object, but not belonging to RuntimeException or its child object, called a subject exception
  • Execution-time exception (non-inspected exception): Because the compiler does not have to be forced to be syntactically handled, it is also called a non-inspected exception
  • Rule expression: The matches () method of string sets the "\d*", which is the rule representation, that indicates whether the character in the check string is a number, and if so matches () returns true
  • If the parent exception object is caught before the subclass exception object, the chunk of the catch subclass exception object will never be executed
9.1 Collecting objects using Collection
  • Understanding the collection Architecture
  • The behavior of the collection object, such as the Add () method of the new object, the Remove () method of removing the object, are all defined in Java.util.Collection
  • Since the object can be collected, but also to be able to get the object, this is the behavior of java.lang.Iterable definition, it defines the iterator () method to return the java.lang.Iterable operand, you can get the objects collected
  • The common behavior of the collection object is defined in Collection, but the collection object will have different requirements
  • java.util.List: Records the index order of each object at collection time and retrieves objects by index
  • java.util.Set: The collected objects are not duplicated and have the behavior of the collection
  • java.util.Queue: objects are collected in a queue, the collected objects are added to the end, and the objects are acquired from the front end
  • java.util.Deque: You can join, remove, and so on both ends of the queue
  • java.util.ArrayList: Manipulating lists with arrays (an index order when you want to collect objects, one of the ways to do this is to use an array)
  • A List is a collection that collects objects and preserves the order of collected objects in an indexed manner, with one of the operations classes Java.util.ArrayList
  • ArrayList attribute: Considering whether to use ArrayList, it is equal to consider whether to use the attributes of the array. Arrays are contiguous linear spaces in memory, and are fast at random access to the index, and if there is such a requirement on the operation, like sorting, you can use
  • ArrayList, can get better speed performance
  • LinkedList uses the link structure when manipulating the list interface
  • In Simplelinkedlist, a new object is used within the Node wrapper, and each time the Add () object is added, a chain structure is formed
  • If the collected objects often have changes in the index of the situation, perhaps consider the link operation of the list will be better, like a client login or logoff at any time the client list, using LinkedList will have a better efficiency
  • Use the set interface to manipulate objects: if there are identical objects in the process of collecting objects, they are no longer collected repeatedly, and if there is such a requirement, the operands of the set interface can be used

Map with 9.2 key values
  • To obtain the corresponding value according to a key, you can use the Java.util.Map interface's operand to establish the key value corresponding data, and then to obtain the value, as long as the corresponding key can be quickly obtained
  • When you create a Map operand, you can use generic syntax to specify the type of the key and value
  • To establish a key value corresponding, you can use the put () method, the first argument is the key, the second argument is the value
  • For Map, the key does not repeat, the key is determined whether the repetition is based on hashcode () and Equals (), so the object as a key must operate Hashcode () with Equals (). To specify the key to retrieve the corresponding value, use the Get () method
  • If you want the keys to be ordered, you can use TREEMAP. If you use TREEMAP to establish a key value corresponding, the part of the key will be sorted, provided that the object acting as the key must manipulate the comparable interface, or the object that specifies the Comparator interface when the TREEMAP is created.
  • 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
Import java.util.*;p ublic class mapkeyvalue2{public    static void Main (string[] args)     {        map<string, string> map = new treemap<> ();        Map.put ("One", "a");        Map.put ("Two", "II");        Map.put ("Three", "three");        foreach (Map.entryset ());    }    static void foreach (Iterable<map.entry<string, string>> iterable)    {for        (map.entry<string, String> entry:iterable)        {            System.out.printf ("keys%s, value%s)%n",                     Entry.getkey (), Entry.getvalue ());        }    }}

Code Hosting Scenarios

Other (sentiment, thinking, etc., optional)

It's good to study Java in school, even though it's a nice day outside. The outside world is wonderful, but exploring new knowledge in Java is a different universe. Spring is a vibrant season, let us greet the spring breeze, with a new, positive, full of fighting face to learn new knowledge, not negative youth!

20145235 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.