Prerequisite
A running MongoDB server, more details on that here.
Setting Up a Java Project
The MongoDB Java Driver is supplied as a JAR file and can be included in a project just like any other JAR. For example:
Maven: add an entry to the <dependencies> section of your pom.xml.
<...