20165203 Java programming Fifth week of study summary

Source: Internet
Author: User
Tags assert

The seventh chapter of textbook Learning content
    • Inner class
      Notice the relationship between the inner class and the outer-nested class:
    1. The member variables and methods of the outer-nested class are valid in the inner class
    2. The class body of an inner class can not declare static variables and methods. The class body of an outer-nested class can declare an object with an inner class.
    3. The inner class is used only for its outer-nested classes, and other classes are not available.
    • Anonymous class
    1. Create a subclass object directly using the class body of the subclass.
    2. Anonymous classes can inherit methods from the parent class or override the parent class's methods.
    3. An anonymous class must be an inner class.
    4. Anonymous classes can access member variables and methods in an outer-nested class, but they cannot have static member variables and methods in their own class body.
    5. When you create an object with an anonymous class, you use the constructor method of the parent class directly.
    6. Anonymous classes related to interfaces: if the parameter of a method is an interface type, you can use the interface name and class body combination to create an anonymous object to pass to the method parameter, and the class name must override all methods in the interface.
    • Exception class ( try-catch statement)

      try {
      Contains statements that may have an exception

}
catch (ExceptionSubClass1 e) {
···
}
catch (ExceptionSubClass2 e) {
···
}
注意: 1.各个catch参数的异常类都是Exception的某个子类,表明try部分可能发生的异常,且子类之间不能有父子关系,否则只保留一个即可。 2.也可以自定义异常类。 - 断言(Assert 语句) 1. 断言语句的语法格式 assert Booleanexpression "'

assert booleanExpression:messageException
2. Enable and Close
Run directly in java format, close assertion sentence by default
You can use the java -ea mainClass enable assertion clause

    • 1.格式:  
      try{}
      catch (Exceptionsubclass e) {}
      finally{}
      2.无论The try 是否异常, finally ' child statement will be executed
Tenth Chapter
    • FileClasses: File objects are primarily used to directly obtain some information about the file itself (the directory in which the file resides, the length and the read and write permissions, etc.)

      Construction method
      File(String filename)
      File(String directoryPath,String filename)
      File(File dir, String filename)

Create a Directory
public boolean mkdir

List files in a directory
public String[] list()
public File[] listFiles()
deleting files
public boolean delete()

To run an executable file

Runtime ec;  ec = Runtime.getRuntime();  ec.exec(String command);   
    • Input stream: Read file
    • Output stream: Writing to File
    • file character input, output stream:FileReader,FileWriter
    • Buffered streams: BufferedReader BufferedWriter objects created by and classes
    • Random stream: RandomAccessFile object created by class
    • Array flow: ByteArrayInputStream and ByteArrayOutputStream created objects
    • Data flow: DataInoutStream DataOutputStream objects created by and classes
    • Object flow: ObjeatInputStream ObjectOutputStream objects created by and classes
    • Serialization and object cloning
    • Using Scanner parse files
    • File dialog box
    • Input stream with progress bar
    • File lock
Problems in teaching materials learning and the solving process

Q1: Before, some classmates asked me in the virtual machine, the Greek alphabet how to knock out, here to say a bit.
A1:

    1. Click the keyboard icon in the upper-left corner of the virtual machine
    2. Select Letter Symbol Mapping table
    3. Select the Greek alphabet in the left column
    4. Double-click the letter you want to hit, copy and paste it.


      Run results

Q2: In learning, code, for the exception subclass is not too understand, want to understand exception subclass have what?

A2: I searched, the original textbook NumberFormatException for the character UTF code data format error caused by exceptions thrown exception class, specific reference exception sub-class

Q3: I'd like to summarize the input and output streams in the textbook.
A3:

name explain Construction Method Callable Methods
File byte input stream objects created by using FileInputStream FileInputStream(String name);FileInputStream(File file); int read()``````int read (byte b[]``````int read(byte b[],int off,int len)
File byte output stream Using FileOutputStream the Created object FileOutputStream(String name); FileOutputStream(File file);``````FileOutputStream(String name,boolean append);FileOutputStream(File file,boolean append); void write(int n);``````void write(int n);``````void write(byte b[],int off,int len);
Problems in code debugging and the resolution process

Q: (unresolved) code debugging, there is a situation, but do not know why my file is not readable, but also hope that you help answer.

Code Hosting

Last week's summary of the wrong quiz

Q1:
A1:a. Application this , which super is used to manipulate the hidden member variables and methods, calls the constructor method in the parent class
B. double The default value is 0.0
D. Methods equivalent to functions in C language

Q2:
A2: For UML diagrams, it is common to use normal fonts to represent normal methods, and italic to represent abstract methods.
b, with + for public, and-for private. D, inheritance is represented by a straight line with a triangle, and the child class points to the parent class

Other (sentiment, thinking, etc., optional)

This week's study involves the knowledge that has not been contacted before, is the concept of the anomaly class and the flow, because has not been contacted before, so, accept the knowledge before, slightly slower, but, my method is to see Lou Teacher to the net lesson, first listen to the teacher's introduction, and then read the textbook, see if they can have new understanding and sentiment , I believe that there is this way, I can conquer this difficulty.

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
Week Five 2119/1500 1/2 46/90
Resources

Subclass of exception

20165203 Java programming Fifth 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.