SoFunction
Updated on 2025-03-08

Summary of commonly used open source libraries in Java

The endurance of Java is largely due to the good Java ecosystem. In daily development, we will often use various open source libraries and tool classes. In order to avoid duplicate wheel creation, this article will post some open source libraries and tool classes that will be used in work and study. The Java ecosystem is too big, so we can only list some of it here. If you are interested in this, you might as well read their source code.

HTML parser jsoup

1.1 Introduction

jsoup(GitHub addressChinese Documentation) is a Java HTML parser that can directly parse a certain URL address and HTML text content. It provides a very labor-saving API, which can extract and manipulate data through DOM, CSS and jQuery-like operation methods.

1.2 Example

Document document = ("/toutou/")
   .userAgent("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36")
   .get();
  // (document);
  Elements elements = ("");
  for(Element element : elements)
  {
  Elements eleUrl = ("-aw a");
  String strPrjUrl = ("href");
  (strPrjUrl);
  // (strPrjUrl);
  Elements eleTitle = (".title");
  String strTitle = ();
  // (strTitle);
  Elements eleSummary = (".summary");
  String strSummary = ();
  // (strSummary);
  }

Java 8 Stream

2.1 Introduction

The Java 8 API adds a new abstraction called Stream, which allows you to process data in a declarative way. Stream uses an intuitive way similar to querying data from a database with SQL statements to provide a higher-order abstraction of Java set operations and expressions. The Stream API can greatly improve the productivity of Java programmers and allow programmers to write efficient, clean and concise code. This style treats the set of elements to be processed as a stream, which is transmitted in a pipeline and can be processed on the nodes of the pipeline, such as filtering, sorting, aggregation, etc.

2.2 Example

List<Integer> transactionsIds = 
()
  .filter(b -> () == RED)
  .sorted((x,y) -> () - ())
  .mapToInt(Widget::getWeight)
  .sum();

Apache Commons

3.1 Introduction

Apache Commons is a very powerful and comprehensive toolkit that contains many open source tools. Here are some relatively common tools.

3.2 Branches

BeanUtils

Commons-BeanUtils provides wrappers for Java reflection and introspection APIs

Chain

Chain provides a "chain of responsibility model" that implements the organization's complex processing processes.

CLI

CLI provides a simple API for command line parameters, options, option groups, forced options, and more.

Codec

Codec contains some common encoding and decoding algorithms. Includes some voice encoders, Hex, Base64, and URL encoder.

Collections

Commons-Collections provides a class package to extend and add standard Java Collection frameworks

Configuration

The Commons-Configuration tool provides reading assistance for a wide variety of configuration and reference files.

DBCP

Commons-DBCP provides database connection pooling services

DbUtils

DbUtils is a JDBC helper class library that completes database tasks with simple resource cleaning code.

Discovery

Commons-Discovery provides tools to locate resources (including classes) and map service/reference names and resource names by using various patterns.

HttpClient

Commons-HttpClient provides a framework that can work on HTTP protocol clients.

IO

IO is an I/O tool set

JXPath

Commons-JXPath provides tools to manipulate JavaBeans that comply with Java class naming specifications using Xpath syntax. Maps, DOM and other object models are also supported.

Lang

Commons-Lang provides many, many general tool class sets, and provides some extended functions of medium classes.

Launcher

The Launcher component is a cross-platform Java application loader. Commons-launcher eliminates the need for batch processing or shell scripts to load Java classes. .The original Java class comes from the Jakarta Tomcat 4.0 project

Logging

Commons-Logging is a wrapping class implemented by various logging APIs.

Math

Math is a lightweight, self-contained mathematical and statistical component that solves many practical problems that are very general but do not appear in the Java standard language in time.

Net

Net is a network toolset based on NetComponents code, including FTP clients, and more.

Pool

Commons-Pool provides a common object pool interface, a toolkit for creating modular object pools, and a common object pool implementation.

There are many excellent branch tools for Apache Commons, and those who are interested canApache Commons – ComponentsCheck.

3.3 Example

Apache Commons is too big, so here are a few simple examples.

String empty operation

boolean isEmpty = (value);

Get the full name of the class

();

Determine whether the set is empty

boolean isNotEmpty = (list);

Reflection gets all fields of a class

Field[] fields = ();

JSON

4.1 Introduction

JSON has become the most widely used data transmission format, so the processing of JSON in programs is becoming more and more common. This article mainly introduces Jackson and Google Gson.

4.2 Jackson

Jacksonis a multi-purpose Java library for processing JSON data. Use it to easily convert between JSON data and Java objects.

 ObjectMapper mapper = new ObjectMapper(); 
 User user = (new File(""), );

4.3 Google Gson

GsonIt is a tool library for serializing and deserializing Json released by Google. It can easily implement the transition from Json to Java Object, and it is also very simple to serialize a Java instance into Json. The main classes in the Gson package include Gson, GsonBuilder, JsonParser, etc.

 Gson gson = new Gson();
 String[] strings = {"123", "456", "789"};
 (strings); // ==> ["123", "456", "789"]

log

JAVA also includes logging functions, but it is not excellent in handling log hierarchy, log storage, and log backup and archiving. Therefore, in projects, we generally use third-party log libraries to process logs.

5.1 SLF4J

SLF4JIt provides a simple and unified interface for various logging APIs, so that end users can configure their desired logging APIs implementation during deployment. Logging API implementation can choose to directly implement SLF4J connection logging APIs such as: NLOG4J and SimpleLogger. You can also develop corresponding adapters such as Log4jLoggerAdapter and JDK14LoggerAdapter through the API implementation provided by SLF4J.

5.2 Apache Log4j

Log4j is an open source project of Apache. By using Log4j, we can control the destination of log information delivery to console, files, GUI components, and even socket servers, NT event loggers, UNIX Syslog daemons, etc.; we can also control the output format of each log; by defining the level of each log information, we can control the log generation process more carefully. What is most interesting is that these can be configured flexibly through a configuration file without modifying the application's code.

5.3 Logback

Logback is another open source log component designed by the founder of log4j. logback is currently divided into three modules: logback-core, logback-classic and logback-access. logback-core is the basic module of the other two modules. logback-classic is an improved version of log4j. In addition, logback-classic fully implements the SLF4J API so that you can easily replace it with other logging systems such as log4j or JDK14 Logging. The logback-access access module integrates with Servlet containers to provide the function of accessing logs through Http. Official website:

JUnit

6.1 Introduction

Junit testing is a programmer test, which is called white box testing, because programmers know how (How) the software being tested completes functions and what functions (What) is completed. Junit is a set of frameworks. Inheriting the TestCase class, you can use Junit for automatic testing.

6.2 Example

import ;
import static ;
public class TestJunit {

 String message = "Hello World"; 
 MessageUtil messageUtil = new MessageUtil(message);

 @Test
 public void testPrintMessage() {
 assertEquals(message,());
 }
}

LeetCodeAnimation

7.1 Introduction

You can search online for many "sweeping notes", "sweeping the correct posture of LeetCode" and other sharing. However, there are still some algorithm questions, and the text still cannot help students get the correct method or logic to solve the problem. What should I do at this time? Any good solution? Today, the battalion commander will introduce to you a special nameLeetCodeAnimationopen source project. In this project, text interpretation is not the main thing. The author shows some LeetCode questions or algorithm principles in very vivid and vivid animation.

JavaGuide

8.1 Introduction

JavaGuideCover the core knowledge most Java programmers need to master

Source code address

/toutouge/javademosecond

The above is the detailed content of the commonly used open source libraries in Java. For more information about the commonly used open source libraries in Java, please pay attention to my other related articles!