201711671224 "Java Programming" Chapter 7 learning summary

Learning content summary

Interface
• Interface (interface) define the behavior of
• implements
for the "definition of behavior", you can use the interface keyword defines the method interface can not be operated directly labeled abstract, and must be public. To operate an interface class, you must use the implements keyword.

Interface syntax details
• public abstract interface can be omitted
• access can use extends inheritance interfaces, and can inherit multiple interfaces
• Internal Lambda • anonymous former JDK8 local variables in an anonymous inner class, then the local variable must be final

Use interface to define the abstract appearance of behavioral methods to be declared as public.abstract, there is no need to cut can not operate. For convenience, you can also omit public sbstract, the compiler will assist padded.

Emum •
emue defines special class, inherited from java.lang.Enum.
enum constant listed actually public static final, enumerated type and instance.

  • try: for monitoring. The code will be monitored (may throw an exception code) placed inside the try block of statement, when an exception occurs within the try block, the exception will be thrown.

  • catch: to catch the exception. catch used to capture an exception occurs in the try block.

  • finally: finally statement block will always be executed. It is mainly for the recovery of material resources opened in a try block (such as database connections, network connections and disk files). Only finally block, after the execution is complete, it will come back the try or catch block return or throw statement, if finally used in the statement termination method of return or throw, etc., then it will not jump back to perform, direct stop.

  • throw: to throw an exception.

  • throws: used in the method signature for this method may throw exception statement.
  • JAVA abnormal architecture
  • Java exception is an error to identify and respond to the consistency mechanism provided by Java;
  • Java exception mechanism allows program code and exception handling normal separation of business code, to ensure that the program code more elegant, and improve the robustness of the program. In the case of the effective use of the exception, the exception can clearly answer what, where, why these three questions: Exception type answers "what" is thrown, the exception stack trace answered, "in which" throws an exception information to answer "Why" will be thrown.
  • try ... finally usage: Compared with other models of language, finally keyword is the perfect complement to the Java exception handling model. finally the structure of the code is always executed, regardless of whether an exception occurs. Use finally can maintain internal state of the object, and to clean up non-memory resources. Without finally, the code will be very difficult to understand. (Finally block must be used with or try try / catch block. Further, it is impossible to exit the try block without performing its finally block.)
  • Assertion: Generally a program is not prepared to handle an exception by capturing error
  • Use a keyword assert statement assert statement
  • Use -ea enable assertion

Other (perception, thinking, etc.)

no

Reference material

  • "Java Programming"

Guess you like

Origin blog.csdn.net/nemeziz/article/details/84544384