
Commons Collection Interfaces
- Commons Collections - Bag Interface
- Commons Collections - BidiMap Interface
- Commons Collections - MapIterator Interface
- Commons Collections - OrderedMap Interface
Commons Collections Usage
- Commons Collections - Ignore Null
- Commons Collections - Merge & Sort
- Commons Collections - Transforming Objects
- Commons Collections - Filtering Objects
- Commons Collections - Safe Empty Checks
- Commons Collections - Inclusion
- Commons Collections - Intersection
- Commons Collections - Subtraction
- Commons Collections - Union
Commons Collections Resource
Apache Commons Collections - Environment Setup
This chapter will guide you on how to prepare a development environment to start your work with Apache Commons Collections. It will also teach you how to set up JDK on your machine before you set up Apache Commons Collections −
Setup Java Development Kit (JDK)
You can download the latest version of SDK from Oracle's Java site − Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively.
If you are running Windows and have installed the JDK in C:\jdk-19, you would have to put the following line in your C:\autoexec.bat file.
set PATH=C:\jdk-19;%PATH% set JAVA_HOME=C:\jdk-19
Alternatively, on Windows NT/2000/XP, you will have to right-click on My Computer, select Properties → Advanced → Environment Variables. Then, you will have to update the PATH value and click the OK button.
On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/local/jdk-19 and you use the C shell, you will have to put the following into your .cshrc file.
setenv PATH /usr/local/jdk-19/bin:$PATH setenv JAVA_HOME /usr/local/jdk-19
Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, you will have to compile and run a simple program to confirm that the IDE knows where you have installed Java. Otherwise, you will have to carry out a proper setup as given in the document of the IDE.
Popular Java Editors
To write your Java programs, you need a text editor. There are many sophisticated IDEs available in the market. But for now, you can consider one of the following −
Notepad − On Windows machine, you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad.
Netbeans − It is a Java IDE that is open-source and free, which can be downloaded from www.netbeans.org/index.html.
Eclipse − It is also a Java IDE developed by the eclipse open-source community and can be downloaded from www.eclipse.org.
Download Common Collections Archive
Download the latest version of Apache Common Collections jar file from Download Apache Commons Collections Page. At the time of writing this tutorial, we have downloaded commons-collections4-4.5.0-bin.zip and copied it into C:\>Apache folder.
OS | Archive name |
---|---|
Windows | commons-collections4-4.5.0-bin.zip |
Linux | commons-collections4-4.5.0-bin.tar.gz |
Mac | commons-collections4-4.5.0-bin.tar.gz |
Set Apache Common Collections Environment
Set the APACHE_HOME environment variable to point to the base directory location where Apache jar is stored on your machine. Assuming, we've extracted commons-collections4-4.5.0-bin.zip in Apache folder on various Operating Systems as follows −
OS | Archive name |
---|---|
Windows | Set the environment variable APACHE_HOME to C:\Apache |
Linux | export APACHE_HOME=/usr/local/Apache |
Mac | export APACHE_HOME=/Library/Apache |
Set CLASSPATH Variable
Set the CLASSPATH environment variable to point to the Common Collections jar location. Assuming, you have stored commons-collections4-4.5.0-bin.zip in Apache folder on various Operating Systems as follows −
OS | Output |
---|---|
Windows | Set the environment variable CLASSPATH to %CLASSPATH%;%APACHE_HOME%\commons-collections4-4.5.0-bin.jar;.; |
Linux | export CLASSPATH=$CLASSPATH:$APACHE_HOME/commons-collections4-4.5.0-bin.jar:. |
Mac | export CLASSPATH=$CLASSPATH:$APACHE_HOME/commons-collections4-4.5.0-bin.jar:. |