20165231 2017-2018-2 "Java Programming" 5th Week study Summary

Source: Internet
Author: User

Summary of the contents of learning materials Seventh internal class

Declaring another class in one class is called an inner class, whereas a class containing an inner class becomes an outer class of an inner class.
class variables and class methods cannot be declared in the class body of an inner class. An outer class can declare an object as a member of an outer class in the class body of a nested class.

Rules for using internal classes:

    • Declaring an inner class is like declaring a method or variable in a class, and a class considers an inner class to be its own member.
    • An object in the class body of an outer-nested class that can be declared with an inner class as a member of an outer-nested class.
    • The member variables of the outer-nested class are still valid within the inner class, and methods within the inner class can also invoke methods in the outer-nested class.
    • Class variables and methods cannot be declared in the class body of an inner class.
    • The outer and inner classes generate two. class files at compile time.

      Anonymous class

      Create a subclass object directly using the class body of a subclass of a class. When creating a subclass object, in addition to using the constructor of the parent class, there is a class body, which is considered to be a subclass that removes the class declaration after the class body, called the anonymous class.

Exception class

The so-called exception is the program to run a number of errors may occur, such as trying to open a nonexistent file, etc., exception handling will change the program control process, so that the program has the opportunity to deal with the error. When the program runs abnormally, the Java runtime creates an exception object with the corresponding subclass of the exception class exception and waits for processing.

Try~catch statements

Java uses the Try~catch statement to handle exceptions, placing possible exception operations in the try portion of the Try~catch statement, and placing the processing after an exception in the Catch section.

Format:

  try {      包含可能发生异常的语句 } catch(ExceptionSubClass1  e) {    … } catch(ExceptionSubClass2  e) {    … }

A try~catch statement with a finally child statement with the following syntax:

      try{}     catch(ExceptionSubClass e){ }     finally{}
The execution mechanism executes the finally child statement after executing the Try~catch statement, that is, the finally child statement is executed regardless of whether an exception occurred in the try part. Tenth properties of the file
    • The following methods of the file class get some information about the files themselves.
    • Public String GetName () Gets the name of the file.
    • The public boolean canRead () determines whether the file is readable.
    • The public boolean canWrite () determines whether the file can be written.
    • public Boolean exits () determines whether the file exists.
    • public long length () Gets the length of the file (in bytes).
    • Public String GetAbsolutePath () Gets the absolute path of the file.
    • Public String getParent () Gets the parent directory of the file.
    • public boolean isfile () determines whether the file is a normal file, not a directory.
    • public Boolean Isdirectroy () determines whether the file is a directory.
    • public Boolean Ishidden () determines whether the file is a hidden file.
    • Public long lastmodified () Gets the time the file was last modified.
Directory

1. Create a Directorypublic boolean mkdir()
2. List the files in the directory:
- public String[] list() returns all files under the directory as a string.

    • public File [] listFiles()Returns all files under the directory as a file object.
    • public String[] list(FilenameFilter obj)Returns all files of the specified type under the directory as a string.
    • public File [] listFiles(FilenameFilter obj)Returns all files of the specified type under the directory in the form of a file object.
    • The parameter filenamefilter of the two methods above is an interface that has a method:
      public boolean accept(File dir,String name);
Creation and deletion of files
    • Creating files: File File=newFile("c:\\myletter","letter.txt");
      (If the C:\myletter directory does not have a name of letter.txt file, file object is called methodpublic boolean createNewFile();

    • To delete a file:public boolean delete()

      File byte input stream

      The Java.io package provides a large number of stream classes, and Java creates a stream object of the subclass of the InputStream abstract class called the byte input stream; The OutputStream stream object created by the subclass of the abstract class is called the byte output stream. Java is a stream object created by a subclass of an Reader abstract class called a character input stream; a Writer stream object created by a subclass of an abstract class is called a character output stream.

    • The use of input flow often includes 4 basic steps:
      (1) Set the source of the input stream
      (2) Create an input stream that points to the source
      (3) Let the input stream read the data in the source
      (4) Close the input stream.

    • The use of output flow often includes 4 basic steps:
      (1) Give the destination of the output stream
      (2) Create an output stream pointing to the destination
      (3) Let the output stream write the data to the destination
      (4) Turn off the output stream.

Problems in code debugging and the resolution process
    • Issue 1: Error prompting when running example7_2.
    • Issue 1 Solution: do not pay attention to the code semicolon location and the code range within parentheses.
Code Hosting

Last week's summary of the wrong quiz
    • The wrong problem 1:jdb debugging, failed to understand test instructions, the class is not proficient in practice.
    • Error 2: Recursive, code not combined successfully. In order to understand test instructions, the independent combination code exercise is not enough.
Pairing and mutual evaluation

Sentiment

With the course in-depth, the content of the course more and more difficult to understand, especially the tenth chapter content, understand very laborious, hope that the teacher can do more in class explanation and practical operation examples.

Learning progress Bar
lines of code (new/cumulative) Blog Volume (Add/accumulate) Learning Time (new/cumulative) Important Growth
Goal 5000 rows 30 Articles 400 hours
First week 200/200 1/4 10/10
Second week 300/500 1/5 10/20
Third week 800/1300 1/6 20/40
Week Four 700/2000 2/8 20/60
Week Five 1100/3100 2/10 30/90
Week Six / / /
Seventh Week
Eighth Week

Reference: Why is it so difficult to estimate software engineering applications, software engineering estimation methods

    • Planned study time: 30 hours

    • Actual learning time: 30 hours

Resources
    • Java Learning Notes (8th Edition)

    • Java Learning Note (8th Edition) Learning Guide

20165231 2017-2018-2 "Java Programming" 5th Week 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.