Libraries and APIs Don’t reinvent the wheel. What’s an API? API – Application Programmers Interface –We want to use code someone else has written –API’s.

Slides:



Advertisements
Similar presentations
Esempio: Tombola!.
Advertisements

INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
GUIs Part 4 CS221 – 4/17/09. Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software –
Methods Liang, Chapter 4. What is a method? A method is a way of running an ‘encapsulated’ series of commands. System.out.println(“ Whazzup ”); JOptionPane.showMessageDialog(null,
CPSC150 Week 6 notes Chapter 5 and other topics. toString Try to print any class Many print “garbage” (e.g., an address) All classes inherit from Object.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
Overloaded Constructors constructors can be overloaded, like other methods – i.e., a class can define several constructors all constructors must have the.
Java Library Java provides a huge library or collection of useful programs A gold mine of well-tested code that can save you countless hours of development.
Pemrograman Dasar - Data Types1 THINGS & STUFF Identifier, Variable, Constant, Data type, operator, expression, assignment, javadoc.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
Chapter 10 Classes Continued
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
1 Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1, 5.6.
UML Basics & Access Modifier
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
Applications in Java Towson University *Ref:
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
Introduction to Programming Writing Java Beginning Java Programs.
METHODS AND SCOPE CSCE More on Methods  This is chapter 6 in Small Java.
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Ch4 Data Types Every value has a type associated with it. The computer needs to know how much memory to allocate. Every value is either a primitive type.
Classes CS 21a: Introduction to Computing I First Semester,
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
Utilities (Part 2) Implementing static features 1.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Objective You will be able to define and identify the basic components of a java program by taking notes, seeing examples, and completing a lab. Construction.
Java Objects and Classes. Overview n Creating objects that belong to the classes in the standard Java library n Creating your own classes.
Chapter 2 Using Objects. Types A type defines a set of values and the operations that can be carried out on the values Examples: 13 has type int "Hello,
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Documentation javadoc. Documentation not a programmer's first love lives in a separate file somewhere usually a deliverable on the schedule often not.
Introduction to Programming Writing Java Beginning Java Programs.
Using Java Class Library
Chapter 9: A Second Look at Classes and Objects
Javadoc. Purpose of javadoc javadoc is a program that reads your Java program and produces great-looking documentation in HTML format Without any help,
Lesson 6 – Libraries & APIs Libraries & APIs. Objective: We will explore how to take advantage of the huge number of pre-made classes provided with Java.
Liang, Introduction to Java Programming, Sixth Edition1 Objects and Classes Gang Qian Department of Computer Science University of Central Oklahoma.
1  lecture slides online
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
The Math Class Methods Utilizing the Important Math Operations of Java!
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Types and Interfaces COMP.
Objects and Classes Start on Slide 30 for day 2 Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Much of.
1 Static Variable and Method Lecture 9 by Dr. Norazah Yusof.
CSE 1030: Implementing Static Features Mark Shtern.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6A Methods (Concepts)
Lecture 9: Object and Classes Michael Hsu CSULA. 2 OO Programming Concepts Object-oriented programming (OOP) involves programming using objects. An object.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Introduction to programming in java Lecture 16 Random.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
More Sophisticated Behavior
Methods Chapter 6.
Lecture 4 Using Classes Richard Gesick.
Lecture 13 Writing Classes Richard Gesick.
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
MSIS 655 Advanced Business Applications Programming
Simple Classes in Java CSCI 392 Classes – Part 1.
Unit 7 - Short-Circuit Evaluation - De Morgan’s Laws - The switch statement - Type-casting in Java - Using Math.random()
Using java libraries CGS3416 spring 2019.
Presentation transcript:

Libraries and APIs Don’t reinvent the wheel

What’s an API? API – Application Programmers Interface –We want to use code someone else has written –API’s tell us how to use prewritten classes Constructors Methods – Example: DrawingTool –We don’t need to know how the original programmer made it work. –Use the import statement

final The value of the variable will never change final double TAXRATE = Convention is the identifier is written in CAPITALS Do this so we only need to change the number in one place.

static Variable or method belongs to the entire class, not an individual instance Often times you use the class name when referencing it (you don’t have to create an instance to use it – i.e. no new) –Color.RED –Dialog.message(“hello); –System.out.println(“hi); –Math.pow(3,4); –Math.PI

Static Example public class Person{ //number of people in world private static int numPeople; public Person(){ numPeople++; }

DrawingTool Example public drawCircle (double r); postcondition If the object is in drawing mode, a circle of radius r is drawn around the current location using the current width and color.

Point2D doubledistancedistance(Point2D pt) Returns the distance from this Point2D to a specified Point2D.Point2D double distance = rat1.distance(rat2);

The Java API Java 1.5 API We only need a small portion of these classes listed P.609 of the book

Random Constructor Summary RandomRandom() Creates a new random number generator. Method Summary nextIntnextInt(int n) Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

A Number From 0 to 10 Random chooser = new Random(); int num = chooser.nextInt(11);

Dice How many sides does a die (one of a pair of dice) have? Would this work? Random random = new Random(); int die = random(6);

Dice Answer Random random = new Random(); int die = random(6) + 1;

Math Let’s look at the real API –Java 1.5 APIJava 1.5 API

Field Summary Variables that you can access –Math.PI –double circ = 2 * Math.PI * r;

Method Summary Methods that you can call 2^3 int answer = Math.pow(2, 3);

Javadoc When you write your own code, you can use javadoc to create your own API (html files)