Java Knowledge points

Source: Internet
Author: User

1. String and StringBuffer (1) string are immutable classes, so when you execute the following code:
String str = ' abc '= str + ' def ';

First of all, ' abc ' and ' Def ' are two separate objects that are compiled to be worshipped in a constant pool. Then execute string str = ' abc ' to point str ' ABC ' to this constant, then str = str + ' def ' will recreate a ' abcdef ' object and point str to this object. So in the above code, we created 3 objects altogether.

(2) StringBuffer is a mutable class, a string object that is often operated on can be defined as StringBuffer, but StringBuffer does not implement the Equals method.
New StringBuffer ("ABC"new StringBuffer ("abc");        System.out.println (Stringbuffer1.equals (StringBuffer2));

The above code returns false. The StringBuffer action string can be used with the Append and delete methods.

(3) string is the final class and cannot be inherited. (4) The difference between string str = "ABC" and string str = new String ("abc")

The first: the "ABC" in STR and the constant pool is the same object.

Second: the "ABC" in STR and the constant pool is a different object.

2. Try Catch finally (1) If there is a return in the try, then the statement execution in finally is not executed? When does it happen?

Perform! Return the result of the operation to the calling function, then execute the statement in Finally, then execute the next code that called the function.

(2) Final, finally, Finalize:

Final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable.

Finally is part of the exception-handling statement structure, which indicates that it is always executed.

Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resource recycles, such as closing the file. The JVM does not guarantee that this method is always called.

3. Hashtable and HashMap

(1) HashMap allows null key names and key values, but Hashtable not.

(2) Hashtable is thread-synchronous security, HashMap is not.

4. Do not finish, dig a big hole slowly fill it ~

Java Knowledge points

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.