Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Artificial Intelligence with Java for Beginners

You're reading from   Hands-On Artificial Intelligence with Java for Beginners Build intelligent apps using machine learning and deep learning with Deeplearning4j

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789537550
Length 144 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Nisheeth Joshi Nisheeth Joshi
Author Profile Icon Nisheeth Joshi
Nisheeth Joshi
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. Introduction to Artificial Intelligence and Java FREE CHAPTER 2. Exploring Search Algorithms 3. AI Games and the Rule-Based System 4. Interfacing with Weka 5. Handling Attributes 6. Supervised Learning 7. Semi-Supervised and Unsupervised Learning 8. Other Books You May Enjoy

Importing Java libraries and exporting code in projects as a JAR file

We will now download a JAR file from the internet and use it in our project to create a JAR file for our project.

Open a web browser and search for download a junit.jar. This will take you to a link where you can download a JAR file. There are online repositories available where JAR files exist. One of the most reliable repositories can be found at http://www.java2s.com/Code/Jar/j/Downloadjunitjar.htm, where you can download any available JAR file. If you click on it, it should take you to the following page:

As seen in the preceding screenshot, you will find the junit.jar file and the different classes that are available in the JAR file also listed. You can right-click on the save (floppy disc) symbol to save the file on your system.

Once the file is downloaded, extract it into a junit.jar file. You can then add it to your project with the following steps:

  1. Create a new project on NetBeans, for example, HelloWorld.
  2. Since the new project will not have the junit.jar file, go to Properties by right-clicking on the project, as shown in the following screenshot:

  1. Go to the Libraries | Add JAR/Folder option and provide the location of where this junit.jar file is, as follows:

  1. Once done, click on Open and it will be added to your project:

  1. Now the JAR file has been added to the project, we can use the junit.jar file in an import statement. We can also import individual packages, as shown in the following screenshot:

  1. If you want to use all of the classes in framework, you just have to write the following code:
import junit.framework.*;
  1. Now, let's use the following code to print the output Hello World:
package helloworld;

/**
*
* @author admin
*/
import junit.framework.*;
public class HelloWorld {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello World");
}
}
  1. After running the preceding code, you should get an output similar to the following:

If you want to create a JAR file for this project, please perform the following steps:

  1. Go to Run and select Clean and Build Project (HelloWorld) to build your project:

  1. Once building the HelloWorld project is complete, the Output window will say BUILD SUCCESSFUL, as shown in the following screenshot:

  1. To check if the JAR file been created or not, go to Windows Explorer and navigate to your project's location, which you received from the previous output:

  1. Open the project folder, in our case HelloWorld, and go into the dist folder, as follows:

  1. In the dist folder, you will find the JAR file (HelloWorld.jar), which you can use and where there will be a lib folder. This will contain the junit.jar file that is being used by the HelloWorld.jar file:

This means that whenever you use any JAR files in your project, they will be stored in the lib folder of your JAR file.

You have been reading a chapter from
Hands-On Artificial Intelligence with Java for Beginners
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789537550
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image