ITEC 320 Lecture 9 Nested records / Packages. Review Project ?’s Records Exam 1 next Friday.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

ITEC 320 Lecture 12 Records. Intro to records Review Look_ahead(char,EOL); –What is this? –What does it allow us to do?
ITEC 320 Lecture 3 In-class coding / Arrays. Arrays Review Strings –Advantages / Disadvantages Input –What two methods are used? Conditionals Looping.
ITEC 320 Lecture 11 Pointers(1). Pointers Review Packages –Generic –Child Homework 3 is posted.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Java Programming (Chapter 1). Java Programming Classes, Types, and Objects.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
Week 2 Recap CSE 115 – Spring Object Oriented Program System of objects that communicate with one another to solve some problem.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Week 3 Recap CSE 115 – Fall Java Source Code File Made up of: Package declaration Class definition.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Methods and Constructors reading: self-checks: #1-12.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors reading:
Chapter 2 Classes and Methods I Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA ‏ Packages.
ITEC 320 Lecture 16 Packages (1). Review Questions? –HW –Exam Nested records –Benefits –Downsides.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Constructors and Encapsulation reading: self-checks: #10-17.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
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.
CSE 131 Computer Science 1 Module 1: (basics of Java)
ITEC 320 Lecture 10 Packages (2). Review Packages –What parts do they have? –Syntax?
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Recap Visual Perception and Data Visualization Types of Information Display Examples of Diagrams used for Data Display Planning Requirement for Data Visualization.
More About Objects and Methods Chapter 5. Outline Programming with Methods Static Methods and Static Variables Designing Methods Overloading Constructors.
Mixing integer and floating point numbers in an arithmetic operation.
1 Object state: fields. Fields field: A variable inside an object that represents part of its internal state.  Each object will have its own copy of.
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
CS305j Introduction to Computing Classes 1 Topic 23 Classes – Part I "A 'class' is where we teach an 'object' to behave." -Rich Pattis Based on slides.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
CSI 3125, Preliminaries, page 1 Compiling the Program.
Introduction to Methods Shirley Moore CS 1401 Spring 2013 cs1401spring2013.pbworks.com April 1, 2013.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
More About Data Types & Functions. General Program Structure #include statements for I/O, etc. #include's for class headers – function prototype statements.
Classes, Interfaces and Packages
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
1 Class and Object Lecture 7. 2 Classes Classes are constructs that define objects of the same type. A Java class uses instance variables to define data.
Attribute - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/24/2016.
Methods.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Constructors; Encapsulation reading: self-checks: #13-18,
Functions + Overloading + Scope
Building Java Programs
Principles of programming languages 4: Parameter passing, Scope rules
CSC240 Computer Science III
Building Java Programs
Building Java Programs
Building Java Programs
CSE 142 Lecture Notes Defining New Types of Objects
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Dr. R Z Khan Handout-3 Classes
Building Java Programs
Lecture 8-2: Object Behavior (Methods) and Constructors
Building Java Programs
reading: 8.6 self-check: #18, exercises: #9, 14
Building Java Programs
Building Java Programs
Presentation transcript:

ITEC 320 Lecture 9 Nested records / Packages

Review Project ?’s Records Exam 1 next Friday

Nested records / Packages Outline Nested records

Nested records / Packages Design exercise How do we represent a line mathematically? How do we represent one in Ada?

Nested records / Packages Code type Pair is record x: Integer; y: Integer; end record; type Line is record start: Pair; end: Pair; end record; myLine: Line; begin myLine.start.x := 1; myLine.start.y := 2; myLine.end := (3, 4); put(myLine.start.x); put(myLine.end.x);

Nested records / Packages Java/Ada Nested records –How is it implemented in Java? –How is it implemented in Ada?

Nested records / Packages UML Composition –Is a part of Aggregation –Is contained in University Department Faculty Example

Nested records / Packages Arrays What does an array of records like Line mean in terms of –Memory allocation –Syntax

Nested records / Packages Real world example Points Lines Line collection / displayer Images Grid World loader

Nested records / Packages Packages Records are one way of grouping data Packages are one way of grouping functions and procedures

Nested records / Packages Definitions Client –Uses the class and its methods –Routine or package that uses the types and routines defined in package P Examples –With ada.text_io; use ada.text_io; Which one is Java? Which one is Ada?

Nested records / Packages Ada “Classes” Records store information Procedures work with records / other data Put the two together and you have the Ada version of classes Contain –Procedures –Types

Nested records / Packages Java class Pair { int x, y; int distanceToOrigin() // How far to origin { return Math.abs(x) + Math.abs(y); } } // Client for class Pair class PairClient { public static void main(String[] args) { Pair p; p = new Pair(); p.x = 1; p.y = 2; Sop(p.distanceToOrigin()); }

Nested records / Packages Ada 2 pieces –Record for a pair –Function to calculate the distance to the origin File structure –Specification –Body

Nested records / Packages Specificatio n Tells the compiler what the package does, but not how to do it Store in a.ads file package PairPkg is type Pair is record x, y: Integer; end record function distanceToOrigin(p: Pair) return Integer; end PairPkg;

Nested records / Packages Body Contains the code for a certain package’s procedures / functions package body PairPkg is function distanceToOrigin(p: Pair) return Integer is begin return abs p.x + abs p.y; end distanceToOrigin; end PairPkg;

Nested records / Packages Ada / Java Java classes (1 file) Ada method (2 files) What are the benefits / downsides of each approach? How does Java sort of provide the same idea that Ada does?

Nested records / Packages Rules The specification must be followed to the letter All functions / procedures must be implemented All return / parameter types must match

Nested records / Packages Use Without the use statement, you have to fully-qualify the package name with pairpkg; procedure pairclient is p: pairpkg.Pair; begin p.x := 1; p.y := 2; put(pairpkg.distanceToOrigin(p)); end pairclient;

Nested records / Packages Specificatio n Tells the compiler what the package does, but not how to do it Store in a.ads file package PairPkg is type Pair is private; function distanceToOrigin(p: Pair) return Integer; private type Pair is record x, y: Integer; end record; end PairPkg;

Nested records / Packages Body Contains the code for a certain package’s procedures / functions package body PairPkg is function distanceToOrigin(p: Pair) return Integer is begin return abs p.x + abs p.y; end distanceToOrigin; end PairPkg;

Nested records / Packages Compilation Rule of thumb –Keep it all in the same directory –Some way of pointing where to look for specifications / bodies Compiler does the work for you –Automatically pulls in packages thanks to the with statement Take a look at the files produced and think about why they are there…

Nested records / Packages Review Nested records Intro to packages