Using java libraries CGS3416 spring 2019.

Slides:



Advertisements
Similar presentations
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Advertisements

GUIs Part 4 CS221 – 4/17/09. Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software –
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
Java Programming Chapter 3 More about classes. Why?  To make classes easier to find and to use  to avoid naming conflicts  to control access  programmers.
Chapter 3 Using Classes and Objects. Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as.
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.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
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.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
***** SWTJC STEM ***** Chapter 3-1 cg 36 Java Class Libraries & API’s A class library is a set of classes that supports the development of programs. Java.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
Using Classes and Objects Chapters 3 Section 3.3 Packages Section 3.4 Random Class Section 3.5 Math Class Section 3.7 Enumerated Types Instructor: Scott.
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.
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.
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.
Class Library, Formatting, Wrapper Classes, and JUnit Testing
Chapter 2: Objects and Primitive Data Classes and Objects String, Random, Math, NumberFormat, DecimalFormat and Wrapper Classes.
Java Packages and Libraries M Taimoor Khan
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
* * 0 Chapter 6 Java Methods. * * 0 Method Syntax [access specifier][qualifier] return type method name(argument list) Access specifier public – method.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 4 part 3 GEORGE KOUTSOGIANNAKIS.
1 The String Class Every character string is an object in Java, defined by the String class Every string literal, delimited by double quotation marks,
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
Static. Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A static method does not operate on an object double dY.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
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.
Class Libraries Chapter 1 1 Source Intro to Java Programming Y. Daniel Liang.
School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 4 Methods Chapter.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A class represents a single concept from the problem domain, or a.
© 2004 Pearson Addison-Wesley. All rights reserved September 7, 2007 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 3.
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.
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.
Math Class Mrs. C. Furman September 2, Math frequently used methods NameUse floor()rounds down ceil()rounds up pow(x,y)returns x to the power of.
1 Chap. 3 Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L, 3.1 – 3.6.
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
1 Wrapper Classes  Sometimes we want to use a primitive type as an object, so there are wrapper classes that will help us.  In particular, we need to.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
Programming in Java (COP 2250) Lecture 7 Chengyong Yang Fall, 2005.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Chapter 4: More Object Concepts. Objectives Understand blocks and scope Overload a method Avoid ambiguity Create and call constructors with parameters.
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Using Classes and Objects We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: object creation and.
Lecture 5: java.lang.Math, java.lang.String and Characters Michael Hsu CSULA.
1 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used as a type to declare an object reference.
© 2004 Pearson Addison-Wesley. All rights reserved January 27, 2006 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Variables in Java A variable holds either
Review of Java … or maybe not.
Methods Chapter 6.
Exercise on Java Basics
Classes, Libraries & Packages
Switch, Rounding Errors, Libraries
Chapter 3 Methods.
Exercise on Java Basics
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
Java Classes and Objects 3rd Lecture
Applying OO Concepts Using Java
Today in COMP 110 Brief static review The Math Class Wrapper Classes
Chapter 6 Objects and Classes
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Presentation transcript:

Using java libraries CGS3416 spring 2019

Some built-in functions System.out.println(); Math.ceil(); Math.pow(a,2);

Function Input output Parameters Return values Defined by return type public void functionName(variableType a, variableType b) { //internal block of code } In order to return values, changing the void to int, String, Boolean etc.

Java API – Application Program Interface Library of classes, Java 8 ~ 4240 classes Developed by experts, well-tested by users Used by millions of programmers Part of JDK

API Code Reuse A collection of Packages Classes Interfaces with their respective methods Fields constructors Included with the JDK Code Reuse

Java.util.Date != java.sql.Date Packages Meaningful organization Security : private, public Name scoping Java.util.Date != java.sql.Date

Java API: Important Packages java.lang ~ fundamental classes (primitive types, string, math functions, thread and exceptions) java.util ~ Data structures (like Linked List, Dictionary and support ; for Date / Time operations). java.io ~ Reading (from a file)&writing(to a file) java.net ~ Networking java.sql ~ Databases

Where – Java documentation Java 8 api

3rd Party APIs

Accessing classes in Packages Same package ~ direct access Different package import Fully-qualified class name ~ rare!

Importing Single vs Multiple Classes Import single class Explicit import (or Single-type-Import) import java.util.Scanner; Import multiple classes Separate explicit import *import (or Import-On-Demand): imports all classes in a package import java.util.*; Explicit import or * import? Better clarity with explicit import Explicit import seems to be preferred asterisk wildcard characters

Fully-qualified Class name Alternative to import java.util.Scanner input = new java.util.Scanner(System.in); Required if using java.util.Date & java.sql.Date

java.lang is imported by default

Static fields and methods class – level java.lang.Math has only static methods For a static variable or method, we use this format: className.fieldName // fields Math.PI className.methodName(arguments) // methods Math.ceil() Math

Example: java.lang.Math All fields and methods in this class are static Class Math has two fields, which are common mathematical constants. Sample usage: double area = Math.PI * radius * radius; // compute area of a circle Sample calls to static methods from Math

java.lang.Math Math.random() Math.abs() Double between 0.0 & 1.0 (exclusive) 0 <= (int) (Math.random()*5)<5 Random roll dice 1<=(int)(Math.random() * 6) + 1<=6 Math.abs() Absolute value Math.abs(-240) = 240

java.lang.Math Math.round() Math.ceil() Math.floor() Nearest long or int based on argument Math.round(24.8) = 25, Math.round(24.25f) – 24 (int) Math.ceil() Smallest double >= argument & equal to integer Math.ceil(20.1) = 21 Math.floor() Largest double <= argument & equal to integer Math.floor(24.8)=24

java.lang.Math Math.min()/max() Math.sqrt() Positive square of a double

Demo Using math function

Instance Field and Methods Create one or more objects from a class A class is a blueprint for building objects For a instance variable or method, we use this format: objectName.fieldName // fields objectName.methodName(arguments) // methods

Example: java.util.Random library Demo