Hutool Java Utility Library

repository·v5-master·Indexed 12 days ago

https://github.com/chinabugotech/hutool

A comprehensive Java utility library providing practical classes for common development tasks. It includes modules for core utilities (collections, IO, threading, Bean manipulation), encryption (hutool-crypto), HTTP clients (hutool-http), JSON (hutool-json), JDBC wrappers (hutool-db), JWT (hutool-jwt), AI model integration (hutool-ai), and Apache POI wrappers for Excel and Word (hutool-poi). Version 5.x requires JDK 8 or higher.

Tokens
5.2K
Snippets
24
Records
58
Agent score
96%

What's inside Hutool

  1. Overview of Hutool-core

    v5-master
    Hutool-core is the foundational module of the Hutool project. It provides a comprehensive set of basic utility classes designed to simplify common Java development tasks. Key areas of coverage include collections, Maps, IO, threading, Bean manipulation, image processing, and concurrency utilities.
  2. Overview of Hutool components

    v5-master

    Hutool is a comprehensive Java utility library. You can either include all modules using hutool-all or import specific modules individually to keep your project lightweight.

    Key modules include:

    ModuleDescription
    hutool-coreCore utilities including Bean operations, Date, and various Utils
    hutool-cryptoEncryption/Decryption (Symmetric, Asymmetric, and Digest algorithms)
    hutool-httpHTTP client based on HttpUrlConnection
    hutool-jsonJSON implementation
    hutool-dbJDBC wrapper based on ActiveRecord principles
    hutool-extraExtensions for Template Engines, Mail, Servlet, QR Codes, FTP, etc.
    hutool-jwtJSON Web Token (JWT) implementation
    hutool-aiAI Large Model wrappers
    hutool-cacheSimple cache implementation
    hutool-cronScheduled tasks using Crontab expressions
    hutool-captchaImage captcha implementation
    hutool-poiWrappers for Apache POI (Excel and Word)
    hutool-bloomFilterBloom Filter implementation
    hutool-dfaMulti-keyword searching based on DFA model
    hutool-aopJDK Dynamic Proxy for AOP support without IOC
    hutool-logLog facade that automatically identifies logging implementations
    hutool-socketSocket wrappers based on Java NIO and AIO
    hutool-systemSystem parameter wrappers (e.g., JVM info)
    hutool-scriptScript execution wrappers (e.g., Javascript)
    hutool-settingEnhanced Setting and Properties configuration
    hutool-lock(Implicitly part of core/concurrency)
  3. Overview of Hutool Modules

    v5-master

    Hutool is a comprehensive library of Java tools encapsulated through static methods. You can either include all modules via hutool-all or import specific modules individually to keep your project lightweight.

    Key modules include:

    • hutool-core: Core operations (Beans, dates, etc.)
    • hutool-crypto: Symmetric, asymmetric, and digest algorithms
    • hutool-http: HTTP client
    • hutool-json: JSON processing
    • hutool-extra: Third-party wrappers (Mail, QR code, Template engines, etc.)
    • hutool-poi: Excel and Word tools via Apache POI
    • hutool-captcha: Image Captcha generation
    • hutool-jwt: JSON Web Token implementation
    • hutool-db: Database operations using ActiveRecord patterns
    • hutool-cache: Simple caching mechanisms
    • hutool-cron: Task scheduling with Cron expressions
  4. Use the JWT module for token management

    v5-master

    Starting from version 5.7.0, Hutool includes a dedicated JWT (JSON Web Token) module. It provides capabilities for creating, parsing, and validating JWTs. The module includes JWTValidator and RegisteredPayload classes. Note that in version 5.7.3, the default JWT behavior was changed to be ordered, and the payload date format was standardized to seconds.

    // Available since 5.7.0
    // Includes JWT creation, parsing, and validation
  5. Use Bean properties with @Alias annotation

    v5-master

    In version 5.2.0, Hutool added support for the @Alias annotation on Bean fields. This annotation is respected during various operations, including converting Beans to Maps and vice versa, and when using ReflectUtil.getFieldValue.

    public class User {
        @Alias("user_name")
        private String name;
    }
    // ReflectUtil and Bean conversion tools will now recognize "user_name" as the field key.
  6. Hutool-core available utility modules

    v5-master

    Hutool-core is organized into several functional modules. Depending on your requirements, you can use specific utilities for:

    • Data & Transformation: bean (Bean manipulation), convert (Universal type conversion), codec (BaseN, BCD, PunyCode, etc.), text (String manipulation, CSV), math (Permutations, combinations).
    • Collections & Maps: collection (Iterators and collection wrappers), map (Table implementations, WeakMap), stream (Stream API wrappers).
    • IO & Files: io (Stream copying, Checksum, File watching), compress (Zip, Gzip, Zlib).
    • Concurrency & Threading: thread (Locks, CompletableFuture, Thread pools), lang (Design patterns like Singleton).
    • System & Environment: net (IP, SSL, URL), swing (Desktop/AWT automation), compiler (Dynamic Java compilation).
    • Specialized Utilities: date (Date/Time parsing/formatting), img (Image/GIF processing), exceptions (Exception handling), util (Regex, XML, Reflection, Random, etc.).
  7. Install Hutool via Maven

    v5-master

    To include the full suite of Hutool tools in your Java project using Maven, add the hutool-all dependency to your pom.xml file.

    Note: Hutool 5.x requires JDK 8 or higher. If you are using JDK 7, you must use Hutool 4.x (which is no longer updated).

    ```xml
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>5.8.47</version>
    </dependency>
    ```埋
  8. Download Hutool JAR files manually

    v5-master

    If you are not using a dependency management tool like Maven or Gradle, you can download the hutool-all-X.X.X.jar directly from Maven Central.

    Note: Hutool 5.x requires JDK 8 or higher. If you are using JDK 7, you must use Hutool 4.x (which is no longer updated).

    https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.8.47/
  9. Install Hutool via Gradle

    v5-master

    To include the full suite of Hutool tools in your Java project using Gradle, add the following line to your dependencies block:

    Note: Hutool 5.x requires JDK 8 or higher. If you are using JDK 7, you must use Hutool 4.x (which is no longer updated).

    implementation 'cn.hutool:hutool-all:5.8.47'