Learn Java 13th Day Personal summary

Source: Internet
Author: User

DAY13 Personal Summary

First, abnormal

1 , Concept:

Exception is the program in the run period of abnormal events caused the system to execute an exception, the exception is divided into exceptions and errors, the error is caused inside the JVM, the programmer does not do processing, the following describes the exception and non-examined exceptions.

2. non-inspected exception

A non-checked exception refers to the possibility of an exception in the code, and the code that is likely to have an exception is thrown and processed, non-inspected exception is subordinate to the parent class RuntimeException, the usage is as follows

3. Exception inspected

The exception to be examined is that a code fragment must be an exception, the program at the time of compilation has been an error, the programmer must be processed and thrown exception, the exception is subject to the parent class exception, using the following:

Both the exception and the non-checked exception are caught by Try{}catch () {}finally{} , where the code is loaded in try, Catche () is used to determine the type of the exception, and if yes then execute catch () {} The content in the method body, the code in finally{} is bound to execute, primarily for shutting down the database, and for cleaning up functionality.

Exception and non-inspected exception inheritance graphs:

4. throws and throw the Use

Both are thrown exception, in the usage there is a certain amount of difference between the following

Throw: is mainly used to generate an exception to throw an exception object, in the internal use of the method, you can throw an exception object type, cannot directly throw a subject exception

throws : mainly used to throw exception classes, using the exception type followed by the method name, you can throw multiple exception types at the same time

Second, the internal class

1 , Concept:

Inner classes are divided into member inner classes, static inner classes, local inner classes, and anonymous inner classes, which are primarily used to manage the properties and methods of external classes.

2 , member inner class characteristics:

1) member inner classes are similar to member properties and methods in external classes

2) You can use the four-in-access modifier to decorate public private protected default

3) The Static keyword cannot be used in a member class

4) The properties and methods of an external class can be used within a member's inner class (including private)

5) If the inner class and the external class have the same properties and method names, then the inner class takes precedence over its own properties and methods, and in the inner class This also represents the inner class itself, and if you want to invoke the properties and methods in the outer class, you need to call through the new external class object

6) to create an inner class object, you need to create an external class object, creating an inner class object by creating an outer class object: Through the Outer class object. New inner class ();

7) Create inner class object in other class, need guide Package

3 , static inner class characteristics

1) Similar to the static properties and methods of the external class, defined with the static class name

2) Static or non-static properties and methods can exist

3) If the inner class attribute is the same as the external property name, call the internal if you want to call the external required new object

4) How to create the object: Inner in = new Inner (); When creating a guide package

5) Static internal classes are mainly used in builder mode

4 , local inner class

1) The declaration position of the local inner class is placed in the method

2) cannot use modifier

3) Non-static properties and methods can appear inside

4) Create object: Only in methods that declare inner classes

5) If you want the local inner class to execute, you must call the method that declares the local inner class

5 , anonymous inner class

1) Anonymous inner classes are primarily objects used for interface implementation classes

2) The advantage of an anonymous inner class is that it saves code, but it saves code if it is created once

3) The anonymous inner class is the object that created the subclass, and because it is anonymous, the parent class name is required instead

Learn Java 13th Day Personal 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.