“This is the third day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021.”
preface
Welcome to our GitHub repository Star: github.com/bin39232820… The best time to plant a tree was ten years ago, followed by now
Hi, everyone, I am small six six, how about today? Let’s take a look at some of the libraries that will help you develop your Java application. If you use them, you will be at least 10 times more productive.
One of the hallmarks of a good and experienced Java developer is a broad understanding of apis, including the JDK and third-party libraries. Almost every programmer knows the rule to “avoid reinventing the wheel” — use a great third-party framework or library whenever possible, but when it comes to actual development, we often forget about those great libraries, as I often see in some project code
if(inputString == null || inputString.length == 0){...... }Copy the code
In addition to string nullness, there are many string manipulation and other data type methods that inexperienced programmers often try to write on their own. There is nothing wrong with this code, of course, but we should try to leverage well-established third-party libraries to solve common problems in a more standard way and improve development efficiency.
In this article, Junior 66 shares some of the most useful and important libraries and apis that Java developers should be familiar with. But does not include a framework, like Spring
20 useful open source libraries for Java programmers
This is a collection of useful third-party libraries that Java developers can use to accomplish many useful functions in their applications. To use these libraries, Java developers should be familiar with them, which is the focus of this article. If you find it useful, you can study the library and use it.
Hutool
Hutool is a small and complete Java tool class library, through the static method encapsulation, reduce the cost of learning related API, improve work efficiency, make Java has the elegant functional language, let the Java language can also be “sweet”.
The tools and methods in Hutool come from the elaboration of each user. It covers all aspects of the Java development code. It is not only a sharp tool to solve small problems in large project development, but also an efficiency responsibility in small projects.
Hutool is a friendly alternative to the util package in a project. It saves developers the time to encapsulate common classes and common tool methods in a project, enables development to focus on the business, and avoids bugs caused by incomplete encapsulation to the maximum.
When we are free, we should read more util so that we can write code with material, which will be much more convenient.
commons-lang3
Apache Commons Lang is the most famous Apache JAVA library (GitHub code library). It is a great extension to java.lang. It contains a large number of very useful utility classes, including StringUtils, DateUtils, NumberUtils, etc. Using StringUtils, the previously mentioned code can be rewritten as:
if(StringUtils.isBlank(inputString)){... }Copy the code
In addition to Apache Commons Lang, there are several other Apache libraries that are good additions to JAVA itself, such as Apache Commons Collection, Apache Commons IO, Apache Commons Math
Logging library
Log libraries are very common because they are required in every project. They are the most important thing for a server-side application, because the logs are only placed where you can see what is going on with the application currently running. Although the JDK ships with its own logging library, there are better alternatives, such as Log4j, SLF4j, and LogBack.
Currently, the most commonly used Java projects are things like Log4j SLF4j and LogBack
JSON parsing library
In today’s World of Web services and the Internet of Things, JSON has become the preferred protocol for transferring information from clients to servers. They have replaced XML as the best way to transfer information between independent platforms.
Unfortunately, the JDK doesn’t have a JSON library. However, there are many excellent third-party libraries that allow you to parse and create JSON messages, such as Jackson and Gson, and FastJson
Under small said some of his own view, be in the project I think no matter you use which a library, you should not refer to their API directly, you should encapsulate a tool you project class, but these tools, not let you to achieve the json conversion, but what you use open source libraries to achieve, such an advantage is that, You would think it would be easier to switch libraries in your project and do uniform exception handling.
Unit test library
Unit testing is the single most important thing that separates the average developer from the best. Programmers often have a reason not to write unit tests, but the most common excuse for avoiding writing unit tests is a lack of experience and knowledge of common unit test libraries, including JUnit, Mockito, and PowerMock.
Talk about unit testing! I don’t know if you can write it in your project, but I think very few of you can write more than 90 percent of your unit tests, and even Spring unit tests aren’t 100 percent! But in general development, because of the schedule, various reasons, we really rarely write, but this code robustness buried a lot of hidden trouble!
HTTP library
The JDK has very little support for HTTP, and I rarely use the native JDK to use HTTP. While you can use classes in the Java.NET package to establish HTTP connections, using open source third-party libraries such as Apache HttpClient and OkHttp3 is not easy or seamless to combine.
HTTP library, I’m sure you’ll use it. Generally, if you use Spring, you might also use Fegin, combined with service discovery, but I think HTTP library refers to external interaction. In fact, there are many internal interaction modes, but most external interaction modes are HTTP
Excel and PDF library
This use is indeed much, upload and download what all need to achieve this, such as Ali easyExcel and POI
This is the import and export, and there is a PDF tool library Itext official website
IText is a project of sourceForge, a well-known open source site, which is a Java class library for generating PDF documents. IText can not only generate PDF or RTF documents, but also convert XML and Html files to PDF files.
The bytecode library
If you’re writing a framework that generates code or interacts with bytecode, you need a bytecode library.
They allow you to read and modify the bytecode generated by your application. Some of the most popular bytecode libraries in the Java world are Javassist and Cglib Nodep.
Javassist (Java Programming Assistant) makes Java bytecode manipulation very simple. It is a class library for editing bytecode in Java. ASM is another useful bytecode editing library. If you are not familiar with bytecodes, I recommend you check out Introduction to Java Programmers for more information about it.
Date and time library
Prior to Java 8, the JDK’s data and time libraries were flawed because they were not thread-safe, immutable, and error-prone. Many Java developers rely on JodaTime for their date and time requirements.
Starting with JDK 8, there’s no reason to use Joda because you get all the functionality in JDK 8’s new date and time API, but if you’re using older Java versions, JodaTime is a library worth learning about.
Email API
Both Javax. mail and Apache Commons Email provide an API for sending E-mail from Java. It builds on the JavaMail API and aims to simplify it.
HTML parsing library
Like JSON and XML, HMTL is another common format that many of us have to deal with. Thankfully, we have JSoup, which greatly simplifies the process of using HTML in Java applications.
Not only can you use JSoup to parse HTML, you can also create HTML documents
It provides a very convenient API for extracting and manipulating data, using DOM, CSS, and jquery-like methods. JSoup implements the WHATWG HTML5 specification and parses HTML into the same DOM, just like modern browsers.
Two-dimensional code processing library ZXing
ZXing, a library that supports decoding and generation of bar codes (such as QR codes, PDF 417, EAN, UPC, Aztec, Data Matrix, Codabar) in images. ZXing(” Zebra Crossing “) is an open source, multi-format, Java-implemented ONE-DIMENSIONAL/two-dimensional barcode image processing library with ports to other languages.
Current knowledge tells us that qr codes exist in the form of squares and store data in a manner similar to binary.
In Zxing, a two-dimensional code is described using a BitMatrix, inside which a matrix array of Boolean – like values is stored. This class abstracts the QR code nicely. ]
P6spy Database performance analysis
P6Spy intercepts SQL statements, acting as a logger for SQL statements, so that we can use it for related analysis, such as performance analysis.
P6spy My understanding is: P6spy has hijacked the data source of the application. P6spy has hijacked the data source of the application. P6spy has hijacked the SQL or HQL statement that needs to be executed. There’s a lot you can do.
MDC Log Dyeing
MDC (Mapped Diagnostic Context) is a feature provided by LOG4J and LogBack to facilitate logging in multi-threaded conditions. It is also a lightweight log tracing tool.
Now that we know that MDC allows us to quickly retrieve usable log information, how do we retrieve it? Let’s start with a scenario like this: Most of the time, we call chain A program can be complicated, and in each invocation chain link, will do log buried to the operation of the key points, such as into and out of the house and complex calculation result and so on information, but in the online environment is many users use our function, such as A program, after every user in the use of A program, I print all the logs in the method call chain of program A. How do I know which of the same logs were printed for the same request? You might say: look at the thread name, HTTP uses the same thread for the same request. To some extent, the thread is ok, but we also know that the web server could not be infinite create threads, inside it there is a thread pool, create, recycling and management for HTTP threads, if the program use frequency is very high, it is entirely possible that in a short period of time of several requests to use the same thread, so it won’t solve the above said: The “find all logs in the call chain in a request” requirement.
Code for reverse engineering a function of MybatisPlus
When using Mybatis, programmers need to write their own SQL statements. The amount of SQL statements for a single table is very large. Mybatis officially provides a tool to generate MyBatis execution code according to database tables.
Reverse engineering: generate code (mapper.xml, mapper.java, POJO…) for database single tables.
At present, there are many such tools, you can also develop a own, CRUD does not have to write is very sweet.
The end of the
Well! In fact, small six six side is to share some commonly used tools, let you know that there is this thing, and so on to really use the time, we go to carefully study ah! Or is free time to study, is also very good! Today to this, I am small 66, three days fishing, two days drying nets!