1. Some of the less-commonly used modifiers such as native and synchronized are found in the interview book.
Native: The local method controller. The native modifier is called the local method. To improve the program running speed, you need to use other advanced languages to write the program's method body. Then, this method class is defined as a local method and modified with the modifier native.
Synchronized: synchronous method controller, mainly used for coordinated synchronization in a multi-threaded program.
2. Which classes in JDK cannot be inherited?
We know that all classes modified by final cannot be inherited, which means that I am the final. You cannot inherit, but which classes are modified by final in JDK, cannot be inherited? At least we need to know about it.
Some basic types or extensions cannot be inherited, such as System, String, StringBuffer, etc.
3. Differences between String and StringBuffer
We all know that the String and StringBuffer are different, because the String class is a character String with immutable content, and the StringBuffer class indicates the String that the content can be changed. Further, we do not know.
In fact, there are also strings that overwrite the equals and hashCode methods, but StringBuffer does not, so the StringBuffer object will be saved into the collection class.
I was puzzled for a moment. I thought there was something wrong with saving the data into the set. The result code was tested once and there was no error.
ArrayList al = new ArrayList ();
Al. add (new StringBuffer ("haha "));
System. out. print (al. remove (0 ));
After the execution was successful, I thought about it. It turns out that the comparison in the set will cause an error. The test code is as follows:
ArrayList al = new ArrayList ();
Al. Add (New stringbuffer ("Haha "));
If (! Al. Contains (New stringbuffer ("Haha "))){
System. Out. println ("it seems that stringbuffer does not overwrite the equals and hashcode methods! ");
}
This will cause an error. The "Haha" character string exists in the collection. When a new "Haha" character string is returned, the return value is true, then, the syso statement will not be executed, but the statement is printed out. This shows that stringbuffer does not overwrite two methods!
4. How can I convert a comma-separated string into an array?
Let's take a look at the general idea.
Use a regular expression. The code is probably string [] result = orgstr. Split (",");
Use stingtokenizer. The code is:
Stringtokenizer tokener = stringtokenizer (orgstr ,",");
String [] result = new string [tokener. counttokens ()];
Int I = 0;
While (tokener. hasnext (){
Result [I ++] = Toker. nexttoken ();
}
5. What are your five common runtime exceptions?
Ah? This exists in the interview questions. It seems that you have to remember it. Open the API documentation and check that all the child classes of runtime are available. Find a few familiar ones, such: classcastexception type conversion exception, contains an invalid element exception, indexoutofboundsexception subscript out-of-bounds exception, nosuchelementexception does not have this element exception, nullpointexception NULL pointer exception, and so on, it is easy to expose that you do not have practical experience, and there are few mistakes in code.