A brief analysis of the JDK Source Code tool library in--java.util package

Source: Internet
Author: User


Preface


Jdk,java Development Kit.

We must first realize that the JDK is just a Java base Class library, which is the base class library developed by Sun, and that's it, the JDK itself and the class library we write ourselves to summarize, technically, or at one level, that need to be compiled into bytecode, run in the JRE, The result of JDK compilation is Jre/lib Rt.jar, we learn to use it to deepen our understanding of Java and improve our Java coding level.

All articles in this series are based on a JDK version of 1.7.16.


The content of this section


In this section, the Java.util package contains a library of tools, mainly the collection of related class libraries, followed by regular, compression decompression, concurrency, date and time, and other tool classes.

This article roughly, simple for the Java.util package has a description, will gradually be supplemented by the content, this article is equivalent to a placeholder, so-called first skeleton, to gradually plump


Collection Class


The main interfaces and their inheritance relationships are as follows:

SortedSet---Collection---iterable

List--Collection--iterable

SortedMap-Map

Common classes and their inheritance relationships are as follows:

Hashset/linkedhashset---Set

TreeSet--SortedSet and Set

Arraylist/linkedlist-List

HashMap-Map

TreeMap--SortedMap-Map


Unified appellation: Collection Branch, we call it "aggregation"; map branching, which we call "mapping".

Collection inherits from Iterable, so the classes under it can be accessed either with an iterator iterator or in the form of a for (E e:es), and the map can be used as an element with an object that implements its internal interface entry.

Hashtable and HashMap, they all implement the map interface, Hashtable inherit from the old abstract class dictionary, is thread-safe, hashmap inherit from the newer abstract class Abstractmap, not thread-safe.

HashMap runs null keys and values, and Hashtable does not run null keys and values because:

Hashtable has a method contains method (to determine whether there is a value), if allowed, whether the key or value is NULL, will return NULL, which is easily misunderstood, so the Hashtable is forced to limit, for the null key and value, Direct throw nullpointerexception;

There are no contains methods for HashMap, ContainsKey () and Containsvalues () respectively.

In addition JDK5 started, for the thread-safe map, there is a concurrenthashmap, efficient, and its implementation of thread-safe process, no use of synchronized.


Regular expressions


Import Java.util.regex.matcher;import Java.util.regex.pattern;public class Hello {public static void main (string[] args {Pattern pattern = pattern.compile ("Regular expression"); Matcher Matcher = Pattern.matcher ("Regular expression Hello world, regular expression Hello World");//Replace the first regular data System.out.println ( Matcher.replacefirst ("Java"));}}


Regular expressions are supported in common development languages, but they are not the same for regular support.

JS Regular: http://msdn.microsoft.com/zh-cn/library/ae5bf541 (vs.80). aspx

Python Regular: http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html

Java Regular:

Http://www.blogjava.net/xzclog/archive/2006/09/19/70603.html

Http://www.cnblogs.com/android-html5/archive/2012/06/02/2533924.html

Concurrency related classes


The following sections are simple to use Demo: Http://blog.csdn.net/puma_dong/article/details/37597261#t5


Compression Decompression Class


The following sections are simple to use Demo: http://blog.csdn.net/puma_dong/article/details/23018555#t20


Other tool classes


Date, time, currency, etc.

A brief analysis of the JDK Source Code tool library in--java.util package

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.