Skip to content

Apache Commons Tutorial with Examples

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

ArrayUtils Examples

NumberUtils Examples

RandomStringUtils Examples

StringUtils Examples

WordUtils Examples

ReverseListIterator Examples

ExceptionUtils Examples

IOUtils Examples

FileUtils Examples

FileNameUtils Examples

Please let me know if you liked the Apache Commons tutorial with examples in the comments section below.

About the author

4 comments

  1. 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-

    1. 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.

Leave a Reply

Your email address will not be published.