Outline of the lecture. Composition of objects Basic types of composition Packages meaning, creation, basic Java packages Java Archives Files (JAR)

Size: px
Start display at page:

Download "Outline of the lecture. Composition of objects Basic types of composition Packages meaning, creation, basic Java packages Java Archives Files (JAR)"

Transcription

1 Java_3 1

2 Outline of the lecture 2 Composition of objects Basic types of composition Packages meaning, creation, basic Java packages Java Archives Files (JAR)

3 Composition & Classification 3 Composition and classification are means to organize complexity in terms of hierarchies. The two terms are used id two different, but complementary, ways. Classification and composition are used to organize our knowledge. Composition: we distinguish two basic form of composition whole part composition aggregation

4 Association relationship between classes 4 Basic division of association: general (namely single sided or double sided). At single sided association only one class knows the interface of the other class, at double sided association each class knows the interface of its partner. Navigability is used to indicate direction of association. whole part association (composition, aggregation), is a special case of association, which expreses that an object of the given class contains other objects.

5 Whole Part Asociation object composition 5 composition is a type of very tight binding among objects it occurs e.g. between the tree and its leaves, among a car and its single parts such as (wheels, body, steering wheel, motor... ), wooden stickman (head, neck, hands, body, legs). aggregation (reference composition) is a free binding among objects ir occurs e.g. between computer and its peripheries.

6 Whole Part Association Composition of Objects 6 use terms: whole or composed object part (part of composed object).

7 Semantics of Composition 7 Mouse Buttons whole part kompozice Composition is a stronger form of composing of objects. No parts can exist outside the whole. Every parts belongs only to one whole.

8 Composition Summary 8 Parts belongs only to the one whole. The whole carries exclusive responsibility for exploiting all its parts it means responsibility for their creation and destroying. Supposing responsibility for parts comes into other object the whole can its parts released. If the whole is destroyed it must destroy all its parts as well.

9 Composition Example 9 Rectangle class object is composed of the Point class objects Point class objects are declared directly in the constructor in case references of the Point class are handed over into Rectangle class constructor, it is recommended to use a copy constructor Rectangle -whole -parts Point 1 2

10 public class Point { private int x; private int y; Outline Class Point 10 public Point() { this(0, 0); public Point(int x, int y) { this.x = x; this.y = y; public Point(Point b){ //copy constructor setx(b. (b.getx getx()); sety(b. (b.gety gety()); public String tostring() { String t = String.format format("%3s %4d %4s %4d","X: ", getx(), " Y: ",gety gety()); return t; public void print() { System.out out.println println("point coordinates: "+this this.tostring tostring());

11 public int getx() { return x; public void setx(int x) { this.x = x; public int gety(){ return y; public void sety(int y){ this.y = y; public void move(int dx, int dy) { x = x + dx; y = y + dy; public void setpoint(point f) { setx(f. (f.getx getx()); sety(f. (f.gety gety()); public Point getpoint(){ return new Point(this this); //return this; Outline Class Point 11

12 public class Rectangle { private Point upperleft, lowerright; // constructor declaration public Rectangle() { upperleft = new Point(); lowerright= new Point(); public Rectangle(Point a, Point b) { //upperleft upperleft= a; lowerright= b; upperleft = new Point(a); //using copy constructor lowerright = new Point(b); public void move(int dx, int dy) { upperleft.move move(dx dx,dy dy); lowerright.move move(dx dx,dy dy); Outline Class Rectangle 12

13 public String tostring() { String tx= String.format format(" ("\n%s %s %s %s"," Rectangle upperleft: ", upperleft.tostring tostring(), " lowerright: ", lowerright.tostring tostring()); return tx; public void print() { System.out out.println println(this this.tostring tostring()); public Point getupperleft(){ return upperleft; // return upperleft.getpoint getpoint(); public void setupperleft(point b){ upperleft.setpoint setpoint(b); Outline Class Rectangle 13

14 Whole & Parts Objects 14 In the whole object we work with parts objects, we do not interfere directly into inner attributes of parts but we do it through their methods correct approach: public void move(int dx, int dy) { upperleft.move(dx,dy); lowerright.move(dx,dy); mistaken approach!!! public void move(int dx, int dy) { upperleft.setx(upperleft.getx() + dx); upperleft.y = upperleft.y + dy; lowerright.sety(lowerright.getx() + dx); lowerright.y = lowerright.y + dy;

15 public class RectangleTest { public static void main(string String[] args) { Rectangle o = new Rectangle(new new Point(9, 12), new Point(-33,46)); o.print print(); Outline Class RectangleTest 15 Point LH = new Point(22,23); Point PD= new Point(100, 200); Rectangle ob = new Rectangle(LH, PD); ob.print print(); LH.move move(-100, 100,-100); 100); LH.print print(); ob.print print();

16 Graphical presentation of the Links between Rectangle and Point 16 x valuex upperleft y valuey lowerright x valuex y valuey rectangle pointa pointb

17 Semantics of Aggregation 17 Aggregation is a relation whole/part type (consisting of many partial parts). In this type of relation one object (whole) used services of the next object (part). Whole: is a dominant in the relation, control the run of the relation. Part: provide services, reacts to demands of the whole (it is passive).

18 Semantics of Aggregation 18 Computer Printer * whole part aggregation more printers can be attached to a computer but sometime none is attached a printer can be attached maximally to a one computer or none (by the diagram) given printer can be sequentially used by more computer a printer is actually independent on the computer

19 Aggregation Summary 19 The whole used to be dependent on its parts but it can also exists independently on them (and it also exists) Parts can exist independently on the whole If some parts are missing the whole is in some sense incomplete. Parts can be shared by more wholes.

20 Aggregation and Composition Complex Example 20 There is an aggregation between Person and its Account (connection is created by set method not in constructor) There is a composition between Person and Address. The connection is created already in a constructor. Person is a whole, Address and Account are parts Person Address Account 1

21 public class Address { private String street; private int number; private String town; // constructor declaration public Address() { street = undeclared undeclared"; number = 0; town = undeclared undeclared"; Outline 21 public Address(String street, int number, String town) { this.street street = street; this.number = number; this.town town= town; public Address(Address ad){ this.setstreet setstreet(ad. (ad.getstreet getstreet()); this.setnumber setnumber(ad. (ad.getnumber getnumber()); this.settown settown(ad. (ad.gettown gettown()); public String getstreet(){ return street; public int getnumber(){ return number;

22 public String gettown(){ return town; Outline 22 public void setstreet(string String ul){ street = ul; public void setnumber(int c){ number = c; public void settown(string m){ town = m; public String tostring() { return String.format format(" ("Street Street: %s number: %4d town: %s",getstreet getstreet(), getnumber(), gettown()); public void print() { System.out out.println println( this.tostring tostring());

23 public class Account { private int number; private int balance; Outline 23 // Konstruktory tridy Account public Account(){ this(0, 0); public Account(int number, int balance) { this.number = number; this.balance = balance; public void deposit (int( amount) { balance = balance + amount; public int withdraw (int amount) { balance = balance - amount; return balance; public int getnumber(){ return number; public void setnumber(int c){ number = c;

24 public int getbalance(){ return balance; public String tostring() { return String.format format(" ("Account number: %d account balance: %d", getnumber(), getbalance()); public void print() { System.out out.println println(this this.tostring tostring()); Outline 24

25 public class Person { private String name; private int yearbirth; private Address address; //whole part composition private Account account; // aggregation // constructor declaration public Person() { name = "undeclared" undeclared"; yearbirth = 0; address = new Address(); public Person(String name, int yearbirth, Address address) { this.name name= name; this.yearbirth = yearbirth; this.address = new Address(address address); //copy constructor //this this.address = address; also available // access and modification methods public void setname(string name) { this.name = name; Outline 25 public String getname(){ return name; public void setyearbirth(int int yearbirth) { this.yearbirth = yearbirth; public int getyearbirth() { return yearbirth;

26 public String tostring() { String tx= String.format format(" ("\nname nname: %s year of birth: %4d\nAddress naddress: "+ "%s\naccount naccount: %s", getname etname(), getyearbirth(), address.tostring tostring(), account.tostring tostring()); return tx; public void print() { System.out out.println println(this this.tostring tostring()); //address address.print print(); account.print print(); already declared in tostring // method public void setaccount(account account) { this.account = account; Outline 26 public Account getaccount(){ return account; public void deposit(int int amount){ account.deposit(.deposit(amount amount); public void withdraw(int int amount) { account.withdraw withdraw(amount amount); public void accountprint(){ System.out out.println println(" ("Account Account: "+account account.tostring tostring()); public void addressprint(){ System.out out.println println(" ("Address Address: "+ address.tostring tostring());

27 public class PersonTest { public static void main(string String[] args) { Address a1 = new Address(" ("Green Green",237," ",237,"Havirov Havirov"); //Address a2 = new Address("30. april",22,"ostrava"); Person o1 = new Person("Kamil",1988,a1); Person o2 = new Person("Peter",1956, ("Peter",1956,new Address("30. ("30.april april", 22,"Ostrava")); Account u1 = new Account(1,200); o1.setaccount setaccount(u1); o2.setaccount setaccount(u1); o1.print print(); o2.print print(); o1.withdraw withdraw(300); o2.deposit(800); u1.print print(); //stale zustava odkaz u1 = null; o1.accountprint accountprint(); o2.addressprint addressprint(); Outline 27

28 Graphical representation of the links among objects 28 street value name yearbirth value value number town value value address account number value balance value person account

29 Example of composition of objects Employee and Date 29 Class Employee accepts already created objects of class Date in its constructor Date -day -month -year 2 1 Employee -firstname -secondname

30 public class Date { private int month; // private int day; // based on month private int year; // any year // constructor: call checkmonth to confirm proper value for month; // call checkday to confirm proper value for day public Date( int themonth, int theday, int theyear ) { month = checkmonth( themonth ); // validate month year = theyear; // could validate year day = checkday( theday ); // validate day System.out.printf( "Date object constructor for date %s\n", % this ); // end Date constructor // utility method to confirm proper month value private int checkmonth( int testmonth ) { if ( testmonth > 0 && testmonth <= 12 ) // validate month return testmonth; else // month is invalid { System.out.printf( "Invalid month (%d) set to 1.", testmonth ); return 1; // maintain object in consistent state // end else // end method checkmonth Outline 30

31 // utility method to confirm proper day value based on month and year private int checkday( int testday ) { int dayspermonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ; Outline 31 // check if day in range for month if ( testday > 0 && testday <= dayspermonth[ month ] ) return testday; // check for leap year if ( month == 2 && testday == 29 && ( year % 400 == 0 ( year % 4 == 0 && year % 100!= 0 ) ) ) return testday; System.out.printf( "Invalid day (%d) set to 1.", testday ); return 1; // maintain object in consistent state // end method checkday // return a String of the form month/day/year public String tostring() { return String.format( "%d/%d/%d d/%d/%d", month, day, year ); // end method tostring // end class Date

32 public class Employee { private String firstname; private String lastname; private Date birthdate; private Date hiredate; Outline 32 // constructor to initialize name, birth date and hire date public Employee( String first, String last, Date dateofbirth, Date dateofhire ) { firstname = first; lastname = last; birthdate = dateofbirth; hiredate = dateofhire; // end Employee constructor // convert Employee to String format public String tostring() { return String.format format( "%s, %s Hired: %s Birthday: %s", lastname, firstname, hiredate, birthdate ); // end method toemployeestring // end class Employee

33 public class EmployeeTest { public static void main( String args[] ) { Date birth = new Date( 7, 24, 1949 ); Date hire = new Date( 3, 12, 1988 ); Employee employee = new Employee( "Bob", "Blue", birth, hire ); Outline 33 System.out.println( employee ); Employee e1 = new Employee( John John, Frost Frost, new Date(12, 4, 1981), new Date(11, 18, 1950)); System.out.println(e1); // end main // end class EmployeeTest

34 Graphical representation of the links among objects 34 firstname lastname birthday hireday value value month value day value year value month value day value employee birth year value hire

35 Difference between empty String and a String referring to null 35 there are two different things: empty String is a valid String query by if (s == ) command in case a String refers nowhere it refers to null query by if (s == null) command

36 Use of Packages 36 packages (projects in BlueJ) are useful for gathering (aggregation) of the related classes packages helps to get rid of the name conflict by adding thae class name as a suffix to the name of package (package name.class name) e.g. full name of the class Date is: java.util.date e.g. java.awt (Abstract Window Toolkid) contains List class and java.util has an interface List example { java.awt.list list1; // List gui java.util.list list2; // abstract List namespace (introduced by Java and used by other systems too)

37 Packages - Creation 37 Class belonging into a given package must start with a command: package name_of_the_package; name_of_the_package must be the same as a name of directory, in which the file is placed (stored) name of parcels - convention: lower case characters, numbers and special character such as _ and $ package name is not allowed to be the same as Java key word, not start with a number character menu Edit \ New package during declaration packages can be nested (like windows directories)

38 Java API Packages Application Programming Interface 38 Java contains many predefined classes that are gathered into packages declaration import specifies that a program uses e.g. Scanner class from a package java.utils import java.util.scanner; overview of the predefined packages is given in the following tables

39 Java API packages 39 Package java.applet java.awt java.awt.event Description The Java Applet Package contains a class and several interfaces required to create Java applets program that execites in Web browsers. The Java Abstract Window Toolkid Package contains the classes and interfaces required to create and manipulate GUIs in Java 1.0 and 1.1 Current version of Java often uses javax.swing instead. The Java Abstract Window Toolkid Event Package contaions classes and interfaces that enable event handling for GUI components in both the java.awt and javax.swing packages.

40 Java API packages 40 Package Description java.io The Java Input Output Package contains classes and interfaces that enable programs to input and output data. java.lang java.net The Java Language Package contains classes and interfaces that are required by many Java programs. This package is imported implicitly. The Java Networking Package contains classes and interfaces that enable programs to communicate via computer networks like the Internet.

41 Java API packages 41 Package Description java.text java.util The Java Text Package contains classes and interfaces that enable programs to manipulate numbers, dates, characters and strings. The package provides internationalization capabilities that enable a program to be customized to a specific locate. The Java Utilities Package cintains utulity classes and interfaces that enable: manipulate time and date work with random numbers the storing and processing of large amount of data the breaking the strings into a smaller pieces called token

42 Java API packages 42 Package Description javax.swing javax.swing.event The Java Swing GUI Components Package contains classes and interfaces for Java s Swing GUI components that provide support for portable GUIs. The Java Swing Event Package contains classes and interfaces that enable event handling for GUI components in the javax.swing package

43 Packages User View 43 Java enables to gather group of classes into hierarchy arranged packages. Convention: source class files belonging to the common package are stored into the same directory Compiler arranges compiled files in the same way Source and compiled files need not be in the same directory (BlueJ places source files *.java as well as compiled files *.class into the same directory)

44 Packages Notation 44 Names of the hierarchy ordered packages are separated by a coma. e.g. import java.util.date import command that integrates the package into an application. The only command that can precede is the package command. java package with the name java util subpackage of the java package Date name of the imported class object declaration with the import command: Date dnes; // just qualification, without a constructor object declaration without the import command: java.util.date dnes;

45 JAR Java Archives Files 45 JAR file format enables you to bundle multiple files into a single archive file. Typically a JAR file contains the class files and auxiliary resources associated with applications.

46 JAR File Format Benefits 46 Security digital sign of the contents of a JAR file. Decreasing download time Compression JAR format allows to compress files Packaging for extension: The extension framework provides a means by which you can add functionality to Java core platform. Package sealing: JAR files can be optionally sealed so that the package can enforced version consistency.

47 Using JAR Files: The Basics 47 JAR files are packed with the ZIP file format. You can use them for ZIP-like tasks such as lossless data compression, decompression, archiving and archive unpacking.

48 Table of Basic Operation 48 Operation To create a JAR file To view the contents of a JAR file To extract the contents of a JAR file To extract specific files from a JAR file To run application packaged as a JAR file (require the Main-class manifest header) Command jar cf jar-file input-file(s) jar tf jar-file jar xf jar-file jar xf jar-file archives-file(s) java jar app.jar

49 Creating a JAR File Independent Application 49 a JAR file cam be executed like an independent application with use only JRE (15 MB) instead of JDK (50 MB). all files in the project are stored in the jar file there must be a main method

50 Creation a JAR File with Application 50 BlueJ: Project Create JAR File Select File with the main class before JAR file creation it is necessary to copy the whole application into an independent package (otherwise all files in the package will be ziped too)

Classes and Objects: A Deeper Look

Classes and Objects: A Deeper Look 1 8 Classes and Objects: A Deeper Look 1 // Fig. 8.1: Time1.java 2 // Time1 class declaration maintains the time in 24-hour format. 4 public class Time1 6 private int hour; // 0 2 7 private int minute;

More information

A class can have references to objects of other classes as members Sometimes referred to as a has-a relationship. Software Engineering Observation 8.

A class can have references to objects of other classes as members Sometimes referred to as a has-a relationship. Software Engineering Observation 8. 8.8 Composition 1 Composition A class can have references to objects of other classes as members Sometimes referred to as a has-a relationship 2 Software Engineering Observation 8.9 One form of software

More information

Classes and Objects: A Deeper Look

Classes and Objects: A Deeper Look Classes and Objects: A Deeper Look 8 Instead of this absurd division into sexes, they ought to class people as static and dynamic. Evelyn Waugh Is it a world to hide virtues in? William Shakespeare But

More information

Classes and Objects:A Deeper Look

Classes and Objects:A Deeper Look www.thestudycampus.com Classes and Objects:A Deeper Look O b j e c t i v e s In this chapter you ll learn: Encapsulation and data hiding. To use keywordthis. To usestatic variables and methods. To importstatic

More information

CSCE3193: Programming Paradigms

CSCE3193: Programming Paradigms CSCE3193: Programming Paradigms Nilanjan Banerjee University of Arkansas Fayetteville, AR nilanb@uark.edu http://www.csce.uark.edu/~nilanb/3193/s10/ Programming Paradigms 1 Java Packages Application programmer

More information

Object-Based Programming

Object-Based Programming Object-Based Programming 8.1 Introduction 8.2 Implementing a Time Abstract Data Type with a Class 8.3 Class Scope 8.4 Controlling Access to Members 8.5 Creating Packages 8.6 Initializing Class Objects:

More information

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I String and Random Java Classes Janyl Jumadinova 12-13 February, 2018 Divide and Conquer Most programs are complex and involved. The best way to develop and maintain a

More information

Classes and Objects: A Deeper Look Pearson Education, Inc. All rights reserved.

Classes and Objects: A Deeper Look Pearson Education, Inc. All rights reserved. 1 8 Classes and Objects: A Deeper Look 2 OBJECTIVES In this chapter you will learn: Encapsulation and data hiding. The notions of data abstraction and abstract data types (ADTs). To use keyword this. To

More information

System.out.print(); Scanner.nextLine(); String.compareTo();

System.out.print(); Scanner.nextLine(); String.compareTo(); System.out.print(); Scanner.nextLine(); String.compareTo(); Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 6 A First Look at Classes Chapter Topics 6.1 Objects and

More information

Code Listing H-1. (Car.java) H-2 Appendix H Packages

Code Listing H-1. (Car.java) H-2 Appendix H Packages APPENDIX H Packages NOTE: To use this appendix you must understand how your operating system uses directories, or folders. In addition, you must know how to set the value of an environment variable. The

More information

Object-Based Programming (Deitel chapter 8)

Object-Based Programming (Deitel chapter 8) Object-Based Programming (Deitel chapter 8) 1 Plan 2 Introduction Implementing a Time Abstract Data Type with a Class Class Scope Controlling Access to Members Referring to the Current Object s Members

More information

Classes and Objects: A Deeper Look

Classes and Objects: A Deeper Look 8 Instead of this absurd division into sexes, they ought to class people as static and dynamic. Evelyn Waugh Is it a world to hide virtues in? William Shakespeare But what, to serve our private ends, Forbids

More information

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

Inheritance and Polymorphism

Inheritance and Polymorphism Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Packages & Random and Math Classes

Packages & Random and Math Classes Packages & Random and Math Classes Quick review of last lecture September 6, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Objects Classes An object

More information

Methods (Deitel chapter 6)

Methods (Deitel chapter 6) Methods (Deitel chapter 6) 1 Plan 2 Introduction Program Modules in Java Math-Class Methods Method Declarations Argument Promotion Java API Packages Random-Number Generation Scope of Declarations Methods

More information

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes

CSEN401 Computer Programming Lab. Topics: Introduction and Motivation Recap: Objects and Classes CSEN401 Computer Programming Lab Topics: Introduction and Motivation Recap: Objects and Classes Prof. Dr. Slim Abdennadher 16.2.2014 c S. Abdennadher 1 Course Structure Lectures Presentation of topics

More information

1 OBJECT-BASED PROGRAMMING CHAPTER 8

1 OBJECT-BASED PROGRAMMING CHAPTER 8 1 OBJECT-BASED PROGRAMMING CHAPTER 8 8 Object-Based Programming 1 // Fig. 8.1: Time1.java 2 // Time1 class definition 3 import java.text.decimalformat; // used for number formatting 4 5 // This class maintains

More information

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year!

Accurate study guides, High passing rate! Testhorse provides update free of charge in one year! Accurate study guides, High passing rate! Testhorse provides update free of charge in one year! http://www.testhorse.com Exam : 1Z0-850 Title : Java Standard Edition 5 and 6, Certified Associate Exam Version

More information

Class Relationships. Lecture 18. Based on Slides of Dr. Norazah Yusof

Class Relationships. Lecture 18. Based on Slides of Dr. Norazah Yusof Class Relationships Lecture 18 Based on Slides of Dr. Norazah Yusof 1 Relationships among Classes Association Aggregation Composition Inheritance 2 Association Association represents a general binary relationship

More information

Introduction to Classes and Objects

Introduction to Classes and Objects 1 2 Introduction to Classes and Objects You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

CSE 143 Au04 Midterm 1 Page 1 of 9

CSE 143 Au04 Midterm 1 Page 1 of 9 CSE 143 Au04 Midterm 1 Page 1 of 9 Question 1. (4 points) When we re modifying Java code, some of the things we do will change the coupling between the class we re working on and other classes that it

More information

Packages. Examples of package names: points java.lang com.sun.security drawing.figures

Packages. Examples of package names: points java.lang com.sun.security drawing.figures Packages To make classes easier to find and to use, to avoid naming conflicts, and to control access, programmers bundle groups of related classes and interfaces into packages. A package is a program module

More information

Introduction to Classes and Objects

Introduction to Classes and Objects 3 Nothing can have value without being an object of utility. Karl Marx Your public servants serve you right. Adlai E. Stevenson Knowing how to answer one who speaks, To reply to one who sends a message.

More information

Methods (Deitel chapter 6)

Methods (Deitel chapter 6) 1 Plan 2 Methods (Deitel chapter ) Introduction Program Modules in Java Math-Class Methods Method Declarations Argument Promotion Java API Packages Random-Number Generation Scope of Declarations Methods

More information

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

CPSC 324 Topics in Java Programming

CPSC 324 Topics in Java Programming CPSC 324 Topics in Java Programming Lecture 24 Today Final exam review Java packages and jar files Reminder Group projects on Thursday! Reading Assignment Core: Ch. 10 pp. 493-500 (Jar files) Core: Ch.

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries

More information

Java Classes & Primitive Types

Java Classes & Primitive Types Java Classes & Primitive Types Rui Moreira Classes Ponto (from figgeom) x : int = 0 y : int = 0 n Attributes q Characteristics/properties of classes q Primitive types (e.g., char, byte, int, float, etc.)

More information

Assignment 8B SOLUTIONS

Assignment 8B SOLUTIONS CSIS 10A Assignment 8B SOLUTIONS Read: Chapter 8 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Chap. 3. Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L,

Chap. 3. Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L, Chap. 3 Creating Objects The String class Java Class Library (Packages) Math.random() Reading for this Lecture: L&L, 3.1 3.6 1 From last time: Account Declaring an Account object: Account acct1 = new Account

More information

Object-Orientation. Classes Lecture 5. Classes. State and Behaviour. Instance Variables. Object vs. Classes

Object-Orientation. Classes Lecture 5. Classes. State and Behaviour. Instance Variables. Object vs. Classes CP4044 Lecture 5 1 Classes Lecture 5 Object-Orientation Object-oriented design (OOD) Models real-world objects Models communication among objects Encapsulates data (attributes) and functions (behaviors)

More information

COMP-202 Unit 5: Basics of Using Objects

COMP-202 Unit 5: Basics of Using Objects COMP-202 Unit 5: Basics of Using Objects CONTENTS: Concepts: Classes, Objects, and Methods Creating and Using Objects Introduction to Basic Java Classes (String, Random, Scanner, Math...) Introduction

More information

Chapter 8 Object-Based Programming

Chapter 8 Object-Based Programming Chapter 8 Object-Based Programming Object Oriented Programming (OOP) Encapsulates data (attributes) and methods (behaviors) Objects Allows objects to communicate Well-defined interfaces Procedural programming

More information

Preview 11/1/2017. Constant Objects and Member Functions. Constant Objects and Member Functions. Constant Objects and Member Functions

Preview 11/1/2017. Constant Objects and Member Functions. Constant Objects and Member Functions. Constant Objects and Member Functions Preview Constant Objects and Constant Functions Composition: Objects as Members of a Class Friend functions The use of Friend Functions Some objects need to be modifiable and some do not. A programmer

More information

Programming in Java

Programming in Java 320341 Programming in Java Fall Semester 2014 Lecture 5: Packages Instructor: Slides: Jürgen Schönwälder Bendick Mahleko Objectives The objective of this lecture is to - Introduce packages in Java page

More information

Chapter Goals. Chapter 7 Designing Classes. Discovering Classes Actors (end in -er, -or) objects do some kinds of work for you: Discovering Classes

Chapter Goals. Chapter 7 Designing Classes. Discovering Classes Actors (end in -er, -or) objects do some kinds of work for you: Discovering Classes Chapter Goals Chapter 7 Designing Classes To learn how to discover appropriate classes for a given problem To understand the concepts of cohesion and coupling To minimize the use of side effects To document

More information

CS 61B Data Structures and Programming Methodology. July 3, 2008 David Sun

CS 61B Data Structures and Programming Methodology. July 3, 2008 David Sun CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun Announcements Project 1 is out! Due July 15 th. Check the course website. Reminder: the class newsgroup ucb.class.cs61b should

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

More information

Software Development With Java CSCI

Software Development With Java CSCI Software Development With Java CSCI-3134-01 D R. R A J S I N G H Outline Week 8 Controlling Access to Members this Reference Default and No-Argument Constructors Set and Get Methods Composition, Enumerations

More information

L4,5: Java Overview II

L4,5: Java Overview II L4,5: Java Overview II 1. METHODS Methods are defined within classes. Every method has an associated class; in other words, methods are defined only within classes, not standalone. Methods are usually

More information

Object Oriented Programming. Week 1 Part 3 Writing Java with Eclipse and JUnit

Object Oriented Programming. Week 1 Part 3 Writing Java with Eclipse and JUnit Object Oriented Programming Part 3 Writing Java with Eclipse and JUnit Today's Lecture Test Driven Development Review (TDD) Building up a class using TDD Adding a Class using Test Driven Development in

More information

Object Oriented Programming. Java-Lecture 1

Object Oriented Programming. Java-Lecture 1 Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen

More information

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference CSI1102: Introduction to Software Design Chapter 5: Enhancing Classes Learning objectives: Enhancing Classes Understand what the following entails Different object references and aliases Passing objects

More information

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE PART 1 Eclipse IDE Tutorial Eclipse Java IDE This tutorial describes the usage of Eclipse as a Java IDE. It describes the installation of Eclipse, the creation of Java programs and tips for using Eclipse.

More information

The most common relationships are: dependency, association, generalization, and realization.

The most common relationships are: dependency, association, generalization, and realization. UML Class Diagram A class diagram describes the structure of an object-oriented system by showing the classes (and interfaces) in that system and the relationships between the classes (and interfaces).

More information

Class 9: Static Methods and Data Members

Class 9: Static Methods and Data Members Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward Goals This the session in which we explain what static means. You

More information

CSI Introduction to Software Design. Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) x 6277

CSI Introduction to Software Design. Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) x 6277 CSI 1102 Introduction to Software Design Prof. Dr.-Ing. Abdulmotaleb El Saddik University of Ottawa (SITE 5-037) (613) 562-5800 x 6277 elsaddik @ site.uottawa.ca abed @ mcrlab.uottawa.ca http://www.site.uottawa.ca/~elsaddik/

More information

CIS 110: Introduction to Computer Programming

CIS 110: Introduction to Computer Programming CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) 11/28/2011 CIS 110 (11fa) - University of Pennsylvania 1 Outline Object-oriented programming. What is

More information

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth

Outline. CIS 110: Introduction to Computer Programming. Any questions? My life story. A horrible incident. The awful truth Outline CIS 110: Introduction to Computer Programming Lecture 22 and 23 Objects, objects, objects ( 8.1-8.4) Object-oriented programming. What is an object? Classes as blueprints for objects. Encapsulation

More information

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.

More information

Class Libraries and Packages

Class Libraries and Packages Class Libraries and Packages Wolfgang Schreiner Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria Wolfgang.Schreiner@risc.jku.at http://www.risc.jku.at Wolfgang

More information

BSc. (Hons.) Software Engineering. Examinations for / Semester 2

BSc. (Hons.) Software Engineering. Examinations for / Semester 2 BSc. (Hons.) Software Engineering Cohort: BSE/04/PT Examinations for 2005-2006 / Semester 2 MODULE: OBJECT ORIENTED PROGRAMMING MODULE CODE: BISE050 Duration: 2 Hours Reading Time: 5 Minutes Instructions

More information

Objects, Distribution, and the Internet. Update on Java. Introduction, fundamentals and basic concepts. Outline

Objects, Distribution, and the Internet. Update on Java. Introduction, fundamentals and basic concepts. Outline Objects, Distribution, and the Internet Update on Java CIMPA INRIA UNESCO School Mérida,Universidad de los Andes (Venezuela) January 7-18, 2002 Richard Grin Richard.Grin@unice.fr University de Nice - Sophia

More information

An introduction to Java II

An introduction to Java II An introduction to Java II Bruce Eckel, Thinking in Java, 4th edition, PrenticeHall, New Jersey, cf. http://mindview.net/books/tij4 jvo@ualg.pt José Valente de Oliveira 4-1 Java: Generalities A little

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

CSE 413 Winter 2001 Midterm Exam

CSE 413 Winter 2001 Midterm Exam Name ID # Score 1 2 3 4 5 6 7 8 There are 8 questions worth a total of 75 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to

More information

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.

More information

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 15 Class Relationships Outline Problem: How can I create and store complex objects? Review of static methods Consider static variables What about objects

More information

Package. A package is a set of related classes Syntax to put a class into a package: Two rules: Example:

Package. A package is a set of related classes Syntax to put a class into a package: Two rules: Example: Packages Package A package is a set of related classes Syntax to put a class into a package: package ; public class { } Two rules: q q A package declaration must always come

More information

CSE1720 Delegation Concepts (Ch 2)

CSE1720 Delegation Concepts (Ch 2) CSE1720 Delegation Concepts (Ch 2) Output (sec 2.2.5) Output to the console Output to a file (later section 5.3.2) Instead of System.out.println( Hi ); Use: output.println( Hi ); 1 2 Ready-Made I/O Components

More information

Implementing Classes (P1 2006/2007)

Implementing Classes (P1 2006/2007) Implementing Classes (P1 2006/2007) Fernando Brito e Abreu (fba@di.fct.unl.pt) Universidade Nova de Lisboa (http://www.unl.pt) QUASAR Research Group (http://ctp.di.fct.unl.pt/quasar) Chapter Goals To become

More information

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B 1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these 2. How many primitive data types are there in Java? A. 5 B. 6 C. 7 D. 8 3. In Java byte, short, int and long

More information

Introduction to Software Development (ISD) David Weston and Igor Razgon

Introduction to Software Development (ISD) David Weston and Igor Razgon Introduction to Software Development (ISD) David Weston and Igor Razgon Autumn term 2013 Course book The primary book supporting the ISD module is: Java for Everyone, by Cay Horstmann, 2nd Edition, Wiley,

More information

CS 335 Lecture 02 Java Programming

CS 335 Lecture 02 Java Programming 1 CS 335 Lecture 02 Java Programming Programming in Java Define data Calculate using data Output result Java is object-oriented: Java program must: Merge data and functions into object Invoke functions

More information

COMP-202 More Complex OOP

COMP-202 More Complex OOP COMP-202 More Complex OOP Defining your own types: Remember that we can define our own types/classes. These classes are objects and have attributes and behaviors You create an object or an instance of

More information

CS 116. Lab Assignment # 1 1

CS 116. Lab Assignment # 1 1 Points: 2 Submission CS 116 Lab Assignment # 1 1 o Deadline: Friday 02/05 11:59 PM o Submit on Blackboard under assignment Lab1. Please make sure that you click the Submit button and not just Save. Late

More information

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing Introduction 1 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Focus of the Course Object-Oriented Software Development

More information

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007 Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max

More information

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar Upon completing the course, you will understand Create, compile, and run Java programs Primitive data types Java control flow Operator Methods

More information

Java: advanced object-oriented features

Java: advanced object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: advanced object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Packages

More information

Another IS-A Relationship

Another IS-A Relationship Another IS-A Relationship Not all classes share a vertical relationship. Instead, some are supposed to perform the specific methods without a vertical relationship. Consider the class Bird inherited from

More information

3.1 Class Declaration

3.1 Class Declaration Chapter 3 Classes and Objects OBJECTIVES To be able to declare classes To understand object references To understand the mechanism of parameter passing To be able to use static member and instance member

More information

AS COMPUTERS AND THEIR USER INTERFACES have become easier to use,

AS COMPUTERS AND THEIR USER INTERFACES have become easier to use, AS COMPUTERS AND THEIR USER INTERFACES have become easier to use, they have also become more complex for programmers to deal with. You can write programs for a simple console-style user interface using

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

Core JAVA Training Syllabus FEE: RS. 8000/-

Core JAVA Training Syllabus FEE: RS. 8000/- About JAVA Java is a high-level programming language, developed by James Gosling at Sun Microsystems as a core component of the Java platform. Java follows the "write once, run anywhere" concept, as it

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

Principles of Software Construction: Objects, Design, and Concurrency

Principles of Software Construction: Objects, Design, and Concurrency Principles of Software Construction: Objects, Design, and Concurrency An Introduction to Object-oriented Programming, Continued. Modules and Inheritance Spring 2014 Charlie Garrod Christian Kästner School

More information

Advanced Object Oriented Programming. EECS2030 Section A

Advanced Object Oriented Programming. EECS2030 Section A Advanced Object Oriented Programming EECS2030 Section A 1 Who Am I? Dr. Mufleh Al-Shatnawi office Lassonde 3057 hours : 5:30PM -- 6:30PM on Tuesdays and Thursdays; or by appointments email mufleh@eecs.yorku.ca

More information

This page intentionally left blank

This page intentionally left blank This page intentionally left blank arting Out with Java: From Control Structures through Objects International Edition - PDF - PDF - PDF Cover Contents Preface Chapter 1 Introduction to Computers and Java

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Summary of Methods; User Input using Scanner Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin

More information

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects.

More Java Basics. class Vector { Object[] myarray;... //insert x in the array void insert(object x) {...} Then we can use Vector to hold any objects. More Java Basics 1. INHERITANCE AND DYNAMIC TYPE-CASTING Java performs automatic type conversion from a sub-type to a super-type. That is, if a method requires a parameter of type A, we can call the method

More information

Course Content. Objectives of Lecture 18 Black box testing and planned debugging. Outline of Lecture 18

Course Content. Objectives of Lecture 18 Black box testing and planned debugging. Outline of Lecture 18 Structural Programming and Data Structures Winter 2000 CMPUT 102: Testing and Debugging Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection

More information

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Introduction to Java Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Introduce Java, a general-purpose programming language,

More information

Objects and Classes -- Introduction

Objects and Classes -- Introduction Objects and Classes -- Introduction Now that some low-level programming concepts have been established, we can examine objects in more detail Chapter 4 focuses on: the concept of objects the use of classes

More information

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages

Agenda. Objects and classes Encapsulation and information hiding Documentation Packages Preliminaries II 1 Agenda Objects and classes Encapsulation and information hiding Documentation Packages Inheritance Polymorphism Implementation of inheritance in Java Abstract classes Interfaces Generics

More information

CS 201, Fall 2016 Sep 28th Exam 1

CS 201, Fall 2016 Sep 28th Exam 1 CS 201, Fall 2016 Sep 28th Exam 1 Name: Question 1. [5 points] Write code to prompt the user to enter her age, and then based on the age entered, print one of the following messages. If the age is greater

More information

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java Introduction Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2 Problem Solving The purpose of writing a program is to solve a problem

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 8 Lecture 8-3: Encapsulation; Homework 8 (Critters) reading: 8.3-8.4 Encapsulation reading: 8.4 2 Encapsulation encapsulation: Hiding implementation details from clients.

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 26 March 26, 2015 Inheritance and Dynamic Dispatch Chapter 24 public interface Displaceable { public int getx(); public int gety(); public void move

More information

Class Libraries. Readings and References. Java fundamentals. Java class libraries and data structures. Reading. Other References

Class Libraries. Readings and References. Java fundamentals. Java class libraries and data structures. Reading. Other References Reading Readings and References Class Libraries CSE 142, Summer 2002 Computer Programming 1 Other References» The Java tutorial» http://java.sun.com/docs/books/tutorial/ http://www.cs.washington.edu/education/courses/142/02su/

More information

Wrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321

Wrapper Classes double pi = new Double(3.14); 3 double pi = new Double(3.14); 4... Zheng-Liang Lu Java Programming 290 / 321 Wrapper Classes To treat values as objects, Java supplies standard wrapper classes for each primitive type. For example, you can construct a wrapper object from a primitive value or from a string representation

More information

CS5233 Components Models and Engineering

CS5233 Components Models and Engineering CS5233 Components Models and Engineering - Komponententechnologien Master of Science (Informatik) Java Services Seite 1 Services Services Build-in technology Java 6 build-in technology to load services

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Version of January 21, 2013 Abstract Review of object-oriented programming concepts: Implementing

More information

Instance Members and Static Members

Instance Members and Static Members Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these

More information

Lecture 12: Classes II

Lecture 12: Classes II Lecture 12: Classes II Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Encapsulation Encapsulation encapsulation: Hiding

More information