Java interview Frequently asked Questions

Source: Internet
Author: User
1. The difference between String and StringBuffer

The Java platform provides two classes: string and StringBuffer, which can store and manipulate strings, That is, character data that contains more than one character. This string class provides values that cannot be changed strings and the strings provided by this StringBuffer class are modified when you know that character data is going to change, you can use StringBuffer typically, You can use Stringbuffers to dynamically construct character data

2. The difference between HashMap and Hashtable

HashMap is a lightweight implementation of Hashtable (non-thread-safe implementation), they all complete the map interface, the main difference is that the HASHMAP allows null (NULL) key value (key), due to non-thread-safe, may be more efficient than the Hashtablejava Chinese station Community portal OC) | G| AX, HashMap allows NULL to be used as a Entryde key or value, and Hashtable does not allow HashMap to remove Hashtable thought methods, Change to Containsvalue and ContainsKey because contains thought method is easy to cause misunderstanding Hashtable inherit from dictionary class, and HashMap is an implementation of Java1.2 introduced map interface.

The biggest difference is that Hashtable way of thinking is synchronize, and HashMap is not, when multiple threads access Hashtable, do not need their own way of thinking to achieve synchronization, and HashMap must provide external synchronization.

The Hash/rehash algorithms used by Hashtable and HashMap are probably the same, so there is no big difference in performance.

Java interview Frequently asked Questions

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.