Home > Java > javaTutorial > Detailed explanation of commonly used tool classes under the Lang package in Java

Detailed explanation of commonly used tool classes under the Lang package in Java

黄舟
Release: 2017-10-11 10:00:40
Original
1777 people have browsed it

This article mainly introduces the commonly used tool classes under the Java language Lang package. I think it is quite good. I share it with everyone here. Friends who need it can refer to it.

No matter which Java application you are developing, you will inevitably have to write a lot of tool classes/tool ​​functions. Did you know that there are many ready-made tool classes available, and the code quality is very good. You don’t need to write or debug, as long as you find it.

In Apache Jakarta Common, the Lang Java toolkit is the most widely used among all Apache Jakarta Common projects. It is used in almost all the famous software you know, including Tomcat, Weblogic, Websphere, Eclipse, etc. We will introduce the entire common project starting from this package.

There are many tool classes in Lang. Here are a few main ones:

  ClassUtils: getShortClassName, this function should be in java.lang. There are some in the Class class, and I see many people writing this function themselves. getAllInterfaces, convertClassNamesToClasses, isAssignable, primitivesToWrappers, isInnerClass.

NumberUtils: Classes about numbers and number and string conversion stringToInt, toDouble, createNumber, isAllZeros, int compare(float lhs, float rhs), isNumber(String str) , double min(double[] array).

RandomUtils: Used to generate random numbers.

 DateFormatUtils: Date and time format conversion, as well as local time and UTC time conversion.

DateUtils: Date tool class. isSameDay, truncate, round, modify.

Several classes based on the reflection mechanism:

CompareToBuilder: Comparison, used in algorithms, sorting, and comparisons. reflectionCompare, append.

 EqualsBuilder: Comparison through reflection mechanism. reflectionEquals is used in many projects.

  HashCodeBuilder: You can generate hash code through reflection. Many algorithms involve hash code, but not everyone knows a method of generating hash code.

 ToStringBuilder: When you need to overload the toString function without writing code to list all member information of the current class, you can use this function.

Several other classes I use less:

SerializationUtils Serialization in Java is tricky and error-prone.

SystemUtils is a tool class that can read some jdk information and operating system information.

Summarize

The above is the detailed content of Detailed explanation of commonly used tool classes under the Lang package in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template