11
Application Application Programming Programming Interfaces Interfaces

Application Programming Interfaces

Embed Size (px)

DESCRIPTION

Application Programming Interfaces. Java comes with a bunch of classes that are already written. For example: Scanner class Random class To organize these classes, they are put into what is called a package. Random. class. java.util. Scanner. package. class. Package: - PowerPoint PPT Presentation

Citation preview

Page 1: Application Programming Interfaces

Application Application Programming Programming

InterfacesInterfaces

Page 2: Application Programming Interfaces

Java comes with a bunch of classes Java comes with a bunch of classes that are already written.that are already written.

For example:For example:– Scanner classScanner class– Random classRandom class

To organize these classes, they are To organize these classes, they are put into what is called a package.put into what is called a package.

Page 3: Application Programming Interfaces

Package:Package:– A group of related classes.A group of related classes.– Think of a package as a “library of Think of a package as a “library of

classes.”classes.”– Each package has a name. For example Each package has a name. For example

the Scanner and Random classes are in the Scanner and Random classes are in the “utility” package the “utility” package This is named This is named “java.util.”“java.util.”

– Ex:Ex:

Scannerclass

Randomclass

java.utilpackage

Page 4: Application Programming Interfaces

APIAPI– ““Application Programming Interface”Application Programming Interface”– Is a collection of packages, that give a Is a collection of packages, that give a

programmer access to classes that they programmer access to classes that they need to write programs.need to write programs.

Scannerclass

Randomclassjava.util

package

javax.swingpackage

JOptionPaneclass

JavaAPI

Page 5: Application Programming Interfaces

To use the classes from any of these packages, To use the classes from any of these packages, you have to import them from the Java API. you have to import them from the Java API.

This is why we have the import statements at the This is why we have the import statements at the beginning of programs.beginning of programs.

Ex:Ex:

import java.util.Scanner; import java.util.Scanner; This imports the ONLY Scanner class.This imports the ONLY Scanner class.

import java.util.*; import java.util.*; By using a wildcard you import ALL of the classes in By using a wildcard you import ALL of the classes in the java.util package. (Scanner, Random, etc…)the java.util package. (Scanner, Random, etc…)

By the way, importing all the classes will not By the way, importing all the classes will not affect the performance OR size of your program.affect the performance OR size of your program.

It just tells the compiler that you want to make all It just tells the compiler that you want to make all the classes in the package available.the classes in the package available.

Page 6: Application Programming Interfaces

There is one package in the Java API that There is one package in the Java API that is automatically imported into EVERY Java is automatically imported into EVERY Java program. This is the program. This is the java.langjava.lang package. package.

Listing of a few standard Java packages:Listing of a few standard Java packages:

PackagePackage DescriptionDescription

java.appletjava.applet Provides classes to write an applet.Provides classes to write an applet.

java.iojava.io Provides classes that perform Provides classes that perform different types of input and output.different types of input and output.

java.langjava.lang Provides general Java classes. This Provides general Java classes. This package is automatically imported.package is automatically imported.

java.utiljava.util Provides various utility classes.Provides various utility classes.

javax.swingjavax.swing Provides classes for graphical user Provides classes for graphical user interfaces(windows).interfaces(windows).

Page 7: Application Programming Interfaces

APIs are not specific to Java.APIs are not specific to Java. There are APIs for all kinds of things…There are APIs for all kinds of things…

Let’s look at the words in API:Let’s look at the words in API:– Application Application meaning a program or service meaning a program or service

(like Google Earth)(like Google Earth)– Programming Programming the syntax and ability to write the syntax and ability to write

code for a program (like the lava language)code for a program (like the lava language)– Interface Interface the classes that let you interact or the classes that let you interact or

create part of an application (the packages and create part of an application (the packages and classes that let you create stuff for Google classes that let you create stuff for Google Earth)Earth)

Page 8: Application Programming Interfaces

Videos:Videos:

– Google Earth APIGoogle Earth API

– API ExplanationAPI Explanation

Page 9: Application Programming Interfaces

Think of an API as a bunch of classes that give you the Think of an API as a bunch of classes that give you the “key” to creating applications.“key” to creating applications.

I can’t create something like Google Earth myself, but I can’t create something like Google Earth myself, but the folks at Google have released the Google Earth the folks at Google have released the Google Earth API so that I can USE their classes to create API so that I can USE their classes to create applications that can interact with their Google Earth applications that can interact with their Google Earth website.website.

Also, keep in mind that Google will only release Also, keep in mind that Google will only release classes in the API for things that they want you to do.classes in the API for things that they want you to do.

APIs give you a way to create programs for APIs give you a way to create programs for applications, but at the same time the companies that applications, but at the same time the companies that create the APIs (like Google’s API for Google Earth) create the APIs (like Google’s API for Google Earth) can control what you can and can’t do with their can control what you can and can’t do with their program.program.

Page 10: Application Programming Interfaces

Here are a few examples of APIs:Here are a few examples of APIs:

Windows API Windows API contains classes that contains classes that allow people to create programs for allow people to create programs for Windows (in the C++ language).Windows (in the C++ language).

Greenfoot API Greenfoot API provides the classes provides the classes to create programs for Greenfoot.to create programs for Greenfoot.

Java 3D API Java 3D API provides the classes provides the classes you need to create 3D objectsyou need to create 3D objects

Page 11: Application Programming Interfaces

Don’t Get Confused!Don’t Get Confused! API API

– Application Programming InterfaceApplication Programming Interface– A bunch of classes all bundled together! Think of it as a library of A bunch of classes all bundled together! Think of it as a library of

classes that are available for you to use!classes that are available for you to use!

IDEIDE– Integrated Development EnvironmentIntegrated Development Environment– A program that let’s you write programs.A program that let’s you write programs.– For example, you write Java programs in Netbeans (which is an IDE). For example, you write Java programs in Netbeans (which is an IDE).

SDKSDK– Software Development KitSoftware Development Kit– Contains a bunch of class libraries, and usually includes an API or Contains a bunch of class libraries, and usually includes an API or

two. For example, the Java SDK comes with the Standard Java API.two. For example, the Java SDK comes with the Standard Java API.– Sometimes the Software Development Kits come with IDEs included. Sometimes the Software Development Kits come with IDEs included.