201621123026 Java programming Tenth week of study summary

Source: Internet
Author: User

Job 10-Exception 1. Summary of this week's study

1.1 Summarize abnormal content in the way you like (mind map 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?

    • Often encounter is NumberFormatException and ArrayIndexOutOfBoundsException .

    • Because they are inherited from, they are not RuntimeException necessarily captured.

    • The simplest way is to handle this part of the problem with a Try-catch statement to facilitate error checking.

1.2 What kind of exception requires the user to be sure to use capture processing?

    • The exception that must be caught. Description A fatal error occurred while writing the code.

    • Errors that may occur when the user enters and operates. This is the time to prompt the user to make a mistake so they need to be captured.

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?

Use the Try-catch statement where there may be a mistake, prompt for an error, and re-execute the statement.

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?

    • Prevent errors from appearing.

    • Let the user know where and why the error occurred.

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?

It is generally a forced type conversion error, such as forcing a string that is not an integral format into an integral type. This time it is passed to the caller that the type cannot be coerced into an integral type of information.

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?

can prompt the user error information, and can re-execute the program without stopping the program, give users a better experience.

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?

The throws keyword should be used. Declares that the throws keyword can prompt the exception and re-execute the program so that the program stops running after an error occurs when the user is in use. Using the throws declaration to customize the information that throws the exception, you can tell the user in more detail what went wrong.

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?

    • Catch exceptions in order.

    • Note that you should catch the subclass exception and catch the parent class first.

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?

    • The subclass exception should precede the parent class exception.

    • An exception in a catch block cannot have an inheritance relationship.

6. Add exception handling to the following code

byte[] content = null;
FileInputStream fis = new FileInputStream ("Testfis.txt");
int bytesavailabe = fis.available ();//Gets the number of bytes available for the file
if (bytesavailabe>0) {
Content = new byte[bytesavailabe];//Create an array that can hold the file size
Fis.read (content);//Read the contents of the file into an array
}
System.out.println (arrays.tostring (content));//print array contents
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?
Like shutting down file resources. File shutdown is not successful and will consume memory. Pay attention to whether the resource you want to close still exists.

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?

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?
The customers of ordinary borrowing books and managers of the book Management system.

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, and perform a borrowing operation for the borrower. Manager's view inventory operations.

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.
You can choose to save the file.

8. Select: Use exceptions to improve your shopping cart system

Give 1 examples of how you can use the exception handling mechanism to make your program more robust.
The description consists of 2 parts: 1. The problem description (where the exception is encountered). 2. Solution (Key Code)

9. Select: Scan your Shopping cart code using the static Code scanning Tool

8.1 Analyze the problems in your own code that arise in terms of specifications.
8.2 Think about how to solve these problems.

3. Code Cloud and PTA

Topic Set: Exceptions

3.1. Code Cloud codes Submission record

In the Code cloud Project, select statistics-commits history-set time period, and then search for and

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
1 98 98
2 338 240
3 535 197
4 705 170
5 818 113
6 1073 255
7 167° 201
8 1451 177
9 1753 302
10 2024 271

Option: 4. Expand

Extracurricular exercises

Javatutorial in questions and exercises
Practice Summary

Extracurricular reading

Select one of the following articles to read and enumerate some of the best practices for exception handling that you can understand.
Best Practices for Exception handling
Exception-handling Antipatterns Blog
The Exceptions debate

Optional: 5. Use Java to solve practical problems (attendance Auto-statistics)

Association check-in, each time using a paper signature table to check in, go back and then manually statistics. If you have more than one signature table, manual statistics are required. Now keep the paper signature method unchanged, responsible for each time the paper signature table will be manually entered after the system, so that the data can be automatically counted. What functional modules are required to implement such a system? Trying to encode the implementation?

201621123026 Java programming Tenth week of study 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.