Packages Where, oh where, is my little lost class file?

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

UML Package Diagrams. package_name presentation view controller model.
•7/12 /07 F-1 © 2010 T. Horton CS 4240 Principles of SW Design Packages in Java and UML.
Classpaths, packages, jarfiles, and all that gunk. Ch 4, pp es.html.
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.
Packages and Class Visibility The objectives of this chapter are: To understand logical class groupings using packages To explain the environment variable.
Road Map Introduction to object oriented programming. Classes
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.
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Terms and Rules Professor Evan Korth New York University (All rights reserved)
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.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
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.
1 Lecture 2: Object Oriented Programming in Java.
Object Oriented Programming in Java Habib Rostami Lecture 5.
Dale Roberts Object Oriented Programming using Java - Packages Dale Roberts, Lecturer Computer Science, IUPUI Department.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
By James Braunsberg. What are Modules? Modules are files containing Python definitions and statements (ex. name.py) A module’s definitions can be imported.
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-
4/1/05F-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Packages and Components in Java and UML.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun.
1 JAVA API & Packages Starring: Java Documentation Co-Starring: BlueJ IDE.
Programs and Classes A program is made up from classes Classes may be grouped into packages A class has two parts static parts exist independently Non-static.
Everything is an object (CH-2) Manipulating Objects with References. Manipulating Objects with References. String s; String s = “IS2550” String s = new.
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.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
CSI 3125, Preliminaries, page 1 Compiling the Program.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Henrik Bærbak Christensen1 Build Management Clean environment that works...
Building Packages BCIS 3680 Enterprise Programming.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 5 Methods.
Package A package is a logical container that contains classes,interfaces sub packages. Package provide a unique name space to its members and provide.
Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and.
Classes, Interfaces and Packages
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
CSI 3125, Preliminaries, page 1 Packages. CSI 3125, Preliminaries, page 2 Packages Packages are containers for classes Collection of classes Packages.
Version Control and SVN ECE 297. Why Do We Need Version Control?
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.
1 Introduction to Object Oriented Programming Chapter 10.
© 2004 Pearson Addison-Wesley. All rights reserved September 5, 2007 Packages & Random and Math Classes ComS 207: Programming I (in Java) Iowa State University,
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.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Packages In Java.
Inner Classes.
JAVA COLLECTIONS LIBRARY
JAVA COLLECTIONS LIBRARY
CompSci 230 Software Construction
Packages Written part of final exam Alex Rudniy
Packages and Interfaces
Sampath Kumar S Assistant Professor, SECE
Applying OO Concepts Using Java
Programs and Classes A program is made up from classes
Object Oriented Programming in java
Java objects: a first view
Java Programming Language
CMPE212 – Reminders Assignment 2 due today, 7pm.
Chapter 7 Objects and Classes
Presentation transcript:

Packages Where, oh where, is my little lost class file?

Administrivia Reminder: Midterm, Mar 9 (next Wed) In class, closed book/notes, individual Office hours cancelled all next week Contact me for special appointment I’m out of town from Mar 7 (after class) - Mar 20 Don’t depend on contact w/ me then

Testing Tips #1 Divide and conquer Test all sub-modules of code, as well as full system Helps you isolate what is broken when something breaks E.g., test REVERSE INDEX on its own, spider crawling code on its own, and combo of two Build test cases for each part Test cases for individual modules == Unit testing For overall system==Integration testing

Packages Every Java class exists in a “package” Essentially a namespace Allows multiple developers to have classes w/ same base name java.util.Date diff from java.sql.Date “True” name of a class is [packagename].[classname]

The UML view

Package imports Could specify all classes w/ “fully qualified name” java.util.Map m=new java.util.HashMap(); unm.cs351.s05.terran.p2.Parser p= new unm.cs351.s05.terran.p2.ZurkParser(); Gets very tedious very quickly Java allows “import” statements Essentially just aliases short version to long version import java.util.Map; import java.util.HashMap; Map m=new HashMap(); Rewritten by javac during compile to java.util.Map m=new java.util.HashMap(); Stored that way in.class file (bytecode)

Importing like crazy Can also import everything in a package import java.util.*; Opens up short form of everything in that package Convenient... But also sloppy Clutters namespace What if you want to refer to java.util.Map and java.sql.Date in same prog? Run into trouble if you import * from both...

Nested... But not really Package names are “nested” by “. ” characters javax.swing.text.html is “inside” javax.swing.text is “inside” javax.swing... Except that import javax.swing.* doesn’t get javax.swing.text.*, javax.swing.text.html.*, etc. Dot notation is mostly just convenience for making very long package names

Picking your package Declaring that class is in a specific class is easy: package my.package.name; At top of file, before imports Sun suggests package name of form: edu.unm.cs.[otherstuff] I.e., your domain-name, run drawkcab At minimum: just ensure name uniqueness Nobody should be likely to collide w/ your package name E.g., unm.cs351.s05.lane.p2

Finding the class Java class loader expects class file for java.util.Date to be [CLASSPATH elt]/java/util/Date.class Can be another “but it’s right there!” problem Java class loader has file system expectations built into it... (Ugh) Problem is that source file doesn’t have to be in any particular place javac will still dump it into the corresponding path The top of the package path has to be on CLASSPATH

Packages and access All members of a package can “see” all other members of a package for free Don’t need import statements Anything declared with no access modifier ( public, protected, private ) has package access Everything in the package has access to it, but nothing outside the package does Sort-of like “semi-global” stuff Good for stuff shared among all members of a package E.g., a static variable used in common by all members of a package