Guava Study Notes: Introduction to Google guava class library

Source: Internet
Author: User
Tags google guava eventbus

Guava is a Google Extension Project Based on java1.6 class library collection, including collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, and so on. these high-quality APIs enable your JavaCodeIt is more elegant and concise, making your work easier and more pleasant. Next we will start the elegant Java programming learning journey!

Project information:

Official documents:
Http:// API = guava

A brief description of the source code package:
Com. Google. Common. Annotations: Common annotation type.

Com. Google. Common. Base: basic tool library and interface.

Com. Google. Common. cache: cache toolkit. It is a simple, easy-to-use and powerful JVM caching tool.

Com. Google. Common. Collect: extension and implementation of generic set interfaces, as well as tool classes. Here you will find many interesting collections.

Com. Google. Common. eventbus: publish a subscription-style event bus.

Com. Google. Common. Hash: Hash toolkit.

Com. Google. Common. IO: I/O toolkit.

Com. Google. Common. Math: a toolkit for primitive arithmetic types and super large numbers. Network toolkit.

Com. Google. Common. primitives: a static toolkit of eight primitive and unsigned types.

Com. Google. Common. reflect: Reflection toolkit.

Com. Google. Common. util. Concurrent: multithreading toolkit.

Class Library User Manual:

I. Basic tools:It makes it even more pleasant to use the Java language.

1. Use and avoid NULL: NULL has language ambiguity, which can lead to puzzling errors. It is always unpleasant. Many guava tool classes directly reject or make errors when encountering null, rather than silently accepting them.
2. Prerequisites: it is easier to test the prerequisites for your method.
3. Common Object Methods: This simplifies the implementation of common object methods, such as hashcode () and tostring ().
4. Sorting: the powerful "fluent comparator" comparator of guava provides multi-Keyword sorting.
5. throwable class: simplifies exception detection and error propagation.

Ii. Collection class:The Collection class library is the extension of the JDK collection class by guava, which is the most complete and well-known part of the guava project.

1. Immutable collections (unchanged set): Defensive Programming, unchangeable set, and improved efficiency.
2. New Collection types (new collection type): Some Collection types not available in JDK collections, including: multisets, multimaps, tables, bidiremaps Al maps, etc.
3. Powerful collection utilities (powerful collection tool class): common operation tool classes not included in Java. util. Collections
4. Extension utilities (Extended tool class): Add a decorator to the Collection object? Implementation iterator? We can use these methods more easily.

III. Cache: Local cache, which allows you to conveniently operate on cached objects and supports various cache failure behavior modes.

Iv. Functional idioms (function type ):Concise: Guava implements Java functional programming, which can significantly simplify the code.

5. Concurrency (concurrency ):Powerful and simple abstraction makes it easier for us to implement simple and correct concurrency code.

1. listenablefuture (monitored future): futures, used for asynchronous callback.
2. Service: control the startup and shutdown of events to manage complex state logic for you.

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

VII. primitives:Extends native type (such as int and char) operations not provided in JDK, including some types of unsigned variables.

8. ranges:Guava is a powerful API that provides comparable range processing, including continuous and discrete situations.

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

10. hashing:Provides more complex hash methods than object. hashcode () and Bloom Filters.

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

12. Math:The optimized math tool class has been fully tested.

13. Reflection:Guava's 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: 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.