Do you know these excellent Java libraries?

One of the characteristics of an experienced Java developer is that he is good at using existing wheels to build cars instead of building wheels repeatedly. Today’s Java ecosystem has developed very maturely.
In the decades of Java’s rapid development, many excellent open source projects have been produced. In most cases, we can find appropriate open source libraries in the open source community.
Many developers have used and tested these libraries and often have good performance and stability. Using excellent open source components reasonably can save you a lot of time to do other things. In this article, We will share some open source class libraries that Java developers should be familiar with.
So here the 5 best java libraries every developer should know-
Orika
One of the best java libraries is Orika, a java bean mapping tool that can recursively copy data from one object to another. When writing code, we usually find that we need to convert objects into different formats to adapt to different APIs, such as converting DTO to POJO, or POJO to VO. Generally, we need to complete it through getter/setter. Orika can do this trouble for you through simple code without much loss of performance.
Maven dependency:
<dependency> <groupId>ma.glasnost.orika</groupId> <artifactId>orika-core</artifactId> <version>1.4.6</version> </dependency> Demo: public class UserVo { private String username; private String phone; //Omit getter/setter } public class User { private String username; private String phone; //Omit getter/setter } public class OrikaTest { public static void main(String[] args) { User user = new User(); user.setPhone("xxxxxx"); user.setUsername("name"); MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); UserVo userVo = mapperFactory.getMapperFacade().map(user, UserVo.class); System.out.println("the copy object: "+userVo); } }
Orika can copy not only simple Java objects but also collections. Is it great?
Caffeine
Caffeine is among the high-performance in-memory cache java libraries. Caffeine using the W-TinyLFU algorithm has much better read and write performance than guava. Spring 5 has changed the default implementation of caching from guava to caffeine.

Maven dependency:
<dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> <version>2.9.0</version> </dependency> Demo: Cache<String, String> cache = Caffeine.newBuilder() .maximumSize(10000) .expireAfterAccess(60, TimeUnit.SECONDS) //If cache is empty, run the following expression and store it in the cache .build(key-> key+"test"); String key2="test2"; cache.put("test", "cache"); //Get the cache value. If it is empty, return null log.info("key present: [{}] -> [{}]", k, cache.getIfPresent(k)); log.info("key present: [{}] -> [{}]", key2, cache.getIfPresent(key2)); //Remove cache cache.invalidate(k);
Kryo
Kryo is a fast and efficient serialization framework for Java objects. It has the characteristics of high performance, small serialization stream, and simple API. At present, many open source projects are using kryo.
For example, Apache hive and Apache spark. The following is the performance comparison between kryo and major serialization frameworks.


Maven dependency:
<dependency> <groupId>com.esotericsoftware</groupId> <artifactId>kryo</artifactId> <version>5.2.0</version> </dependency> Demo: public class KryoSerializer { private KryoFactory factory =()->{ Kryo kryo = new Kryo(); kryo.setDefaultSerializer(CompatibleFieldSerializer.class); kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy())); return kryo; }; private KryoPool pool = new KryoPool.Builder(factory).softReferences().build(); public byte[] serialize(Object object) { return pool.run(kryo -> { try(Output output = new Output(2048,-1)) { kryo.writeClassAndObject(output,object); output.flush(); return output.toBytes(); } }); } public <T> T deserialize(byte[] data) { try(Input input = new Input(data)) { return pool.run(kryo -> ((T) kryo.readClassAndObject(input))); } } }
Netty
Another best of best among java libraries is Netty, an asynchronous event-driven network application framework, which can be used to quickly develop and maintain high-performance protocol servers and clients.
Netty is absolutely dominant in the field of network programming. Based on Java NIO, netty uses the reactor thread model and binds the client connection to a specific thread to avoid frequent context switching of IO threads.
All IO operations in netty are asynchronous and have super high performance. Many open-source Java projects use netty as the default communication layer framework. For example zookeeper, Elasticsearch, and Redisson to be mentioned below.
Redisson
Redisson adopts the nety framework based on NIO, which can not only be used as the underlying driver client of Redis, but also can send redis commands in synchronous, asynchronous, asynchronous stream or pipeline forms, execute and process Lua scripts, and process the returned results.
On this basis, it also integrates more advanced application solutions, which not only integrate the native redis hash, list, set, string, and geo, Data Structures such as hyperLogLog are encapsulated as the most familiar data structures in Java, and high-level application scenarios such as distributed locks are also implemented.
Maven dependency:
<groupId>org.redisson</groupId> <artifactId>redisson</artifactId> <version>3.16.2</version> </dependency> Demo: //key value get and set RBucket<String> nameRBucket = redisson.getBucket("username"); nameRBucket.set("lance", 60, TimeUnit.SECONDS); redisson.getBucket("username").get(); //operate hashes RMap<String, String> userMap = redisson.getMap("user"); userMap.put("id", "1"); userMap.put("name", "lance"); userMap.put("age", "30"); userMap.expire(60, TimeUnit.SECONDS); redisson.getMap("user").get("name"); //operate lists RList<String> usernames = redisson.getList("usernames"); users.add("lance"); studentRList.expire(60, TimeUnit.SECONDS); redisson.getList("usernames").get(0);
Conclusion
The above are the five excellent open source Java libraries we recommend, which developers often use in their daily work. The above code is just a demo. If you want to really use it in production, you need to package it according to your project situation.
To learn more about Java Libraries, Connect with FunctionUp. We At FunctionUp trains candidates such interesting things and concept of backend and front end development. We are a group of IIT/ISB alumni that trains candidates and help them securing a high paying job in IT. We offer pay after placement coding BootCamp to learn coding in one of the most affordable way. To Know more, visit us here