Packages From Deitel & Deitel.

Slides:



Advertisements
Similar presentations
More on Object-Oriented Programming
Advertisements

 Pearson Education, Inc. All rights reserved static Class Members static fields – Also known as class variables – Represents class-wide.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look 1 Xiang Lian The University of Texas – Pan American Edinburg,
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
CS-1030 Dr. Mark L. Hornick 1 Constructors Copy Constructors.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
CS 106 Introduction to Computer Science I 03 / 21 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 03 / 23 / 2007 Instructor: Michael Eckmann.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look - modified by Eileen Kraemer.
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.
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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.
ITP © Ron Poet Lecture 13 1 Helper Objects. ITP © Ron Poet Lecture 13 2 Console Helper Object  We have used Console objects for a while, let’s see what.
Dale Roberts Object Oriented Programming using Java - Packages Dale Roberts, Lecturer Computer Science, IUPUI Department.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
Packages. Package 1.Avoid naming conflicts. Put classes into packages so that they can be referenced through package names. 2.Distribute software conveniently.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java Classes. Consider this simplistic class public class ProjInfo {ProjInfo() {System.out.println("This program computes factorial of number"); System.out.println("passed.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
(C) 2010 Pearson Education, Inc. All rights reserved. abstract class Employee represents the general concept of an employee. Subclasses: SalariedEmployee,
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
 2005 Pearson Education, Inc. All rights reserved Classes and Objects: A Deeper Look.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
1 Chapter 3 – Object-Based Programming 2 Initializing Class Objects: Constructors Class constructor is a specical method to initialise instance variables.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Methods. Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
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.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 12.
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
CompSci 230 S Programming Techniques
Classes and Objects: A Deeper Look
Inheritance and Encapsulation
Building Java Programs
Classes and Objects: A Deeper Look (Chapter 8)
Object Oriented Programming using Java - Class Instance Variables
The University of Texas Rio Grande Valley
Object Based Programming
Programming Vocabulary.
IFS410: Advanced Analysis and Design
د.سناء الصايغ الفصل الأول البرمجة الشيئية
Package & Java Access Specifiers
Implementing Non-Static Features
Object Oriented Programming
Object Oriented Programming in java
Week 4 Object-based Programming (2) Classes and Objects: A Deeper Look
Overriding Methods & Class Hierarchies
Time Grade 4.
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
PreAP Computer Science Quiz Key
CS360 Client/Server Programming Using Java
Classes & Objects A deeper Look Chapter 10 & 11
Joel Adams and Jeremy Frens Calvin College
OOP Aga private institute for computer science 5th grade
Presentation transcript:

Packages From Deitel & Deitel

Packages A package is a group of related classes All of the classes in the Java API are organized into classes.

Creating packages Before a class can be imported into multiple applications, it must be placed in a package to make it reusable Steps Make your class public Choose a unique package name Add a package declaration to the source code file. Note that there can be only one package declaration in each Java source-code file. The package declaration must precede all other declarations and statements in the file. Compile the class – so that it is placed in the appropriate package directory structure Import the reusable class into a program and use the class.

// Fig. 8. 1: Time1. java from Deitel and Deitel package com. deitel // Fig. 8.1: Time1.java from Deitel and Deitel package com.deitel.jhtp7.ch08; public class Time1 { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 - 59 public void setTime( int h, int m, int s ) { // method contents not shown } // end method setTime // convert to String in universal-time format (HH:MM:SS) public String toUniversalString() { return String.format( "%02d:%02d:%02d", hour, minute, second ); } // end method toUniversalString // convert to String in standard-time format (H:MM:SS AM or PM) public String toString() { return "this is an example"; } // end method toString } // end class Time1

Declarations and Packages Order of declarations package declaration – if any import declarations – if any class declarations Only one of the class declarations in a single file can be public. Other classes in the file are placed in the package and can be used only by the other classes in the package Non-public classes in a package are there to support the reusable classes in the package. Convention for naming package Domain name backwards (i.e. edu.jmu)

Getting to packages Use import statements Remember IF you use a wildcard to import all of the classes in a package, do not also import individual classes in the package Using the wildcard import statement does not affect the performance or the size of your program.