130 likes | 225 Views
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:
E N D
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: • A group of related classes. • Think of a package as a “library of classes.” • Each package has a name. For example the Scanner and Random classes are in the “utility” package This is named “java.util.” • Ex:
Random class java.util javax.swing Java Scanner JOptionPane package package API class class • API • “Application Programming Interface” • Is a collection of packages, that give a programmer access to classes that they need to write programs.
To use the classes from any of these packages, you have to import them from the Java API. • This is why we have the import statements at the beginning of programs. • Ex: import java.util.Scanner; This imports the ONLY Scanner class. import java.util.*; By using a wildcard you import ALL of the classes in the java.util package. (Scanner, Random, etc…) • By the way, importing all the classes will not affect the performance OR size of your program. • It just tells the compiler that you want to make all the classes in the package available.
There is one package in the Java API that is automatically imported into EVERY Java program. This is the java.lang package. • Listing of a few standard Java packages:
APIs are not specific to Java. • There are APIs for all kinds of things… • Let’s look at the words in API: • Application meaning a program or service (like Google Earth) • Programming the syntax and ability to write code for a program (like the lava language) • Interface the classes that let you interact or create part of an application (the packages and classes that let you create stuff for Google Earth)
Videos: • Google Earth API • API Explanation
Think of an API as a bunch of classes that give you the “key” to creating applications. • I can’t create something like Google Earth myself, but the folks at Google have released the Google Earth API so that I can USE their classes to create applications that can interact with their Google Earth website. • Also, keep in mind that Google will only release classes in the API for things that they want you to do. • APIs give you a way to create programs for applications, but at the same time the companies that create the APIs (like Google’s API for Google Earth) can control what you can and can’t do with their program.
Here are a few examples of APIs: • Windows API contains classes that allow people to create programs for Windows (in the C++ language). • Greenfoot API provides the classes to create programs for Greenfoot. • Java 3D API provides the classes you need to create 3D objects
Don’t Get Confused! • API • Application Programming Interface • A bunch of classes all bundled together! Think of it as a library of classes that are available for you to use! • IDE • Integrated Development Environment • A program that let’s you write programs. • For example, you write Java programs in Netbeans (which is an IDE). • SDK • Software Development Kit • Contains a bunch of class libraries, and usually includes an API or two. For example, the Java SDK comes with the Standard Java API. • Sometimes the Software Development Kits come with IDEs included.