1. Study summary 1.1 This week summarize anomalies in the way you like (mind mapping or other).
2. Written work
This PTA job problem set anomaly
1. Common exceptions
Combined Topic 7-1 Answer
1.1 What exceptions do you often have in code that you have written before, and what do you need to capture (why)? What should be avoided?
- Null pointer: NullPointerException
- Type Input exception: NumberFormatException
- Array out of bounds: arrayindexoutofboundsexception
- Strong turn type exception: ClassCastException
These are not checked exception exceptions, but unchecked exception exceptions, which are best not captured, and you should avoid these exceptions when writing code.
1.2 What kind of exception requires the user to be sure to use capture processing?
Checked exception exception requires the user to be captured. For example, an exception that is caused by a file open failure.
2. Handle exceptions to make your program more robust
Topic 7-2
2.1 Experimental summary. And answer: How can you make your program more robust?
In this case, notice whether the input string contains a non-numeric component, and it is the exception that is caught when it is thrown. To make your program more robust, you should handle the exceptions that are likely to occur.
3. Throw and throws
Topic 7-3
Read Integer.parsetint source code
3.1 Integer.parsetint There is a lot of code thrown out of the exception at the outset, what is the benefit of this practice?
Throws multiple exceptions at the beginning, allowing the user to quickly know that they are using the method to produce an error and know the cause of the error.
3.2 What information do you usually need to pass to the caller when you write your own program with 3.1 and analyze your own method of throwing an exception?
Begin must be less than end,begin to be greater than or equal to 0,end not greater than arr.length. These are the exceptions that the problem needs to be thrown, and in other places it is necessary to judge the input's shape, and throw the corresponding exception to the non-conforming form.
4. Improve Arrayintegerstack with exception
Topic 6-3
4.1 In combination with 6-3 code, how does it benefit to use an exception-throwing method to represent a program run-time error? What is the advantage of returning an error value more than a simple one?
Using a throw exception to represent a program run-time error can make it unnecessary for us to call the method in other places without judging its return value, just by using the Try-catch statement to handle the exception. And comparing the simple return error value, throwing an exception can get a more specific cause of the error.
4.2 If the inner code of a method throws an exception of type RuntimeException, does the method declaration use the throws keyword, and if the exception that is thrown by the method is declared using the throws keyword, what benefit can it bring us?
You can not use throws, because RuntimeException is not checked Exception. You can let us use Try-catch to catch the exception it throws in the place where the method is called, and write the corresponding code as required.
5. Function questions-capture of multiple exceptions
Topic 6-1
5.1 Combined with 6-1 code, answer: If you can throw multiple exceptions in a try block, and there may be an inheritance relationship between exceptions, what do you need to be aware of when capturing?
When using multiple catch statements, be aware that the subclass exception is placed before the parent class exception.
5.2 If you can throw multiple exceptions in a try block, what do you need to be aware of when using Java8 's multiple exception capture syntax?
When using Java8 's multiple exception capture syntax, be aware that the subclass exception is placed before the parent class exception.
6. Add exception handling to the following code
byte[] content = null;FileInputStream fis = new FileInputStream("testfis.txt");int bytesAvailabe = fis.available();//获得该文件可用的字节数if(bytesAvailabe>0){ content = new byte[bytesAvailabe];//创建可容纳文件大小的数组 fis.read(content);//将文件内容读入数组}System.out.println(Arrays.toString(content));//打印数组内容
6.1 Correct the code and add the following functions. When the file cannot be found, you need to prompt the user not to find the file xxx, retype the file name, and then try to open it again. If it is another exception, prompt to open or read the file failed!.
Note 1: There are several methods inside that can throw an exception.
Feature 2: You need to add a finally close file. Regardless of whether the above code produces an exception, always be prompted to close the file ing. If closing the file fails, the prompt to close the file failed!
6.2 Combining the title set 6-2 code, what kind of action to put in the finally block? Why? What do I need to be aware of when closing resources using finally?
To close the file to the finally block, determine in the finally block that the open file variable is not empty when used.
6.3 Use try-with-resources in Java7 to rewrite the above code to automatically close the resource. What are the benefits of this approach?
By using try-with-resources in Java7, you can automatically close a file without writing a finally block, reducing the amount of code and ensuring that the file is closed.
7. Object-oriented design job-Library management system (group completion, no more than 3 students per group)
Log in to lib.jmu.edu.cn to search for books. Then log in to the library information system to view my library. If you want to implement a book borrowing system, try using object-oriented modeling.
7.1 Who is the user of this system?
Borrowing users and administrators.
7.2 Main function modules (not too many) and the owner of each module. Next week everyone is going to submit their own module code and run the video.
?? Log in, register, view information, search for books, borrow, book, return
principal |
Module |
Zheng Yupo |
Search for a book, borrow it, return it |
Jianheng |
Register, login, view information |
7.3 Main class design and class diagram of the system (available)
7.4 How you plan to store library information, address information, reader information, and more.
?? Use one file to store the book information and modify it to resolve the information and to store the reader information in another file.
3. Code Cloud and PTA
Topic Set: Exceptions
3.1. Code Cloud codes Submission record
在码云的项目中,依次选择“统计-Commits历史-设置时间段”, 然后搜索并
3.2 PTA Problem set complete situation diagram
Two graphs are required (1. Ranking chart. 2.PTA Submission list diagram)
3.3 Count the amount of code completed this week
The weekly code statistics need to be fused into a single table.
Week Time |
Total code Amount |
New Code Volume |
total number of files |
number of new files |
2 |
625 |
625 |
99 |
99 |
3 |
1429 |
804 |
113 |
14 |
4 |
3354 |
1925 |
223 |
110 |
5 |
3751 |
397 |
241 |
18 |
6 |
4369 |
31] |
80 |
-161 |
7 |
4998 |
629 |
78 |
-2 |
8 |
5590 |
592 |
87 |
9 |
9 |
5751 |
161 |
89 |
2 |
11 |
6101 |
350 |
97 |
8 |
201621123016 Java programming Tenth week of study summary