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
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
- 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)
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
- 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)
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
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)
Java EE Fundamentals (19)/Exceptions and file