The longevity of Java is largely due to its good ecology. In daily development, we often use various open source libraries and tool classes. In order to avoid repeating the wheel, this article will post some open source libraries and tool classes that will be used in work and study. The Java ecosystem is just too large to list here. If you’re interested, read their source code.

The vHTML parser jsoup

1.1 introduction

Jsoup (GitHub address, Chinese document) is a Java HTML parser, which can directly resolve a URL address, HTML text content. It provides a very labor-intensive API for retrieving and manipulating data using DOM, CSS, and jquery-like manipulation methods.

1.2 the sample

The Document Document = Jsoup. Connect (" https://www.cnblogs.com/toutou/ "). The userAgent (" Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36").get(); // System.out.println(document); Elements elements = document.select("div.box.item"); for(Element element : elements) { Elements eleUrl = element.select("div.box-aw a"); String strPrjUrl = eleUrl.attr("href"); setProjUrls.add(strPrjUrl); // System.out.println(strPrjUrl); Elements eleTitle = eleUrl.select(".title"); String strTitle = eleTitle.text(); // System.out.println(strTitle); Elements eleSummary = eleUrl.select(".summary"); String strSummary = eleSummary.text(); // System.out.println(strSummary); }Copy the code

vJava 8 Stream

2.1 introduction

The Java 8 API has added a new abstraction called a Stream that lets you process data in a declarative way. Stream provides a high-level abstraction of Java collection operations and expressions in an intuitive manner similar to querying data from a database with SQL statements. The Stream API can greatly improve the productivity of Java programmers, allowing programmers to write efficient, clean, and concise code. This style treats the collection of elements to be processed as a stream that travels through a pipe and can be processed at the nodes of the pipe, such as filtering, sorting, aggregating, and so on.

2.2 the sample

List<Integer> transactionsIds = 
widgets.stream()
             .filter(b -> b.getColor() == RED)
             .sorted((x,y) -> x.getWeight() - y.getWeight())
             .mapToInt(Widget::getWeight)
             .sum();
Copy the code

vApache Commons

3.1 introduction

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

3.2 branch

BeanUtils

Commons-beanutils provides a wrapper around Java reflection and introspection apis

Chain

Chain provides a “Chain of responsibility pattern” that implements an organization’s complex processing processes.

CLI

The CLI provides simple apis for command line arguments, options, option groups, mandatory options, and so on.

Codec

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

Collections

Commons-collections provides a class package that extends and adds to the standard Java Collection framework

Configuration

Commons-configuration 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 library that performs simple resource cleaning code for database tasks.

Discovery

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

HttpClient

Commons-httpclient provides a framework for working with HTTP clients.

IO

IO is an I/O tool set

JXPath

Commons-jxpath provides tools to manipulate JavaBeans that conform to Java class naming conventions using Xpath syntax. Maps, DOM, and other object models are also supported.

Lang

Commons-lang provides many, many common utility classes that extend some of the functionality of the classes in Java.lang

Launcher

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

Logging

Commons-logging is a wrapper class for various Logging API implementations.

Math

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

Net

Net is a set of networking tools, based on the NetComponents code, including FTP clients and so on.

Pool

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

Apache Commons has a number of excellent branching tools, which you can check out at Apache Commons — Components.

3.3 the sample

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

String null operation

boolean isEmpty = StringUtils.isEmpty(value);
Copy the code

Gets the full name of the class

ClassUtils.getName(String.class);
Copy the code

Determines whether the set is empty

boolean isNotEmpty = CollectionUtils.isNotEmpty(list);
Copy the code

Reflection gets all the fields of a class

Field[] fields = FieldUtils.getAllFields(User.class);
Copy the code

vJSON

4.1 introduction

JSON has become the most widely used data transfer format, and as a result, processing of JSON in programs is becoming more and more common. This article focuses on Jackson and Google Gson.

4.2 Jackson

Jackson is a versatile Java library for working with JSON data. It makes it easy to convert between JSON data and Java objects.

   ObjectMapper mapper = new ObjectMapper(); 
   User user = mapper.readValue(new File("user.json"), User.class);
Copy the code

4.3 Google Gson

Gson is a tool library for serializing and deserializing Json. It is very easy to convert Json to Java Object. It is also very easy to serialize a Java instance to Json. The main classes in the Gson package are Gson, GsonBuilder, JsonParser and so on.

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

V log

JAVA also includes logging functions, but it is not good at dealing with log classification, log storage, and log backup and archiving, so we usually use third-party log libraries to process logs in our projects.

5.1 SLF4J

SLF4J provides a simple unified interface to the various Loging APIs so that end users can configure their desired loging APIs at deployment time. Logging API implementation can either directly implement the LOGing APIs connected to SLF4J, such as NLOG4J and SimpleLogger. SLF4J API implementation can also be used to develop the corresponding adapter such as Log4jLoggerAdapter, JDK14LoggerAdapter.

5.2 Apache Log4j

Log4j is an open source project of Apache. By using Log4j, you can control the destination of log messages to the console, files, GUI components, even the socket server, NT event logger, UNIX Syslog daemon, etc. We can also control the output format of each log; By defining the level of each log message, we can more carefully control the log generation process. The most interesting thing is that these can be configured flexibly through a configuration file without the need to modify the application code.

5.3 Logback

Logback is another open source logging component designed by the log4J founders. Logback is currently divided into three modules: logback-core, logback-classic, and logback-access. Logback-core is the base module for 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 switch to other Logging systems such as Log4J or JDK14 Logging. The logback-Access access module integrates with the Servlet container to provide log access over Http. Official website: logback.qos.ch.

vJUnit

6.1 introduction

Junit testing is programmer testing, known as white-box testing, because programmers know How and What the software being tested does. Junit is a framework that inherits TestCase classes so that you can use Junit for automated testing.

6.2 the sample

import org.junit.Test; import static org.junit.Assert.assertEquals; public class TestJunit { String message = "Hello World"; MessageUtil messageUtil = new MessageUtil(message); @Test public void testPrintMessage() { assertEquals(message,messageUtil.printMessage()); }}Copy the code

vLeetCodeAnimation

7.1 introduction

You can find a lot of “brush notes” and “correct posture to brush LeetCode” on the Internet. However, there are still some algorithm problems, text is still unable to help students get the right method or solve the problem of logic, and how to do at this time? What’s a good solution? Today, the battalion chief will introduce an open source project named LeetCodeAnimation. In this project, text interpretation is not the main task. The author presents some LeetCode topics or algorithm principles in a very vivid and vivid animation form.

vJavaGuide

8.1 introduction

JavaGuide covers most of the core knowledge that Java programmers need to know

V Source code address

Github.com/toutouge/ja…

Other references:

  • GitHub High Score project
  • What are the best Java open source projects to read?
  • Excellent third-party libraries that JAVA programmers must know about
  • The JAVA open source libraries on GitHub that are worth a try
  • Several Java open source libraries worth applying to your project are given to you

About the author: Focus on basic platform project development. If you have any questions or suggestions, please feel free to comment! Copyright notice: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but without the consent of the author must retain this statement, and give the original text link in a prominent place on the page of the article. For the record: all comments and messages will be answered as soon as possible. You are welcome to correct your mistakes and make progress together. Or direct private message I support the blogger: if you think the article is helpful to you, you can click on the lower right corner of the article [recommendation]. Your encouragement is the author to adhere to the original and continuous writing of the biggest power! \