Lecture 13
Java API Docs &
Using JAR Files
By: Asif Shahzad
What you would learn in this session
1. What is API? What are Java API Docs? How
to read/use it?
2. What is a JAR file and how to use classes
from a JAR file?
Application Programmable Interface (API)
• TV Remote is an interface for a user to interact with TV.
• API is interface for machine/program.
• API is an interface that we can use in our program to interact with a
system programmatically, e.g.
• Java API.
• Easypay API, BlueX/TCS API
• Twitter API, Facebook API
• To use an API, we don’t need to understand or even think of how it
work inside. We only need to now the interface that API provides e.g.
nextInt is an interface to talk with Scanner component.
Java API DOCs
• API comes with API Documentation (DOCs for short), that help the
developers to understand how API can be used in a program
• Java API Docs describes the Java components, so that we can use
them in our program
• Download Link: https://www.oracle.com/java/technologies/javase-
jdk8-doc-downloads.html
• Demo
• Scanner, String, Math.PI
• static methods and Math class
Using classes from a JAR File
• In last lecture, we discussed, we can use classpath to link classes
placed outside of our project.
• There are 2 forms of such classes:
• Individual .class files e.g. classes available in your other project.
• Multiple .class files placed in single .jar file, called Java Archive / Library
• Linking mechanism is same for both categories.
• javac –classpath D:\project2\;. MyClass.java
• javac –classpath D:\api.jar;. MyClass.java
Example of using JAR file
• Apache Commons project contains many Open Source Java Libraries
• Lets download and make use of:
• Apache Commons Lang