201421123042 Java programming 10th Week of study summary

Source: Internet
Author: User
Tags finally block set time

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?

A: The array is often out of bounds and does not need to be captured because the exception belongs to RuntimeException. If you want to avoid it, you should pay attention to the array boundaries when writing.

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

A: Exceptions for the non-RuntimeException exception class and subclass require that the user be sure to use capture processing.

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?

A: Familiarity with Try-catch and re-entering also requires writing code in catch.

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?

A: Throwing an exception can allow people to focus on the key code, without adding a variety of error judgments to interfere with the logic in the code, all the problems in the back of the unified processing, so that the code logic and error handling separate for easy maintenance.

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?

A: When throwing an exception, the exception is displayed first, and then the reason why this exception occurs.

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?

A: In 6-3, a method that throws an exception is used, and when the code runs out of error, it ends immediately and throws an exception object.
Pros: Simply returning an error value, the function returns a special result after an exception occurs. We need to check the code and analyze the results to know what the exception is, and the way to throw the exception is to get a specific exception directly when the error is run.

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?

A: If the inner code of a method throws an exception of type RuntimeException, then the method declaration can use the throws keyword, but it is not necessary to use the throws keyword.

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?

A: You need to write multiple catch words to catch, and the subclass's exception must precede 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?

Answer: An exception in Catch 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();//获得该文件可用的字节数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. Always prompt, regardless of whether the above code produces an exception 关闭文件ing . If closing the file fails, prompt 关闭文件失败! .
For:

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?

For:

You need to prompt to close the file after reading the file and end the operation, 关闭文件ing and if the file shutdown fails, you need to prompt and 关闭文件ing determine if the file is empty.

Attention:
If the code fis = new FileInputStream("dtestfis.txt"); runs in an error, the null pointer exception is reported, so it can be avoided by judging whether the file fist is empty in finally.

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?

For:

Use try-with-resources to declare that the resource is closed at the end of the declaration, without having to write finally close the resource.

7. Object-oriented design job (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?

A: Users who have borrowed books (in lieu of students in the program) and administrators.

7.2 Main function modules (not too many)

Answer: User:

    • User Registration
    • User Login
    • View Books
    • Borrowing books
    • Return books
      Administrator:
    • Add a book
    • Delete a book
    • View Books
7.3 Main class design and class diagram of the system (available)

For:

7.4 How you plan to store library information, address information, reader information, etc.

A: Store book information using the map key value pair, the key value to store books, value values stored quantity.
Borrowing information is also stored using the Map key value pair
Reader information using Set collection storage

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)
1.

2.

3.3 Count the amount of code completed this week

Need to incorporate weekly code statistics into a single table

Week Time Total code Amount New Code Volume total number of files number of new files
1 0 0 0 0
2 0 0 0 0
3 125 125 2 2
4 141 141 3 3
5 674 647 13 13
6 647 647 13 13
7 695 48 14 1
8 1867 1867 25 25
9 1974 107 29 4
10 2227 253 34 5
11 2473 246 43 9

201421123042 Java programming 10th 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.