I need to record some of the things I saw in Sunday, or I'll forget about them.
Hashcode, equals:
1) Each Java object has the Hashcode and equals methods.
The ultimate Java class is the object class, so how does the object class label itself, that is, how the class of object distinguishes each other. is to use their hashcode and equals to infer.
(Hashcode is implemented by the hash algorithm)
2) Every new object in the JVM will be said to throw an object into a hash (hash table), so that the next time to compare or retrieve this object can be based on the object's hashcode to the table to fetch, can improve efficiency.
We have to know that Java has a memory limit, so in theory it is not possible to have unlimited new.
Compare Hashcode First, if there is other data on the list with equals.
We may ask that the direct use of equals does not have to, of course, this is possible. But to see the efficiency of hashcode, the main purpose of hashcode is to reduce each call to equals.
3) questions about rewriting hashcode and equals:
In general, we do not need to rewrite these two functions. Like an integer double of this kind of object, Java has rewritten these two functions for us, which is why as long as the two string content is the same as their equals, it should not be justified, because equals compares the object's reference.
What needs rewriting: when we use the hashmap of the map, we have to rewrite the custom class as the key value, otherwise we won't find the class. Because a class inherits object, it uses the hashcode of object
So two data of the same value, in this case will become two numbers.
is to use a custom key to override it.
/ o:
File class: Can be files, or it can be a file directory. Through the file class we can get a certain property of the files.
Stream: This is a series of data, I can not tell.
Java Input and output: (1) Character output, input stream (Writer, Reader) (2) byte output, input stream. (InputStream, OutputStream)
(as if there were stdio)
Difference
(1) Different reading and writing units
The byte stream is in bytes (8bit) and the character stream is in characters, and each read byte is mappings by the word used.
(2) different processing objects
Byte stream can handle all types of objects (picture, video, text ...) )
Character streams can only be of type
Note: A byte stream cannot be converted directly to character output, because the unit of reading can be converted to a string with the output of the different units being read: