# Guava — Google Core Libraries for Java > Google's suite of core Java libraries covering collections, caching, primitives, concurrency, common annotations, string processing, I/O, and more. ## Install Save as a script file and run: # Guava — Google Core Libraries for Java ## Quick Use ```xml com.google.guava guava 33.4.0-jre ``` ```java import com.google.common.collect.ImmutableList; ImmutableList items = ImmutableList.of("a", "b", "c"); ``` ## Introduction Guava is Google's open-source set of core Java libraries that supplement the standard library. It grew out of Google's internal Java codebase and provides battle-tested utilities used across thousands of production services. ## What Guava Does - Provides immutable collections (ImmutableList, ImmutableMap, ImmutableSet) that prevent accidental mutation - Offers a powerful in-process caching API (LoadingCache, CacheBuilder) with size and time-based eviction - Includes utilities for concurrency such as ListenableFuture and RateLimiter - Supplies string utilities (Splitter, Joiner, CaseFormat) and precondition checks - Adds functional-style helpers, hashing (Murmur3, SHA), I/O helpers, and math utilities ## Architecture Overview Guava is a single JAR of pure Java with zero transitive dependencies. It is organized into packages by domain: com.google.common.collect for collections, com.google.common.cache for caching, com.google.common.util.concurrent for concurrency, and so on. Each package is self-contained and follows Google's strict API compatibility guarantees. ## Self-Hosting & Configuration - Add the Maven or Gradle dependency; no external service required - Choose the `-jre` artifact for Java 8+ or `-android` for Android and older JVMs - Configure caching via CacheBuilder with maximumSize, expireAfterWrite, or expireAfterAccess - Use @Beta-annotated APIs with caution as they may change between releases - Guava follows semantic versioning; deprecated APIs are removed after a deprecation period ## Key Features - Immutable collections that are inherently thread-safe and memory-efficient - LoadingCache with automatic loading, eviction policies, and statistics - ListenableFuture and Futures utilities for composable async programming - RateLimiter for smooth client-side rate limiting - EventBus for lightweight publish-subscribe within a JVM process ## Comparison with Similar Tools - **Apache Commons Lang** — focuses on java.lang extensions; Guava covers a broader surface including collections and caching - **Eclipse Collections** — richer primitive collections but lacks Guava's caching and concurrency utilities - **Caffeine** — superior standalone cache (inspired by Guava Cache) but does not provide collections or I/O helpers - **Vavr** — functional collections for Java; heavier API surface and learning curve ## FAQ **Q: Is Guava still actively maintained?** A: Yes. Google releases multiple updates per year and uses Guava extensively in production. **Q: Should I use Guava Cache or Caffeine?** A: For new projects, Caffeine is recommended for pure caching. Guava Cache is adequate for existing codebases already depending on Guava. **Q: Does Guava work with Java 21+?** A: Yes. The -jre artifact supports the latest LTS Java versions. **Q: What is the difference between -jre and -android artifacts?** A: The -jre artifact targets Java 8+ and includes APIs using newer JDK types. The -android artifact avoids those for compatibility with Android and older runtimes. ## Sources - https://github.com/google/guava - https://guava.dev/ --- Source: https://tokrepo.com/en/workflows/d6d9fb6f-433e-11f1-9bc6-00163e2b0d79 Author: Script Depot