20145301 Six weeks Study summary of learning Contents Tenth chapter input/output 10.1 InputStream and OutputStream
InputStream and OutputStream
Stream is an abstraction of "input output", noting that "input and output" is relative to the program
InputStream and OutputStream
InputStream, OutStream provides streaming basic operations, and if you want to do processing for input/output data, you can use a wrapper class. The commonly used packager has the function of buffer bufferedoutputstream, Bufferedinputstream, with data conversion processing DataInputStream, DataOutputStream, ObjectInputStream, ObjectOutputStream, etc. with the ability to serialize objects. Read for character data, Java SE provides the Java.io.Reader class, which abstracts the source of character data read-in. The Java.io.Writer class is provided for writing to character data. It abstracts the destination that the data writes out. Write FileReader, FileWriter can read and write to the document, read or write by default using the operating system default encoding to do character conversion. When you start the JVM, you can specify-dfile.encoding to specify the encoding used by the FileReader, FileWriter. Binary file standard input/output system.in: Standard input, default association to keyboard (terminal input) System.out: standard output, default associated to display (terminal output) System.err: standard error, default associated to display (terminal output) Input and output redirection: Setin,setout,seterr FileInputStream and FileOutputStream FileInputStream are subclasses of InputStream, you can specify a file name to create an instance, Once the document is created, it is opened and then can be used to read the data. FileOutputStream is a subclass of OutputStream, you can specify a file name to create an instance, once the document is created, and then it can be used to write data. Use Close () to close the document when not in use, whether FileInputStream or FileOutputStream. File read/write Adorner class decorator mode Bufferedinputstream and Bufferedoutputstream: Provides buffering internally to improve efficiency DataInputStream and DataOutputStream: Basic data type and byte conversion, API study ObjectInputStream and ObjectOutputStream Java.io.Serializable interface character processing class reader and writer REader and writer also have some adorner classes to use. If the byte data that is processed by the stream actually represents the encoded data of some characters, and you want to convert the byte data to the corresponding encoded character, you can use InputStreamReader, outputstreamwriter to package the streaming data. BufferedReader, BufferedWriter can provide buffer function to reader and writer, and it will be helpful to the efficiency when processing character input/output. Printreader and PrintStream are very similar in use, but in addition to OutputStream packaging, PrintWriter can also package writer, providing print (), println (), Format () and other methods. The character processing adorner wants to convert these byte data into corresponding encoded characters, and can use InputStreamReader, OutputStreamWriter to package the stream data. BufferedReader, BufferedWriter can provide buffer function to reader and writer, and it will be helpful to the efficiency when processing character input/output. PrintWriter can also package writer, providing methods such as print (), println (), Format (), and so on.
11th chapter-Thread and parallel API7.1 what is interface
Definition form: interface InterfaceName {...}
The member method defaults to abstract, public, and the member property defaults to static, final decorated
The interface simply provides a form, and the specific implementation details are given to its class to complete
Because the interface does not involve a specific implementation, the member variable in the interface is a static constant variable, which defaults to static and final decoration
class implements an interface: Class MyClass implements A, B, C {...}
A class can implement multiple interfaces
Note: Although there is no explicit declaration method in the interface is public, but the default access control in the interface is public, and the default access control in the class is in-package friendly, the method must be decorated in class with the
Selection of interfaces and abstract classes:
Multiple inheritance is not supported between classes in Java, but classes can implement multiple interfaces
If the class needs to include implementations of some methods, it must be implemented as an abstract class, and in other cases, the use of interfaces is preferred, making the program easier to extend
7.2 Interface Syntax Details
- Use interface to define the appearance of an abstract behavior, which is declared as public abstract, and is not required and cannot be manipulated. For convenience, the public abstract can also be omitted, and the compiler will assist in completing the process. You can use an interface enumeration constant, which can only be defined as public static final. For convenience, you can also omit public static final.
- Interfaces can inherit other interfaces, or they can inherit more than two interfaces at the same time, and also use the extends keyword.
- The enum syntax can be used to define enumeration constants, which actually define the class, and the constants enumerated in the enum are actually public static final, and cannot be written to instantiate the enumeration type directly because the constructor permission is set to private and only in the class can be instantiated.
Problem and resolution process issues
No clear overrides and overloads.
Resolution process
In the blog Park to find a master's see, Special recommendation:
The difference between overloading and overwriting:
- Overloads occur in the same class, overloading requires the same function name, with different parameters (number of arguments | | Parameter Type | | Parameter order). The return type of a particular function does not affect overloading.
1, the mark of the method of covering must match with the mark of the method that is covered completely, can reach the effect of coverage;
2. The return value of the overridden method must be the same as the return of the overridden method;
3. The exception that is thrown by the overridden method must be the same as the exception thrown by the overridden method, or its subclass;
4. The overridden method cannot be private, otherwise only a new method is defined in its subclass, and it is not overwritten.
- Overrides occur between parent and child classes, overwriting also requires the same function name, and the parameters are the same. Coverage follows the principle of "two and two small and one big". The two are the same as the function name and the parameter are the same, two small is thrown the exception is smaller or the same, the return type is smaller or the same; Constructors and static methods support overloading, but they cannot be overwritten. (Construction method and static similarity can also be linked to private and final keywords also have this similarity)
1. You can only pass different parameter styles when using overloads. For example, different parameter types, different number of parameters, different parameter order (of course, several parameter types within the same method must differ, such as can be fun (int, float), but not fun (int, int));
2, can not be overloaded by access rights, return type, thrown exception;
3, the method of the exception type and number will not affect the overload;
Other
- The difference between an abstract class and an interface:
In design philosophy, a class can inherit only one abstract class, but it can implement multiple interfaces.
Abstract classes can contain normal member variables and non-abstract methods, and the member variables and methods of the interface have a fixed decoration. That is, public static final and public abstract. For inheritors, the method subclasses of the abstract class may not all be replicated, but the method abstract class of the interface must be completely replicated.
Abstract classes can also be implements interfaces, can implement methods in the interface, or can not be implemented. Abstract classes can not be final decorated. Abstract classes can contain non-abstract methods. ExperienceThis week, the feeling of learning more difficult, abstract things more and more, the difficulty of understanding gradually increased. Such as: object, encapsulation and other concepts, even if read, can not fully understand. Also can not eat C language strongholds, need I put more time and energy, I need more to expand to learn, not only limited in reading, code code, do not understand the place, I will first yards code, good first retained the problem, to communicate with classmates. I found that the study of blog Park should not only be confined to the small circle of dky, we can take some time to see other masters of the blog to learn, will be very helpful to our study.
Learning progress Bar
| Target |
number of lines of code |
Blog Volume |
Study Time |
Important Growth |
| Goal |
4000 rows |
30 Articles |
400 hours |
---- |
| First week |
100/4000 |
2/30 |
15/400 |
Hello Java |
| Second week |
350/4000 |
3/30 |
40/400 |
Process Control |
| Third week |
500/4000 |
4/30 |
50/400 |
Classes and objects, encapsulation |
| Week Four |
700/4000 |
5/30 |
50/400 |
Inheritance, interfaces |
Resources
- "Java Learning Notes"
- Learning Guide for Java Learning notes
- Bi Xiangdong Java Teaching
20145301 Six weeks Study summary