Package and Import Yoshi. Michael How many “Michael” in this world? When we only say “Michael”…who? So we have the last name – Michael Jordan – Michael.

Slides:



Advertisements
Similar presentations
1 Packages: Putting Classes Together. 2 Introduction The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance)
Advertisements

Packages Sudhir Talasila Preeti Navale. Introduction Packages are nothing more than the way we organize files into different directories according to.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
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.
YOSHI Package and Import. 加油 ! 陳欣怡 ! 世界上有多少陳欣怡 ? 2004 的大學聯考,榜單上叫「陳怡君」的,總共有 64 人,有些人考上了好學校,有些卻名落孫山,同樣 姓名卻有不一樣的際遇。 雅婷.勝.
1 Lecture 2 Java Packages  What are Java packages?  Why do wee need packages?  How to create a Java package?  Some examples.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Grouping Objects 1 Introduction to Collections.
1 Chapter 3 Programs and Packages. 2 Java Virtual Machine (JVM) Java programs execute on the JVM. The JVM is a virtual rather than a physical machine,
Packages Where, oh where, is my little lost class file?
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Ruby (on Rails) CSE 190M, Spring 2009 Week 4. Constructors Writing a new class is simple! Example: class Point end But we may want to initialize state.
PACKAGES Mimi OpkinsCECS277. What We’ll Cover  Packages and Import Statements  The Package java.lang  Package Names and Directories  The Default Package.
Access Control Problem A primary consideration in object- oriented design is to “separate the things that change from the things that stay.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
1 Lecture 2: Object Oriented Programming in Java.
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.
Georgia Institute of Technology Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
Java programming Package. A package is a group of similar types of classes, interfaces and sub-packages. Package can be categorized in two form, built-
Grouping objects Introduction to collections 5.0.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun.
1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.
School of Computer Science & Information Technology G6DICP - Lecture 14 Class Libraries.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Objects & Classes Lakshmish Ramaswamy. instanceOf Operator Testing whether an object is of a certain type (class) object instanceOf classname True if.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
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.
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.
Java Programming Review (Part II) Enterprise Systems Programming.
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.
More Object Concepts— Farrell, Chapter 4 Dr. Burns.
Objects First With Java A Practical Introduction Using BlueJ Grouping objects Collections and iterators 1.0.
Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and.
Packages. The main feature of OOP is its ability to support the reuse of code: –Extending the classes –Extending interfaces The features in basic form.
CSI 3125, Preliminaries, page 1 Packages. CSI 3125, Preliminaries, page 2 Packages Packages are containers for classes Collection of classes Packages.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 3 is due Sunday, the 8 th at 7pm. Problems with assn 3? Discuss at your team meeting tonight.
April 20, 1998CS102-02Lecture 4-1 A Method to the Madness CS Lecture 4-1 Java's Work Horses.
Java Package Advantage of Java Package
UNIT-3 Interfaces & Packages. What is an Interface? An interface is similar to an abstract class with the following exceptions: All methods defined in.
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.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Surviving the OPAC Helpful tips for Elementary Students.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Java API Course Lecture Slides 7 June 2010 “ And you guys were putting.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
Java Packages  What are Java packages?  Why do we need packages?  How to create a Java package?  Some examples.  Coming Next: Program Documentation.
Java Packages - allow you to group classes as a collection Standard Java library has packages: java.lang and java.util … Also hierarchical: java and javax.
OOP Tirgul 7. What We’ll Be Seeing Today  Packages  Exceptions  Ex4 2.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Packages In Java.
Lecture 5:Interfaces and Abstract Classes
Topic: Packages Course : JAVA PROGRAMMING Paper Code: ETCS-307
Java Import Statement Copyright © Curt Hill
Exercise on Java Basics
Java Basics Packages.
Exercise on Java Basics
Packages and Interfaces
Applying OO Concepts Using Java
PACKAGES.
Joel Adams and Jeremy Frens Calvin College
Review: libraries and packages
Using java libraries CGS3416 spring 2019.
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Interfaces,Packages and Threads
CMSC 202 Exceptions.
Presentation transcript:

Package and Import Yoshi

Michael

How many “Michael” in this world? When we only say “Michael”…who? So we have the last name – Michael Jordan – Michael Jackson – Michael Schumacher However, it is still very possible that two persons who have the same first name and last name

How to tell which is which? We can add the qualifier to them! – sports.basketball.bulls.jordan.Michael – sports.racing.ferrari.schumacher.Michael – entertainment.singer.jackson.Michael This is the idea of package!

Package Package is a kind of classfication – Corresponding to the directory it exists Ex: nthu.pads.Container Saved in nthu\pads\Container.class Package can be arbitrary – However, they usually are meaningful java.util.Date (java’s utility library) java.io.InputStream (java’s I/O library)

Example System – java.lang.System String – java.lang.String package java.lang; class System { … } package java.lang; class String { … }

Simplifying and the keyword import java.lang.System is too long to use import java.lang.System; – Then, when we want to use java.lang.System, just type System instead of the full name import java.lang.*; – Then, all the classes which starts with java.lang can be identified with only the class name. That is, java.lang can be skipped Mapping to the examples – sports.basketball.bulls.jordan.Michael – import sports.basketball.bulls.jordan.Michael; Just type Michael Can we write import java.*, even import *? – No! (why?)

Package sql, util, and the ambiguity java.util.Date java.sql.Date The full qualified names of them If we use import – import java.util.*; – import java.sql.*; – So now, the compiler does not know which one you are calling – So you need to give the full name like this java.util.Date dateObj1 = new java.util.Date(); java.sql.Date dateObj2 = new java.sql.Date();

Wrong Concept import in java is similar to include in C – Exactly not! – Import is for laziness! – Try to compile a source code with import and without import, and check the size of the class file

Tips Note that java.lang.* are imported by default for convenience – That is, you don’t have to write the following code explicitly import java.lang.*;