Packages Written part of final exam Alex Rudniy

Slides:



Advertisements
Similar presentations
Packages Sudhir Talasila Preeti Navale. Introduction Packages are nothing more than the way we organize files into different directories according to.
Advertisements

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.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
EEC-681/781 Distributed Computing Systems Java Tutorial Wenbing Zhao Cleveland State University
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.
1 Lecture 2 Java Packages  What are Java packages?  Why do wee need packages?  How to create a Java package?  Some examples.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
James Tam Java Packages Packages, a method of subdividing a Java program and grouping classes.
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,
Unit2: Object-oriented programming Getting started with Java Jin Sa.
Unit 051 Packages What is a Package? Why use Packages? Creating a Package Naming a Package Using Package Members Managing Source and Class Files Visibility.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Access Control Problem A primary consideration in object- oriented design is to “separate the things that change from the things that stay.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Packages.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Packages F Package is a container for classes F A package is a grouping of related types (classes and interfaces) providing access protection and name.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
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.
Packages. Package 1.Avoid naming conflicts. Put classes into packages so that they can be referenced through package names. 2.Distribute software conveniently.
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-
1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.
Applets Yong Choi School of Business CSU, Bakersfield.
Class Libraries Chapter 1 1 Source Intro to Java Programming Y. Daniel Liang.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Even More Java. Java Packages What is a package? Definition: A package is a grouping of related types providing access protection and name space management.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Packages. Creating and Using Packages To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups.
Building Packages BCIS 3680 Enterprise Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
Packages are used in Java in-order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations.
Classes, Interfaces and Packages
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.
Working with Packages BCIS 3680 Enterprise Programming.
Java Package Advantage of Java Package
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Object Oriented Programming Object and Classes Lecture 3 MBY.
CS 112 Introduction to Programming Java Graphics Yang (Richard) Yang Computer Science Department Yale University 208A Watson, Phone:
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
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.
Java Packages  What are Java packages?  Why do we need packages?  How to create a Java package?  Some examples.  Coming Next: Program Documentation.
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
“Packages in Java”.
Topic: Packages Course : JAVA PROGRAMMING Paper Code: ETCS-307
Software Construction
Packages When we name a program , we name it by class name…
Java Basics Packages.
Packages and Interfaces
Package & Java Access Specifiers
Packages, a method of subdividing a Java program and grouping classes
Object Oriented Programming in java
Sampath Kumar S Assistant Professor, SECE
Applying OO Concepts Using Java
PACKAGES.
Packages & Random and Math Classes
Building a program (Java libraries) - an example
Chapter 6 Objects and Classes
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Interfaces,Packages and Threads
Presentation transcript:

Packages Written part of final exam Alex Rudniy CIS 602 Java and the Web Packages Written part of final exam Alex Rudniy

Packages To make types easier to find and use, to avoid naming conflicts, and to control access, programmers bundle groups of related types into packages. Definition:  A package is a collection of related types providing access protection and name space management. Note that types refers to classes, interfaces, enums, and annotations. 11/16/2018

Packages Provide and enforce a contract between the developer and the user of a collection of resources Reuse Organize resources so they can be used in more than one program Organize the name space Avoid naming conflicts Helps to organize the software Group related resources 11/16/2018

Packages Organize smaller components into larger components Helps to organize work effort Divide and Conquer a large body of software Allow multiple programmers to work on same effort Encapsulation Package is a collection of related classes or packages 11/16/2018

Graphical Notation Packages are graphically drawn as a rectangle with a tab on the left hand side. Further packages contained within the main package may be drawn in the rectangle. If this is the case, the name of the main package is shown in the tab. Otherwise it is shown in rectangle. 11/16/2018

Predefined packages Predefined packages come with Java Group of all packages known as Java class library or Java API Two groups of packages in Java API: Core packages begin with java import java.util.Vector; Extension or Extra packages begin with javax import javax.swing.JOptionPane; 11/16/2018

Core Packages The Java class library is organized into a number of packages: java.applet - classes necessary and beneficial for creating classes to go on the web java.awt - classes for defining GUIs java.awt.datatransfer - for cut and paste java.awt.event - for handling button presses, mouse moves, etc java.awt.image - for handling images 11/16/2018

Core Packages java.io - handling input/output java.lang - classes for primitive types other essential classes java.math - math functions java.net - networking functions java.text - text handling functions java.util - classes not well defined in other classes but very helpful java.util.zip - package for handling, creating and using zip files, compression 11/16/2018

Extension Packages javax.crypto - for cryptographic operations. javax.net - for networking applications. javax.print - describe the types of JavaTM Print Service attributes javax.swing - a set of "lightweight" components that, to the maximum degree possible, work the same on all platforms. javax.sound.sampled - for capture, processing, and playback of sampled audio data. javax.security.cert - public key certificates. 11/16/2018

Created packages Software developers organize own classes into packages Naming conventions packages are all lower case commonly use reverse of internet domain name to provide a globally unique name i.e. com.sun.java.swing The first line of the unit declares the package to which the class belongs: package mypackage.subpackage.subsubpackage; 11/16/2018

Named and unnamed For example, it is possible to declare a package: package vector; public class Vector {Object[] vec;} A compilation unit that has no package declaration is part of an unnamed package. As an example, the compilation unit: class FirstCall {public static void main(String[] args) { System.out.println(“Hi Mr. Student”); } } defines a very simple compilation unit as part of an unnamed package. 11/16/2018

Import Packages If you have classes in packages, you can then reference them in different ways : with the fully qualified domain name packagename.classname, for example, geometry.Point myPoint = new geometry.Point(); or use an import statement import packagename.classname; //one class import packagename.*; //entire package Elephant myElephant = new Elephant(); 11/16/2018

Disambiguating a Name If by some chance a member in one package shares the same name with a member in another package and both packages are imported, you must refer to each member by its qualified name. For example, a developer defined a class named Rectangle in the graphics package. The java.awt package also contains a Rectangle class. 11/16/2018

Disambiguating a Name If both graphics and java.awt have been imported, the following is ambiguous. Rectangle rect; In such a situation, you have to be more specific and use the member's qualified name to indicate exactly which Rectangle class you want. graphics.Rectangle rect; 11/16/2018

Directory structure If you have classes in packages, the directories on the file system they reside in must match the package structure. For example, I have a directory called d:\java Then my directory structure would have d:\java\zoo\Elephant.java after compiling would give us d:\java\zoo\Elephant.class 11/16/2018

Tips Only public classes or interfaces are accessible outside the package in which they are defined. Packages may be uncompressed (i.e. directories) or compressed (i.e. zip files) Package directories may be either placed in the current directory, or on the CLASSPATH. The Java VM automatically imports java.lang and the current package you are using 11/16/2018

Compile and Run javac packagenames.classname To compile you should to move out to the top source directory (above your packages) and type javac packagenames.classname d:\java> javac zoo\Elephant.java to run the program, you use the dot notation instead d:\java> java zoo.Elephant 11/16/2018

Summary To create a package, put a type (class, interface, enum, or annotation) in it. To put a class or an interface into a package, put a package statement as the first statement in the source file for the class or the interface. The path name of the source and class file of a class or an interface mirrors the name of the package. 11/16/2018

Summary To use a class or an interface that's in a different package, you have three choices: use the fully qualified name of the class or the interface import the class or the interface import the entire package of which the class or the interface is a member. 11/16/2018

Summary You might have to set your class path so that the compiler and the interpreter can find the source and class files for your classes and interfaces. 11/16/2018

Bibliography Jia, Xiaoping, Object Oriented Software Development Using Java. Addison Wesley, 2003 http://java.sun.com/docs/books/jls/second_edition/html/packages.doc.html http://java.sun.com/docs/books/tutorial/java/interpack/index.html http://java.sun.com/j2se/1.4.2/docs/api/overview-summary.html http://www.cse.sc.edu/~turkett/csci209/lectures/lecture3outline.txt 11/16/2018