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

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
1 Java Programming Basics SE-1011 Dr. Mark L. Hornick.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
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.
Outline Java program structure Basic program elements
Chapter 3 Using Classes and Objects. 2 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
JAVA PROGRAMMING PART II.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Java 程序设计 Java Programming Fall, Contents for Today Java Program Structure  How to Compile a Java Program  How to Run a Java Program Environment.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
1 Java Library Lecture 9 by Dr. Norazah Yusof. 2 Java Library Java has pre-defined classes that consist of the basic language classes in Java (organized.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
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.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Chapter 4 Assignment Statement
Lecture 2: Data Types, Variables, Operators, and Expressions
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An overview of Java, Data types and variables
MSIS 655 Advanced Business Applications Programming
The Building Blocks Classes: Java class library, over 1,800 classes:
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Interfaces.
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Instructor: Alexander Stoytchev
Applying OO Concepts Using Java
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
Instructor: Alexander Stoytchev
Zorah Fung University of Washington, Spring 2015
Using java libraries CGS3416 spring 2019.
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
Zorah Fung University of Washington, Winter 2016
Presentation transcript:

University of Limerick1 Work with API’s

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

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

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

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

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

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

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

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 – 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

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

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”

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

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.*;

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 ?

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