JavaRush /Java Blog /Random EN /Coffee break #81. The best Java libraries every developer...

Coffee break #81. The best Java libraries every developer should know. Why write clear, meaningful code (and how to do it)

Published in the Random EN group

The Best Java Libraries Every Developer Should Know

Source: Hackernoon Java libraries save you the trouble of reinventing the wheel. The libraries support large communities, have high performance code, and are well tested. And since the Java ecosystem is more than 25 years old, you can easily find the necessary libraries for solving many routine tasks. Third-party libraries are easy to use with the Maven or Gradle dependency management tools , which automatically resolve transitive dependencies and load jars. Coffee break #81.  The best Java libraries every developer should know.  Why write clear, meaningful code (and how to do it) - 1

General Purpose Java Libraries

Libraries such as Google Guava and Apache Commons, help to write code for routine operations. The general purpose libraries contain utility classes for beans, collections, caching, compression, hashing, I/O, cryptography, math and statistics, string processing, graphing, concurrency, validation, and more. Guava is a Google project created by Joshua Bloch, lead developer of the Java Collection Framework and author of Effective Java. Previously, Guava was the only collection library with support for Java 5 features such as generics, enums, covariant return types. Today, Guava is actively developed and maintained. Apache Commons is used in a wide range of projects. It consists of 44 modules, you can add only the dependencies you need. Since version 4.0, the library supports generics.

Logging libraries

If you are developing a large project, you may need logging (logging). There are several types of logging. They help you understand code behavior, fix errors, track and analyze program activity, and audit important events. Previously, the most popular logging library was Log4j . Although now obsolete, Log4j has had an impact on modern logging libraries. New projects: Logback and SLF4Jreplaced Log4j. Compared to its predecessor, it has better performance, Groovy config files, automatic reloading of config files, automatic deletion of old log archives, automatic compression of archived log files, advanced filtering, and other benefits. SLF4J (Simple Logging Facade) is an interface to logging libraries that does not log itself. With SLF4J, a developer can switch between logging implementations simply by changing dependencies. Apache Log4j2- a modern library of magazines. In addition to having all the benefits of Logback, it has many interesting features such as plugin architecture, support for Java 8 lambda expressions, custom log levels, integration with application servers, and customization with Spring Cloud Configuration. Apache Commons Logging - A component of the Apache Commons project such as SLF4J provides an API for logging and can be used with any implementation at runtime.

Java testing libraries

Writing tests is an integral part of software development. They help ensure certain code behaviors. Automatic execution of regression tests ensures that changes, such as enhancements or fixes, do not break existing functionality or introduce new bugs. The most commonly used Java unit testing framework is JUnit . It allows you to write repetitive annotation-based tests and run them with a build automation tool. JUnit supports test case grouping, parameterization, timeouts, test name customization, and test case nesting. TestNG(Test Next Generation) is also a popular testing framework and more advanced than JUnit. TestNG is used not only for unit testing, but also for integration and functional testing. Unlike JUnit, TestNG supports dependent tests, parallel test execution (JUnit provides it experimentally), and other features. Both JUnit and TestNG have great integration with common IDEs such as IntelliJ IDEA, Eclipse and NetBeans.

Data serialization libraries

Often there is a need to exchange data between software components or external systems. For this purpose, we can use human-readable (JSON, XML) or binary data formats. Jackson and Gson are the most popular JSON libraries. They support streaming and custom serialization. Jackson provides extensive annotation support. Gson is easy to use in examples and is suitable when you don't have access to the source code to add annotations. To work with XML, you can use the JAXB and StAX libraries. JAXB allows you to map Java objects to XML documents in a convenient way. StAX provides stream processing of XML documents. StAX is suitable when the application works with huge XML documents.

Other Java Libraries

Lombok is a code generation library that helps you minify boilerplate code. Quartz is a job scheduling library. StreamEx - Provides additional functionality to the standard Stream API. Jsoup is an extended library for working with HTML. I hope that thanks to this article, you will not only get acquainted with the most common Java libraries, but you will also be able to easily find ready-made libraries for your projects. Using third party libraries will help you become a more productive Java developer.

Why write clear, meaningful code (and how to do it)

Source: Amymhaddad Short code is not the goal when writing programs. Short is not necessarily the best. We should not strive for short and concise code. We just shouldn't intentionally complicate or obfuscate the code. It should be clear and meaningful. “Clarity is not the same as brevity,” writes Brian Kernighan in The Practice of Programming. “Most of the time clean code will be shorter... but it can be longer... The right criterion here is ease of understanding.” Coffee break #81.  The best Java libraries every developer should know.  Why write clear, meaningful code (and how to do it) - 2Clear writing is also evidence of our thinking. So, if your text (be it prose or code) is complex and confusing, then you have something to work on. Anyone can do something difficult. It is much more difficult to take something complex and make it clear and understandable. Here are six ways to do it:

1. Write clear class, function, and variable names

The names we choose in the code we write have an impact on readability and meaning. For example, single-letter variable names can be misleading. The reader may not understand what the single variable t is, so they must assume what it means based on the context. Such assumptions can be a road to disaster. It is equally confusing when a variable name is used in the plural when it should be in the singular (or vice versa). It's not clear if the variable represents many elements or one element? Steve McConnell's Code Complete has some great naming advice: “Describe in words what a variable is. Often this statement alone is the best variable name.” Then ask yourself: “What is this variable?” Most often, the answer to this question will be the name of the variable.

2. Refactoring

Many writers spend most of their time editing. It's one thing to write a text. The other is to put meaning into it. The same thing should happen with the code we write: we should spend more time “editing” (or refactoring, in our case). Let's be honest, our first attempt at solving a problem is usually not the best, even if the solution is correct. There is always room for improvement, be it a better algorithm, data structure, or variable name.

3. Read your code out loud

After I write an article (including this one), I read it out loud. If a sentence sounds awkward or confusing, it probably needs to be rewritten. Reading aloud is a great practice for the code you write. This way you will be able to find errors that were previously overlooked.

4. Create a list

Write a list to outline the important steps needed to write a program or solve a problem. This list gives you the confidence that your work is complete. It also reminds you of important tasks that might elude you, such as meaningful variable names, during the coding process.

5. Study someone else's code where the same problem was solved

We shouldn't just write code. We should also be attentive readers of it. By regularly reading the code, you will be introduced to new ideas and learn about problem-solving strategies. As you add more tools to your coding toolbox, you will learn different coding styles.

6. Read William Zinsser's On Good Writing

Zinsser's book is intended for writers, but many of its principles apply to the work of programmers. After all, prose writers and code writers are doing the same thing: writing text.
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION