Presentation is loading. Please wait.

Presentation is loading. Please wait.

University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.

Similar presentations

Presentation on theme: "University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two."— Presentation transcript:

1 University of Limerick1 Work with API’s

2 University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two part –Learning the language »Sequence, selection and iteration –Learning the API »Commonly used structure and services »GUI’s, Input\Output, Data storage, Networking

3 University of Limerick3 Learning the language abstract boolean break byte case catch char class const* continue default do int interface long native new null package private protected public return short double else extends final finally float for goto* if implements import instanceof static super switch synchronized this throw throws transient try void volatile while N.B. Keyword maked with * are unused

4 University of Limerick4 Learning the API u API stands for Application Programming Interface u The interface (calling conventions) by which an application programmer accesses the standard Java classes u Java –2,000 Classes and Interfaces –Spread over more than 75 packages

5 University of Limerick5 Java Class Library u As we can see the Java provides a large collection of classes that support and simplify many common programming activities –GUIs, TCP/IP sockets, CORBA, Compression (ZIP), 2D Graphics, Encryption

6 University of Limerick6 Commonly used packages u java.lang –Provides classes that are fundamental to the design of the Java programming language (including the Math class) u java.math –Provides classes for performing math functionality

7 University of Limerick7 Scale u At first the number of classes may seem impossible to learn but in most cases programmers are only required to know a specific subset u The subset they know often depends on what they are developing u What is of importance is that you can find and use new classes as you require or discover them in preexisting code

8 University of Limerick8 Comparison u The Standard Dictionary –Over 100,000 entries u Commonly used words –First 25 words make up about one-third of all printed material in English –First 100 words make up about one-half of all written material –First 300 make up about sixty-five percent of all written material in English u

9 University of Limerick9 The Math Class u Description provided in Java API u Collection of common math functions (sin, cos, sqrt, etc.). u And two constants: PI and E u Math.PI –3.141592653589793 u Math.sqrt(25) –5.0 u Math.pow(2,10) –1024 u Math.cos(0) –1.0 u Math.cos(2 * Math.PI) –1.0

10 University of Limerick10 How the Math Class Works public class Math{ public static final double PI = 3.141592653589793; public static double sin(double d){.. } public static double sqrt(double d) {.. } private Math(){}.. } > Math.PI 3.141592653589793 > Math.sqrt(25) 5.0

11 University of Limerick11 What's different about Math Class u It’s different from a typical Java class – It is a “stateless” class – We only need one Math class (not multiple instances) – No need to instantiate it (hence, no public constructor) – All of its variables and methods are static – static means “applies to the class as a whole” vs. “applies to an individual instance”

12 University of Limerick12 Math Class Description u When we look at the Maths class using the API documentation notice the phrase java.lang at the top of the main panel above the word Math –This means that the Math class is part of the core Java language and hence can be used directly u Math Class Interface –Field Summary: Has two constants PI and E –Constructor Summary: has no public constructor –Methods Summary: many methods all which are static –Method Details: e.g. sqrt() takes a double and returns a double

13 University of Limerick13 Packages and import Statements u If a class is not part of java language i.e. java.lang, you'll see package name u What is a package? –Basically it's a directory that has a collection of related classes –E.g. Random Class description contains: java.util.Random –Indicating that the Random code is stored in a file called java/util/Random.class somewhere on your machine. –The java/util directory/folder is known as the "util", or utility package. u Since Random is not part of Java Language we need to tell Java where to find it by saying –import java.util.Random; –Another way is to use the asterisk "wildcard character": import java.util.*;

14 University of Limerick14 Random Class u A class to create Random numbers u Constructor Summary shows the objects of this type can be created –E.g. Random ran = new Random(); u Method Summary shows that it can generate random values of types: –integers, doubles etc. –E.g. r.nextInt(6) – Generate a integer numbers between 0 (inclusive) and 6 (exclusive) –How do I generate a number between 1 and 6 ?

15 University of Limerick15 Pseudorandom numbers u The computer is not capable of generating truly random numbers –The computer can only generate pseudorandom numbers-- numbers that are generated by a formula –Pseudorandom numbers look random, but are perfectly predictable if you know the formula »Pseudorandom numbers are good enough for most purposes, but not all--for example, not for serious security applications –Devices for generating truly random numbers do exist »They are based on environmental noise, or on lava lamps

Download ppt "University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two."

Similar presentations

Ads by Google