The seventh chapter of textbook Learning content
- Inner class
Notice the relationship between the inner class and the outer-nested class:
- The member variables and methods of the outer-nested class are valid in the inner class
- 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.
- The inner class is used only for its outer-nested classes, and other classes are not available.
- Create a subclass object directly using the class body of the subclass.
- Anonymous classes can inherit methods from the parent class or override the parent class's methods.
- An anonymous class must be an inner class.
- 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.
- When you create an object with an anonymous class, you use the constructor method of the parent class directly.
- 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.
}
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
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:
- Click the keyboard icon in the upper-left corner of the virtual machine
- Select Letter Symbol Mapping table
- Select the Greek alphabet in the left column
- 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