I am 3Y, one year CRUD experience with ten years markdown programmer 👨🏻💻

Today I’m going to talk about the things that speed up development: toolkits, Lombok, and common libraries

01. What is a toolkit

Basically, every project has a package called utils. This package is dedicated to hosting our own project’s utility classes, such as the usual DateUtils, HttpUtils, and Collections

Utils is: we use it a lot, but the original API is not good enough, so we wrap it into a more general method

If it is a beginner, many times encountered this kind of similar tool class will not directly write, will go to the search engine to find a. Found after, can feel directly look a CTRL + c, a CTRL + v to their main method a stick, make some test data, see if I can make it work.

If it works, give it a name and put it under utils. After a meal of operation, I found myself this operation posture is perfect!

However, the utility class you want is likely to have already been written with a corresponding JAR package, which is much more reliable than the blog code that a search engine found.

Those who know they exist will always use them well, while those who don’t may always copy what is missing, and the code gets messy.

02. JAVA Toolkit recommended

In the Java space, there are two well-known toolkits in the industry: Commons and Guava

A tool kit maintained by Chinese: Hutool

We can use these toolkits as much as possible in our project code if there is a need for them. Their code is generally better than our own, and utility classes are designed to help us reduce repetitive code, which makes the project more readable.

As for what they can do, if you haven’t, take a look at their Guide to get a sense of what these kits come with. Wait until you realize that you need to package a feature, first look through the documentation of these toolkits, really can not find, do not implement their own.

Do not repeat the wheel, do not repeat the wheel, do not repeat the wheel.

I’ve posted links to these kits at 🔗 if you’re not familiar with them, check them out

  • commons.apache.org/
  • Github.com/google/guav…
  • www.hutool.cn/docs/#/

I have captured part of the hutool document to give you a sense of it. I think it is quite complete:

The module introduce
hutool-aop JDK dynamic proxy encapsulation, providing non-IOC aspect support
hutool-bloomFilter Bloom filtering, which provides some Hash algorithms for Bloom filtering
hutool-cache Simple cache implementation
hutool-core Core, including Bean operations, dates, various utils, and so on
hutool-cron Scheduled task module that provides scheduled tasks like Crontab expressions
hutool-crypto Encryption and decryption module, providing symmetric, asymmetric and digest algorithm encapsulation
hutool-db JDBC encapsulated data manipulation, based on ActiveRecord ideas
hutool-dfa Multi-keyword search based on DFA model
hutool-extra Extension module, encapsulation for third parties (template engine, mail, Servlet, TWO-DIMENSIONAL code, Emoji, FTP, word segmentation, etc.)
hutool-http Http client encapsulation based on HttpUrlConnection
hutool-log Automatic identification of log facade of log implementation
hutool-script Scripts perform encapsulation, such as Javascript
hutool-setting More powerful Setting profile and Properties wrapper
hutool-system System parameters call encapsulation (JVM information, etc.)
hutool-json JSON implementation
hutool-captcha Image verification code implementation
hutool-poi Excel and Word encapsulation for POI
hutool-socket NIO and AIO Socket encapsulation based on Java
hutool-jwt JSON Web Token (JWT) encapsulation implementation

03, LOMBOK

I was introduced to Lombok as an intern. The first thing he gave me was that I didn’t have to generate my own set/get methods anymore

In fact, with the IDE, generating set/get methods is a shortcut, but every time we add/remove/modify a class property, we need to generate an extra one for those changes. But that doesn’t seem to be the case. After all, there isn’t much work to add/delete/modify.

It’s not just set/get that Lombok can do, but I recommend it when you use it. Annotations like @Builder, @slf4j, and @data are used a lot in my projects, so if you’re not familiar with Lombok, check out the Lombok website.

Projectlombok.org/features/al…

Has anyone ever wondered Lombok how he did it? A group member was asked the question: Do you know how Lombok works?

I talked about this in the first article in the Online Interviewer series, Notes. In fact, it is not particularly complicated things, as long as we can figure out the general steps of Java compile time and the basic knowledge of annotations, this problem can be answered.

  1. Annotations have a life cycle@RetentionThere are constants SOURCE, CLASS, and RUNTIME. Using Lombok annotations is the SOURCE phase
  2. .javaWhen a file is compiled, it can be summarized in a few simple steps: parsing -> parsing ->Annotation processing– > class files
  3. The JDK provides hooks, and if we want to do annotation related things at compile time, we can inherit AbstractProcessor and implement the Process method (Lombok does this).

04, JSON libraries

Java backend development is now largely dependent on JSON, so we need a JSON library to do serialization and deserialization for us

  • The interaction between the front and back end interfaces is basically JSON format
  • Sometimes, for convenience, we will directly convert the data into JSON and store it (the storage can be MySQL, HBase, Redis, etc.).
  • .

As I write this, I look through my old study notes from college. When I first learned JSON, I followed the video to learn Spring and Strtus2, both of which had built-in JSON parsing libraries. At that time, I had no difficulty in learning to tune an API from the video, so I didn’t think much of it.

The video tutorial taught me how to easily manipulate JSON without Spring and Struts2, and then introduced a JSON-lib package in the classpath. Looking back at my college notes, IT’s really full of memories…

All right, let’s get back to the present. JSON libraries that are commonly used on Java backends today are FastJSON, Gson, and Jackson

I used to use FastJson a lot in my company. The API is very simple to use and comfortable to use everyday. However, I am someone who has had to force an upgrade to fastjson! I think it was 19, when the security team told us that we needed to force fastjson to be upgraded, probably because Fastjson was bugged and had to be upgraded. We, as library users, have no choice but to upgrade.

As a result, a few days later. The security team pulled a group again, saying that they still need to upgrade the XXX version or above, the previous upgrade version still has a problem… There were other potholes that the team ran into to upgrade the Fastjson version, and they were annoying anyway.

There are also many articles comparing these JSON libraries on the Internet (the main indicators are performance and stability), you can read them.

However, the Austin project chose FastJSON as the main SERIalization library for JSON (multi-point inclusion)

05, HTTP library

I already forgot the HTTP library. But just as I was about to implement the SMS function, IT occurred to me that HTTP is also used a lot. So in a hurry to send the article before the supplement.

I don’t know how you felt the first time you called HTTP in Java. In my impression, I think this thing is a lot of complicated, transfer HTTP really trouble! Later, after working on the project, there was already a big name packaging HTTP. Sometimes, however, HTTP calls are just too complicated (oh, the various headers, accidentally set up, that’s half a day).

However, HTTP calls are common enough that many corporate interfaces provide HTTP calls almost everywhere. For example, we call Tencent API to send wechat messages, call various channel vendors to send SMS messages and so on.

Anyway, let’s go back to the HTTP library. In the Java ecosystem, HTTP libraries can be broadly divided into three categories:

  • HttpURLConnection
  • Apache HttpClient
  • OkHttp

HttpURLConnection is an HTTP library originally provided by the JDK that does not implement HTTP connection pooling (connection pooling is still very important, I won’t explain the concept too much here). The HTTP libraries I used in my previous projects are all packaged on the basis of Apache HttpClient, while OkHttp can be said to be a late comer (now android HTTP libraries are basically based on OkHttp).

Utils: Utils: Utils: Utils: Utils: Utils: Utils: Utils: Utils: Utils: Utils

  • For example, as mentioned aboveHutoolOn the nativeHttpURLConnectionEncapsulate (but not thread pools)
  • Square’s ownOkHttpCarry on two times again package, open source givesRetrofit(This is used a lot on Android.)
  • Provided in the Spring environmentRestTemplateMultiple ways to access remote Http services (thread poolless by default, but available)Apache HttpClientandOkHttpEncapsulate it toRestTemplate
  • Provided in the SpringCloud environmentOpenFeignThe HTTP service is then invoked
  • Domestic HTTP tool libraryForest:HttpclientandOkHttpencapsulate
  • .

This time I chose OkHtpp as the HTTP library for Austin

Why OkHtpp? Looking ahead, OkHtpp as an Http library has indeed become the benchmark (at least in the case of Android, many SDK companies use Okhttp as a dependency on Http libraries). RestTemplate doesn’t work well in the Spring environment, and I’m not on SpringCloud for my project, so I’m not using OpenFeign. Retrofit is used a lot on Android (and relatively little on the Java backend, it seems).

So I chose OkHttp.

06,

This article is about the toolkit used by the Austin project, but it may be a bit boring for those who already know.

However, there are many students who want to study this project with me, many of whom have never done a project before, so I still feel it is necessary to post a summary. Most of the time what we do, others feel low, actually lies in the poor information.

I’m sure there are some working people reading this who haven’t heard of Lombok and haven’t used a tool like Guava (Commons is probably used, potentially, but didn’t know there was a dedicated Apache class library).

In fact, this kind of toolkit will be used very frequently in the project, using these tool libraries will make our project code more concise, code readability and maintenance is very important for a project.

My advice for such a tool is to check it out at your leisure and see what it offers. When you find yourself encapsulating a utility class, go in and see if it’s already implemented, and if so, use it. If you’re interested in features, take a look at how the big guys implemented them and what they might not have thought of if they implemented them themselves.

There must be a lot of great toolkits out there that I don’t know about, so please feel free to recommend them in the comments! This is the third Austin project, and it has been updated to 11. Welcome to follow my steps and work on the project!

Follow my wechat official account [Java3y] to talk about something different! Continuous high-intensity updates to online Interviewers + Writing Java projects from scratch! O star!!!!! Original is not easy!! Three times!!

Gitee link: gitee.com/austin

GitHub link: github.com/austin