Java EE Fundamentals (19)/Exceptions and file

Source: Internet
Author: User
Tags throwable try catch

1. Exceptions (Overview and classification of exceptions)
    • A: Overview of exceptions
      • An exception is an error that occurs while the Java program is running.
    • B: Classification of exceptions
      • View Throwable via API
      • Error
        • Server downtime, database crashes, etc.
      • Exception C: Abnormal inheritance system
      • Throwable
        • Error
        • Exception
          • RuntimeException
2. Exceptions (how the JVM handles exceptions by default)
    • A:JVM The default is how to handle exceptions
      • When the main function receives this problem, there are two ways to handle it:
      • A: Handle the problem yourself, then continue running
      • B: There is no treatment for yourself, only the JVM that calls main to handle
      • The JVM has a default exception handling mechanism that handles the exception.
      • and the name of the exception, the exception information. The location where the exception occurred is printed on the console, and the program stops running
    • B: Case Demo
      • How the JVM handles exceptions by default
3, exception (Try...catch way to handle exception 1)
    • A: Two ways of exception handling
      • A:try...catch...finally
        • Try Catch
        • Try Catch finally
        • Try finally
      • B:throws
    • B:try...catch basic format for handling exceptions
      • Try...catch...finally
    • C: Case Demo
      • Try...catch handles 1 exceptions in a way
4, exception (Try...catch way to handle exception 2)
    • A: Case Demo
      • Handling multiple exceptions in a try...catch way
      • How to handle multiple anomalies after JDK7 and precautions
5. Exception (difference between compile-time exception and run-time exception)
    • A: Differences in compile-time exceptions and run-time exceptions

      • Exceptions in Java are divided into two main classes: compile-time exceptions and run-time exceptions.
      • All instances of the RuntimeException class and its subclasses are called run-time exceptions, and other exceptions are compile-time exceptions

      • Compile-time exceptions

        • The Java program must show processing, or the program will have an error and cannot be compiled
      • Run-time exception
        • No need to display processing, or to be treated as a compile-time exception
    • B: Case Demo
      • Differences between compile-time exceptions and run-time exceptions
6. Anomalies (several common methods of throwable)
    • Several common methods of a:throwable
      • A:getmessage ()
        • Gets the exception information that returns the string.
      • B:tostring ()
        • Gets the exception class name and exception information, which returns a string.
      • C:printstacktrace ()
        • Gets the exception class name and exception information, and the location where the exception appears in the program. return value void.
    • B: Case Demo
      • Basic use of several common methods of throwable
7, exception (throws way to handle exceptions)
    • A:throws Way to handle exceptions
      • When defining a functional method, it is necessary to expose the problem to the caller for processing.
      • Then the method is identified by throws.
    • B: Case Demo
      • Examples of throwing at compile-time exceptions and run-time exceptions, respectively
8. Exceptions (Overview of throw and differences from throws)
    • Overview of A:throw
      • In the function method inside some situation, the program can not continue to run, need to jump, with throw to throw the exception object.
    • B: Case Demo
      • Demonstrates the throwing of exception objects and runtime exception objects at compile time, respectively
    • The difference between c:throws and throw
      • A:throws
        • Used after the method declaration, followed by the exception class name
        • Can be separated by a comma with multiple exception class names
        • Represents a thrown exception that is handled by the caller of the method
      • B:throw
        • Used in the body of a method, followed by the name of the exception object
        • Only one exception object name can be thrown
        • Represents a thrown exception, handled by a statement in the method body
9. Exception (the feature and function of the finally keyword)
    • Features of a:finally
      • The statement body that is finally controlled is bound to execute
      • Special case: The JVM exits before execution to finally (e.g. System.exit (0))
    • The role of b:finally
      • Used to free up resources, and in IO stream operations and database operations, you will see
    • C: Case Demo
      • The features and functions of the finally key word
10. Exception (The interview question of the finally keyword)
    • A: Face question 1
      • The difference between final,finally and finalize
    • B: Face question 2
      • If there is a return statement inside the catch, will the finally code be executed? If so, is it before or after return?
11, Exception (Custom exception overview and basic use)
    • A: Why do I need A custom exception
      • Example: Age of person
    • B: Overview of custom exceptions
      • Inherit from exception
      • Inherit from RuntimeException
    • C: Case Demo
      • Basic use of custom exceptions
12. Exception (Exception precautions and how to use exception handling)
    • A: Exception Precautions
      • A: When a subclass overrides a parent class method, the child class's method must throw the same exception or subclass of the parent exception. (father is broken, son can not be worse than father)
      • B: If the parent class throws more than one exception, when the subclass overrides the parent class, it can only throw the same exception or a subset of his, the subclass cannot throw exceptions that the parent class does not have
      • C: If the overridden method does not throw an exception, then the subclass method is absolutely not to throw an exception, if there is an exception in the subclass method, then the subclass can only try, not throws
    • B: How to use exception handling

      • Principle: If the function can be handled within the problem, with a try, if not handled, referred to the caller, which is used throws
      • Difference:

        • Subsequent programs need to continue to run on the try
        • Subsequent programs do not need to continue to run throws
      • If the JDK does not provide the corresponding exception, you need to customize the exception.

13. Exception (Practice)
    • Keyboard input an integer of type int, the binary representation of which is obtained
      • If the input integer is too large, give hints, enter the integer too large please re-enter an integer BigInteger
      • If the input is a decimal, give hints, input is a decimal, please re-enter an integer
      • If you enter a different character, give a hint, enter an illegal character, please re-enter an integer
14. File Class (Overview of the file class and how to construct it)
    • Overview of the A:file class
      • File should also be called a path
        • File path or folder path
        • Path is divided into absolute path and relative path
        • An absolute path is a fixed path, starting with the drive letter
        • Relative path relative to a location, under Eclipse, under current project, under DOS
      • The view API refers to the current path
      • Abstract representation of file and directory path names
    • B: Construction method
      • File (String pathname): Gets the file object based on a path
      • File (string parent, String child): Gets the file object based on a directory and a sub-file/directory
      • File (file parent, String child): Gets the file object based on a parent file object and a sub-file/directory
    • C: Case Demo
      • How to construct the file class
15. File Class (the creation function of the file class)
    • A: Create A feature
      • public boolean createnewfile (): Create file If such a file exists, you do not create a
      • public boolean mkdir (): Create folder if such a folder exists, you do not create a
      • public boolean mkdirs (): Create a folder, if the parent folder does not exist, will help you create it
    • B: Case Demo

      • The CREATE function of the file class

      • Precautions:

        • If you create a file or folder and forget to write the drive path, the default is under Project path.
16. File Class (rename and delete function of file class)
    • A: Renaming and deleting features
      • public boolean Renameto (file dest): Renames the file to the specified file path
      • public boolean Delete (): Delete file or folder
    • B: Renaming considerations
      • If the path name is the same, it is renamed.
      • If the path name is different, it is renamed and clipped.
    • C: Removal Precautions:
      • Delete in Java does not go to the Recycle Bin.
      • To delete a folder, note that the folder cannot contain files or folders
17. File class (The function of judging the file class)
    • A: Judging function
      • public boolean isdirectory (): Determines whether the directory
      • public boolean isfile (): Determines whether the file is
      • public Boolean exists (): Determine if there is
      • public boolean CanRead (): Determines whether it is readable
      • public boolean canWrite (): Determines if writable
      • public boolean Ishidden (): Determines whether to hide
    • B: Case Demo
      • The judgment function of the file class
18. File class (Fetch function of file Class)
    • A: Get Features
      • Public String GetAbsolutePath (): Gets the absolute path
      • Public String GetPath (): Get Path
      • Public String getName (): Get Name
      • public long Length (): Gets the length. Number of bytes
      • Public long LastModified (): Gets the last modified time, millisecond value
      • Public string[] List (): Gets an array of names for all files or folders under the specified directory
      • Public file[] Listfiles (): Gets the file array of all files or folders under the specified directory
    • B: Case Demo
      • The FETCH function of the file class
19. File Class (the file name of the specified suffix in the output specified directory)
    • A: Case Demo
      • Requirements: Determine if there is a file with a suffix. jpg in the E-drive directory, and if so, output the file name
20. File class (Overview and use of the name filter)
    • A: Overview of file name filters
      • Public string[] List (filenamefilter filter)
      • Public file[] Listfiles (filefilter filter)
    • B: Use of File name filter
      • Requirements: Determine if there is a file with a suffix. jpg in the E-drive directory, and if so, output the file name
    • C: Source Code Analysis
      • Source of List () method with file name filter
21. File Class (Recursive)
    • Factorial of 5

Java EE Fundamentals (19)/Exceptions and file

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.