Java Packages and Libraries M Taimoor Khan

Slides:



Advertisements
Similar presentations
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Advertisements

More Sophisticated Behaviour 1 Using library classes to implement more advanced functionality.
Importing methods in the Java library. Previously discussed Method = a collection of statements that performs a complex (useful) task A method is identified.
PACKAGES. PACKAGES IN JAVA A package is a collection of related classes and interfaces in Java Packages help in logical grouping of classes and interfaces.
GUIs Part 4 CS221 – 4/17/09. Professional Assignments Assignment #2 – Download and install Visual Studio 2008 Professional Trial Software –
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.
More sophisticated behavior Using library classes to implement some more advanced functionality 4.0.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
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.
More sophisticated behavior Using library classes to implement some more advanced functionality 3.0.
More sophisticated behavior Using library classes to implement some more advanced functionality.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
***** 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.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
University of Limerick1 Work with API’s. University of Limerick2 Learning OO programming u Learning a programming language can be broadly split into two.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
Week1 Using the Library (the Java API) Classes are grouped together in packages –To use a class you have to know which package it is in –Every package.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
More sophisticated behavior Using library classes to implement some more advanced functionality 5.0.
10-Nov-15 Java Object Oriented Programming What is it?
1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.
Class Libraries Chapter 1 1 Source Intro to Java Programming Y. Daniel Liang.
JAVA COLLECTIONS M. TAIMOOR KHAN (ADAPTED FROM SWINBURNE NOTES)
Types in programming languages1 What are types, and why do we need them?
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Objects & Classes Weiss ch. 3. So far: –Point (see java.awt.Point) –String –Arrays of various kinds –IPAddress (see java.net.InetAddress) The Java API.
16-August-2002cse Libraries © 2002 University of Washington1 Class Libraries CSE 142, Summer 2002 Computer Programming 1
Java Coding OOP_3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Some important Java interfaces +
Application Programming Interfaces. Java comes with a bunch of classes that are already written. Java comes with a bunch of classes that are already written.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
More sophisticated behavior Using library classes to implement some more advanced functionality 5.0.
1 COS 260 DAY 10 Tony Gauvin. 2 Agenda Questions? 4 th Mini quiz Today –Chapter 4 Assignment 2 Due Capstone Discussion Proposals Due Oct 15 No class on.
Programming in Java (COP 2250) Lecture 7 Chengyong Yang Fall, 2005.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
1 COS 260 DAY 9 Tony Gauvin. 2 Agenda Questions? 3 rd Mini quiz –Good results ->All A’s –Threw out question on name overloading 4 th Mini quiz next class.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
Know Your Java. Java is special Java source code Byte code/ native code Object code on windows Object code on Dos Object code on Lynux.
Computer Science 209 Software Development Packages.
Outline Creating Objects The String Class The Random and Math Classes Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Console Input and Output JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Comp1004: Environments The Java Library. Coming up Recap – Encapsulation – Constructors – Loops – Arrays – ArrayList – Iterators The Java Library – Implementation.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Mind Q Systems Leader s In Training /7, 2nd Floor, Srinivasa Nagar Colony (W) Above HDFC Bank, S.R. Nagar Hyderabad Tel: /92.
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.
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
BlueJ Chapter 5 More sophisticated behavior: Library classes and documentation.
More-Sophisticated Behavior
Using the Java Collection Libraries COMP 103 # T2
Review of Java … or maybe not.
Java Course Review.
Libraries CITS1001.
Exercise on Java Basics
Classes, Libraries & Packages
More sophisticated behavior
Exercise on Java Basics
MSIS 655 Advanced Business Applications Programming
Building a program (Java libraries) - an example
Using java libraries CGS3416 spring 2019.
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Presentation transcript:

Java Packages and Libraries M Taimoor Khan

Content What is a class library? What is a package? Java class libraries, what do they provide? The root class : java.lang.object 2

The Java class library Thousands of classes Tens of thousands of methods Many useful classes that make life much easier A Java programmer must be able to work with the libraries o 3

Working with the library You should: know some important classes by name know how to find out about other classes o Remember: We only need to know the interface, not the implementation 4 The public face of the class

The exit condition String input = reader.getInput(); if(input.startsWith("bye")) { finished = true; } Where does ‘startsWith’ come from? What is it? What does it do? How can we find out? 5

Reading class documentation Documentation of the Java libraries in HTML format; Readable in a web browser Class API: Application Programmers’ Interface Interface description for all library classes 6

Interface vs implementation The documentation includes the name of the class; 7

Interface vs implementation The documentation includes a general description of the class; 8

Interface vs implementation The documentation includes a list of constructors 9

Interface vs implementation The documentation includes a list of methods 10

Interface vs implementation The documentation includes return values and parameters for constructors and methods 11

Interface vs implementation The documentation does not include private fields (most fields are private) private methods the implementation (source code) for each method 12

Using library classes Classes from the library must be imported using an import statement (except classes from java.lang). They can then be used like classes from the current project. gs.html gs.html 13 “The Java compiler automatically imports” java.lang package the package of the current file source code

Packages and import Classes are organised in packages. Single classes may be imported: import java.util.ArrayList; Whole packages can be imported: import java.util.*; 14 Some of the Packages listed in the API Packages are NOT hierarchical Using “ import java.awt.*;” does not import java.awt.color.*;

Using Random The library class Random can be used to generate random numbers 15 import java.util.Random;... Random randomGenerator = new Random();... int index1 = randomGenerator.nextInt(); int index2 = randomGenerator.nextInt(100);

Generating random responses 16 public Responder() { randomGenerator = new Random(); responses = new ArrayList (); fillResponses(); } public String generateResponse() { int index = randomGenerator.nextInt(responses.size()); return responses.get(index); } public void fillResponses() {... }

Java Packages An overview can be found at this link summary.html summary.html 17

Java Packages Inside each package you will find o Interfaces o Classes o Enumerations o Exceptions 18

java.lang “Provides classes that are fundamental to the design of the Java programming language.” Boolean, Byte, Double, Integer, Long, String String Math System Object 19

java.util “Contains the collections framework…date and time facilities,… string tokenizer.. random-number generator..” ArrayList, LinkedList, Stack ArrayList LinkedList Stack Calendar, Date Calendar Date Formatter Scanner StringTokenizer Random Iterator 20

java.io “Provides for system input and output through data streams, serialization and the file system.” Console File FileReader BufferedInputStream StreamTokenizer 21

GUI libraries java.awt o java.awt.Event javax.imageio javax.swing o

All classes are Objects 23

Packages 24

25

Reading & Exercises P136 – p147 Collections o Swing o Classes and Objects o ex.html ex.html Generics o ex.htm ex.htm 26

References agingfiles.html agingfiles.html html html 27