[Guava source daily (1)] Introduction to Guava Class Library

Source: Internet
Author: User
Tags arithmetic pack reflection eventbus

1. Introduction

The Guava project contains a number of core libraries that are heavily reliant on Google's Java projects, including collections, caching, primitives support, concurrency libraries, common Annotations, string processing, I/O, and so on. These high quality APIs can make your Java code more elegant and concise, making your work easier and more enjoyable.

2. Official Information

Official home: Http://code.google.com/p/guava-libraries

Official Download: http://code.google.com/p/guava-libraries/downloads/list

Official documents: Http://docs.guava-libraries.googlecode.com/git/javadoc

Http://www.ostools.net/apidocs/apidoc?api=guava

3. Class Package Description

Class Package Describe
Com.google.common.annotations Common note type
Com.google.common.base Basic tools class libraries and interfaces
Com.google.common.cache Cache toolkit, very simple and powerful JVM cache
Com.google.common.collect Collection interface extensions and implementations with generics, and tool classes
Com.google.common.eventbus Publish subscription-style event bus
Com.google.common.hash Hash tool Pack
Com.google.common.io I/O Tool pack
Com.google.common.math Arithmetic kits for primitive arithmetic types and oversized numbers
Com.google.common.net Network Kits
Com.google.common.primitives Eight original types and unsigned types of static kits
Com.google.common.reflect Reflection Kit
Com.google.common.util.concurrent Multithreading Toolkit

4. Class Library use manual

4.1 Base Basic tool class libraries and interfaces

Look at what kind of changes base has brought to us:

Use and avoid null

Null has a linguistic ambiguity and can cause puzzling errors. Guava's tool classes reject or fail directly in the face of NULL, rather than silently accepting them.

Prerequisite conditions

It's easier to test your methods for preconditions.

Common Object Methods

simplifies the implementation of object-common methods, such as Hashcode () and toString ().

Sort

Guava is a powerful "fluent Comparator" comparator that provides multiple keyword sorting.

Throwable class

Simplifies exception checking and error propagation.

Based on the above, we should look at the above aspects more emphatically when we read the Guava base class package content.

4.2 Collection Collection Class

The Collection class library is an extension of the guava to the JDK collection class, which is the most complete and well known part of the Guava project.

Immutable collections (invariant set)

Defensive programming, a set that cannot be modified, and increased efficiency.

New collection types (newly set type)

The JDK collections does not have some collection types, mainly: Multisets,multimaps,tables, bidirectional maps, etc.

Powerful collection utilities (powerful Collection tool Class)

Common operations Tool classes not included in the Java.util.Collections

Extension Utilities (Extension tool Class)

Add an adorner to the Collection object to implement the iterator.

4.3 Cache caching

Local caching, which facilitates the operation of cached objects and supports various caching failure behavior patterns.

4.4-Functional idioms functional programming

Concise, guava implementation of Java functional programming, can significantly simplify the code.

4.5 Concurrency Concurrency Operations class

Powerful, simple abstraction makes it easier to implement simple and correct concurrency code.

4.6 Strings String Tool class

A very useful string tool class: Provides splitting,joining, padding, and other operations.

4.7 Primitives Type

An extension of operations on native types (such as int, char, etc.) not provided in the JDK, including certain types of unsigned variables.

4.8 Ranges

Guava a powerful API that provides comparable types of range processing, including continuous and discrete situations.

4.9 I/O

Simplifies I/O operations, especially for I/O streams and files, for Java 5 and 6.

4.10 Hashing

Provides a more complex hash method than Object.hashcode (), providing Bloom filters.

4.11 Eventbus

Component communication based on publish-subscribe mode, but does not need to be explicitly registered in the delegate object.

4.12 Math

Optimized math tool class, complete test.

4.13 Reflection

Guava Java Reflection Mechanism tool class.


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.