Apache commons tutorial with examples will help you understand how to use the Apache commons classes more easily. Apache Commons is a collection of libraries with many useful and reusable Java Components. Apache Commons project is developed and maintained by developers of the Apache community.
Apache Commons libraries are open source and can be obtained, modified, and distributed freely (with the preservation of copyright notice and disclaimer).
Apache Commons libraries provide functionality that is either missing from the core Java libraries or is difficult to implement. These libraries are properly tested which is why you should use them instead of writing your own code where ever possible.
It may seem to be overhead to add a third-party library dependency for simple functionality, but over time as your project grows, it will prove to be very useful. Plus, the Apache commons libraries are extensively tested and usually bug-free.
Apache commons provide so many useful libraries, some of them are listed below.
- DbUtils library provides various JDBC and database-related functionality.
- BeanUtils library provides easy-to-use wrappers around Java reflection API.
- CLI library provides easy API for parsing the command line arguments passed into your programs.
- The email library is very useful for sending emails using Java.
- Codec library is an implementation of commonly used encoders and decoders.
- FileUpload library provides upload functionality to any web application.
- IOUtils provides input-output utilities.
- Lang library provides extra functionality to java.lang package.
- CollectionUtils class provides various methods to work on the Java collections.
- Crypto is an apache cryptographic library.
- DBCP is a database connection pool implementation based on commons-pool 2 and offers better performance.
- ArrayUtils class provides various methods for manipulating arrays.
- JXPath library provides various utilities for manipulating java beans using XPath syntax.
- The logging library provides a wrapper around popular logging APIs.
- Math library provides functionality not available in Java.
- Net library is a client-side implementation of many basic internet protocols like FTP, SMTP, POP3, IMAP, etc.
- Proxy library allows us to create dynamic proxies.
- Commons text provides many utilities to work with text or strings.
You can download the Apache Commons libraries from Apache Commons Site.
Apache Commons Examples
CollectionUtils Examples
- Convert array to ArrayList using CollectionUtils
- Convert List to Set using CollectionUtils
- Convert array to HashSet using CollectionUtils
- How to get HashMap key using value example
- Convert array to TreeSet using CollectionUtils
- Convert HashSet to ArrayList using CollectionUtils
- Convert array to LinkedHashSet using CollectionUtils
- Convert LinkedHashSet to ArrayList using CollectionUtils
ArrayUtils Examples
- Convert ArrayList to array using ArrayUtils
- Search index of array element using ArrayUtils
- Check if array contains element or value using ArrayUtils
- Convert List of wrapper objects to array of primitive values
- Reverse array using ArrayUtils
- Convert String to char array
- Convert LinkedList to an array
- How to find element index in LinkedHashSet
- Convert Vector to array using ArrayUtils
NumberUtils Examples
RandomStringUtils Examples
StringUtils Examples
- Convert ArrayList to comma separated String using StringUtils
- Mask part of the String using StringUtils
- Create String with the specified number of characters using StringUtils
- Pad String with zero using StringUtils
- Count occurrences of substring in String using StringUtils
- Replace String characters using StringUtils
- Search String within String using StringUtils
- Print array elements using StringUtils
- Remove last character of String using StringUtils
- Convert first character of String to lower case using StringUtils
- Check if String is in lower case using StringUtils
- Check if String is in upper case using StringUtils
- Invert String case using StringUtils
- Capitalize first character of String using StringUtils
- Convert String to lower case or upper case using StringUtils
- Check if String starts with another String using StringUtils
- Check if String ends with another String
- Check if String is empty
- Remove leading and trailing spaces from String
- Remove multiple spaces from String (consecutive)
- Convert String array to String
- Convert List elements to comma separated String
- Split String using StringUtils
- Remove leading zeros from String
WordUtils Examples
- Capitalize first character of each words using WordUtils
- Convert String to title case using WordUtils
ReverseListIterator Examples
- Iterate List in backward or reverse direction using ReverseListIterator
- Iterate Vector in reverse direction using ReverseListIterator
ExceptionUtils Examples
IOUtils Examples
FileUtils Examples
- Create new directory using FileUtils
- Delete file or directory using FileUtils
- Create new empty file using FileUtils
FileNameUtils Examples
Please let me know if you liked the Apache Commons tutorial with examples in the comments section below.
Content is very useful, Thanks a lot for providing helpful content.
Glad you liked it, thanks.
Your article is concise and informative on the benefits of the Apache Commons library, but it is not helpful for a beginner — arguable the only type of person who might need it!
I have been trying to figure out how to call the JaroWinklerSimilarity() function in my code for an hour now, and nobody bothers to explain exactly how one goes about doing it. Which snippets to copy from that website? Paste them where? What about dependencies? Do I copy any code from Apache commons? If not, how do I know which is the function name given the structure of that website? In short, how in the world do you use the apache commons website?
These are the most basic set-up kind of problems that are obvious if you know what you’re doing, but they make some beastly menaces to a newbie!
https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/similarity/JaroWinklerSimilarity.html#apply-java.lang.CharSequence-java.lang.CharSequence-
Hello DDP,
I understand your concern. I will try to include such set-up steps in future tutorials.
Coming back to the problems you are facing, I have not used this particular algo, but the process to use any library in Java remains the same. First, you need to download the lib and put it in the classpath. In your case, that is apache-commons text library.
Once that is done, you can use the classes of it in your code. First, you need to import the JaroWinklerSimilarity class. Now create an object of it using the default constructor it provides. Once you have the object of it, you can call the apply method on it and pass two strings for which you need to check the similarity. Examples of the apply method is provided in the javadoc itself.
I hope it helps. Thank you.