Java0078 Java OOP Callbacks - II *
|
|
- Cuthbert Walters
- 5 years ago
- Views:
Transcription
1 OpenStax-CNX module: m Java0078 Java OOP Callbacks - II * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract A previous lesson introduced you to the basic Java callback mechanism using interfaces, and walked you through the development of a set of classes that implement a simple multicast form of callback. In that lesson, the denition of the CallBack interface was limited to a single method declaration. In a real program involving callbacks, many dierent objects may ask one object to notify them when any interesting event in a family of interesting events happens, and to identify the specic event that actually happened along with the notication. This lesson will enhance our previous program to accommodate this possibility. Revised: Tue Jul 05 19:16:25 CDT 2016 This page is included in the following Books: ITSE Java Programming (Intermediate) 1 Object-Oriented Programming (OOP) with Java 2 1 Table of contents Table of contents (p. 1) Preface (p. 2) Viewing tip (p. 2) * Figures (p. 2) * Listings (p. 2) Introduction (p. 2) Sample program (p. 3) Interesting code fragments (p. 3) Summary (p. 6) Complete program listing (p. 7) Miscellaneous (p. 12) * Version 1.3: Jul 5, :22 pm
2 OpenStax-CNX module: m Preface This is a page from the Event Handling 3 section of the book titled ITSE Java Programming (Intermediate) 4. The Event Handling section explains how to write programs that handle events in Java. This is the second in a series of three consecutive lessons on Callbacks in Java. The three lessons are named Callbacks - I, Callbacks - II, and Callbacks - III. Students in Prof. Baldwin's ITSE 2317 Intermediate Java Programming classes at ACC are responsible for knowing and understanding all of the material in this lesson. 2.1 Viewing tip I recommend that you open another copy of this module in a separate browser window and use the following links to easily nd and view the Figures and Listings while you are reading about them Figures Figure 1. (p. 6) Output from the program named Callback Listings Listing 1 (p. 4). The CallBack interface. Listing 2 (p. 4). The callrecess method in the Teacher class. Listing 3 (p. 5). The Dog class. Listing 4 (p. 5). The controlling class named Callback03. Listing 5 (p. 7). The program named Callback03. 3 Introduction Many processes in the standard Java API make use of a mechanism that in other programming environments might be referred to as a callback mechanism. Basically, this is a mechanism where a method in one object asks a method in another object to "call me back" or "notify me" when an interesting event happens. For example, an interesting event might be that the price of a specied stock goes above its previous high value, or the toaster nishes toasting the bread. A previous lesson introduced you to the basic Java callback mechanism using interfaces and walked you through the development of a set of classes that implement a simple multicast form of callback. In that lesson, the denition of the CallBack interface was limited to a single method declaration. In a real program involving callbacks, many dierent objects may ask one object to notify them when any interesting event in a family of interesting events happens, and to identify the specic event that actually happened along with the notication. This lesson will enhance our previous program to accommodate this possibility. As mentioned in the earlier lesson, it is usually easier to understand abstract concepts if they are explained in terms of a meaningful scenario. For that reason, we have conjured up a scenario in which to develop and explain our callback programs. Our scenario consists of a teacher and some students. In the beginning there was only one student. Then we expanded the scenario to include many students and some animals in the classroom as well. The students (and the animals) register themselves on the teachers roll book to be notied of interesting events. Initially the interesting event was simply the teacher taking the roll. In this lesson, we expand that scenario to include notication that it is either time for recess, or it is time for lunch
3 OpenStax-CNX module: m Initially, only one student received notication of one type of event. In this lesson, all of the students and all of the animals receive notication of both types of event (recess or lunch) but some of those who are notied choose to ignore the notication. Without further discussion, let's look at some code. 4 Sample program In case you just started reading at this point, this program named Callback03 is an enhanced version of the program named Callback02 that you learned about in an earlier 5 lesson. You should familiarize yourself with the earlier program before trying to understand this program. The earlier version of the program dened two dierent classes that implemented the CallBack interface. In order to give us more to work with, this version denes three dierent classes named Student, Dog, and Cat that implement the CallBack interface. Mixed objects of those three types are registered and maintained on a list and notied at callback time. As before, this program denes a CallBack interface. However, this version of the interface declares two dierent methods that can be invoked as callback methods instead of just one. In other words, in this case, the objects register to be notied whenever an interesting event from a family of interesting events occurs (the family has two members). When notied, the objects also need to be advised as to which interesting event actually happened. The methodology for dierentiating between the two dierent kinds of interesting events is to invoke one callback method in the case of one event, and to invoke the other callback method in the case of the other event. All classes that implement the CallBack interface must dene both methods, but it is allowable to dene the method as an empty method. The net eect of dening a callback method as an empty method is to simply ignore the callback associated with that method. Note however, there is some overhead associated with the invocation of an empty method. (Although we haven't discussed the topic yet, I believe that this overhead is the reason that JavaSoft chose to separate the MouseListener and MouseMotionListener interfaces. Perhaps someone will remember to remind me to discuss that when we get to the topic of MouseMotionListener interface in the classroom lecture.) One of the callback methods in this version of our program is named recess and the other callback method is named lunch. Thus, registered objects can be notied either of a recess event, or of a lunch event. The Dog class ignores the recess callback by dening an empty recess method, and the Cat class ignores the lunch callback by dening an empty lunch method. The Student class responds to both types of callbacks with fully- dened methods. The program denes a Teacher class that has the ability to create and maintain a list of objects of the interface type, and to notify those objects that something interesting has happened by invoking either the recess method or the lunch method on all the objects on the list. It is important to note that every object on the list will be notied of both types of callbacks, although as mentioned above, a particular type of callback can be ignored by a class simply by leaving the callback method empty when it is dened. As before, objects can be added to the list and then removed from the list. However, removal of objects from the list was demonstrated in the previous program, so removal is not demonstrated in this program. Notication takes the form of invoking either the recess method or the lunch method on all the objects on the list. Finally, the program denes a controlling class that ties all the pieces together and exercises them. The program was originally tested using JDK under Win95. The program was more recently retested using JDK 8 and Win7. The output from the program is shown later. 4.1 Interesting code fragments The code in Listing 1 (p. 4) denes an interface named CallBack that will create a new type and that declares two generic methods that can be used to call back any object that is of a class that implements the 5
4 OpenStax-CNX module: m interface. Listing 1. The CallBack interface. interface CallBack{ public void recess(); public void lunch(); }//end interface CallBack Listing 2 (p. 4) denes a class whose objects can maintain a list of registered objects (registration is the process of placing an object on the list) of type CallBack and can notify all the objects on that list when something interesting happens. This class diers form the one in the earlier lesson in that it has the ability to notify for two dierent types of callbacks: recess and lunch. The name of this class is Teacher. The code to construct the Teacher object, add objects to the list, and remove objects from the list hasn't changed in a signicant way, so we will skip over that code and go straight to the code that is new and dierent. Basically what we now have is two dierent methods in place of one. One of the methods is named callrecess and the other is named calllunch. Except for their names, these methods are almost identical to the single method named calltheroll in the earlier lesson, so a lot of discussion isn't needed. The code in the method makes a copy of the list and then uses a for loop along with some Vector methods to access each object reference. Then the callback method is invoked on each object reference. We will show one of the methods below for reference. Listing 2. The callrecess method in the Teacher class. void callrecess(){ Vector templist;//save a temporary copy of list here //Make a copy of the list. synchronized(this){ templist = (Vector)objList.clone(); }//end synchronized block //Invoke the recess() method on each object on // the list. for(int cnt = 0; cnt < templist.size(); cnt++){ ((CallBack)tempList.elementAt(cnt)).recess(); }//end for loop }//end callrecess() That concludes the discussion of the class named Teacher. The Teacher class is followed by three class denitions that implement the CallBack interface: Student, Dog, and Cat. These class denitions dier from the ones in the earlier lesson in that they dene two callback methods instead of just one: recess and lunch. Recall that I said that a class can ignore a particular type of callback simply by dening the callback method as an empty method. Recall also that I said that the Dog class ignores the recess() callback in just this way. Because of the similarity of these three classes, I am only going to show one of them below. Listing 3 (p. 5) shows the Dog class to illustrate how it denes an empty method to ignore the recess callback.
5 OpenStax-CNX module: m Listing 3. The Dog class. class Dog implements CallBack{ String name; //store name here for later ID Dog(String name){//constructor this.name = name; //save the name to identify the obj }//end constructor //An object of the Teacher class can invoke this method // as the callback mechanism. public void recess(){//announce recess //ignore this callback with an empty method }//end overridden recess() //An object of the Teacher class can also invoke this // method as a callback mechanism. public void lunch(){//announce recess System.out.println(name + " lunch"); }//end overridden lunch() }//end class Dog That brings us to the controlling class that ties all the pieces together and exercises them (see Listing 4 (p. 5) ). Except for the fact that the main method triggers two callbacks instead of just one, and the code to remove an object from the list was deleted for brevity, this code is essentially the same as the code in the earlier lesson. Therefore, I am going to delete some of the redundant code from this fragment and primarily show only the new code. The code in the main method of the controlling class instantiates a Teacher object named missjones, and then instantiates some objects of the three types: Student, Dog, and Cat. These objects are registered for callback by invoking the register method on the Teacher object. Then the code triggers a recess callback and a lunch callback. Listing 4. The controlling class named Callback03. class Callback03{ public static void main(string[] args){ //Instantiate Teacher object Teacher missjones = new Teacher(); //Instantiate some Student objects //... code deleted for brevity //Instantiate some Dog objects. //... code deleted for brevity //Instantiate some Cat objects
6 OpenStax-CNX module: m //... code deleted for brevity //Register some Student, Dog, and Cat objects with // the Teacher object. missjones.register(tom); missjones.register(spot); missjones.register(sue); missjones.register(cleo); missjones.register(fido); missjones.register(peg); missjones.register(kitty); missjones.register(bob); missjones.register(brownie); //Cause the Teacher object to call recess on all // the objects on the list. missjones.callrecess(); //Cause the Teacher object to call lunch on all // the objects on the list. missjones.calllunch(); }//end main() }//end class Callback03 The output produced by this program is shown in Figure 1 (p. 6). Figure 1. Output from the program named Callback03. Tom recess Sue recess CleoCat recess Peg recess KittyKat recess Bob recess Tom lunch SpotDog lunch Sue lunch FidoDog lunch Peg lunch Bob lunch BrownieDog lunch 5 Summary In summary then, we have objects of dierent classes registered on a common callback list where every object on the list receives a callback for every dierent type of callback event associated with the list. The dierent types of callbacks are established by the method declarations in the CallBack interface. Each class of object that registers for callbacks can either respond to all of the dierent types of callbacks by providing full denitions for all of the callback methods, or can selectively ignore some types of callbacks by dening those callback methods as empty methods.
7 OpenStax-CNX module: m Complete program listing A complete listing of the program named Callback03 is shown in Listing 5 (p. 7). Listing 5. The program named Callback03. /*File Callback03.java Copyright 1997, R.G.Baldwin The purpose of this program is to develop a callback capability using Interfaces. This is an enhanced version of the program named Callback02. You should familiarize yourself with the earlier program before getting into this program. This version defines three different classes named Student, Dog, and Cat that implement the CallBack interface. Mixed objects of those three types are maintained on a list and notified at CallBack time. As before, this program defines a CallBack interface that can be used to establish a new type of object. This version of the interface declares two different methods that can be invoked as callback methods instead of just one. All classes that implement the interface must define both methods, but it is allowable to define the method as an empty method and ignore the callback associated with a particular method. One of the callback methods is now called recess() and the other is called lunch(). The Dog class ignores the recess() callback by defining an empty method, and the Cat class ignores the lunch() callback by defining an empty method. The Student class responds to both types of callbacks with fullydefined methods. The program defines a Teacher class that has the ability to create and maintain a list of objects of the interface type, and to notify those objects that something interesting has happened by invoking either the recess() method or the lunch() method on all the objects on the list. It is important to note that every object on the list will be notified of both types of callback, although as mentioned above, a particular type of callback can be ignored simply by leaving the method empty when it is defined. Note that objects can be added to the list and then removed from the list. However, removal of objects from
8 OpenStax-CNX module: m the list was demonstrated in the previous program, so removal is not demonstrated in this program. As always, notification takes the form of invoking either the recess() method or the lunch() method on all the objects on the list. Finally, the program defines a controlling class that ties all the pieces together and exercises them. Tested using JDK under Win95. The output from the program was: Tom recess Sue recess CleoCat recess Peg recess KittyKat recess Bob recess Tom lunch SpotDog lunch Sue lunch FidoDog lunch Peg lunch Bob lunch BrownieDog lunch **********************************************************/ import java.util.*; //First we define an interface that will create a new type // and declare two generic methods that can be used to // callback any object that is of a class that implements // the interface. interface CallBack{ public void recess(); public void lunch(); }//end interface CallBack //=======================================================// //Next we need a class whose objects can maintain a // registered list of objects of type CallBack and can // notify all the objects on that list when something // interesting happens. This class has the ability to // notify of two different types of callbacks, recess() // and lunch(). class Teacher{ Vector objlist; //list of objects of type CallBack
9 OpenStax-CNX module: m Teacher(){//constructor //Instantiate a Vector object to contain the list // of registered objects. objlist = new Vector(); }//end constructor //Method to add objects to the list. synchronized void register(callback obj){ this.objlist.addelement(obj); }//end register() //Method to remove objects from the list. synchronized void unregister(callback obj){ if(this.objlist.removeelement(obj)) System.out.println(obj + " removed"); else System.out.println(obj + " not in the list"); }//end register() //Method to notify all objects on the list that // something interesting has happened regarding recess. void callrecess(){ Vector templist;//save a temporary copy of list here //Make a copy of the list. synchronized(this){ templist = (Vector)objList.clone(); }//end synchronized block //Invoke the recess() method on each object on // the list. for(int cnt = 0; cnt < templist.size(); cnt++){ ((CallBack)tempList.elementAt(cnt)).recess(); }//end for loop }//end callrecess() //Method to notify all objects on the list that // something interesting has happened regarding lunch. void calllunch(){ Vector templist;//save a temporary copy of list here //Make a copy of the list. synchronized(this){ templist = (Vector)objList.clone(); }//end synchronized block //Invoke the lunch() method on each object on // the list.
10 OpenStax-CNX module: m for(int cnt = 0; cnt < templist.size(); cnt++){ ((CallBack)tempList.elementAt(cnt)).lunch(); }//end for loop }//end callrecess() }//end class Teacher //=======================================================// //Class that implements the CallBack interface. Objects // of this class can be registered on the list maintained // by an object of the Teacher class, and will be notified // whenever that object invokes either the recess() method // or the lunch() method on the registered objects on // the list. This method provides a full definition for // both methods. class Student implements CallBack{ String name; //store the object name here for later ID Student(String name){//constructor this.name = name; //save the name to identify the obj }//end constructor //An object of the Teacher class can invoke this method // as a callback mechanism. public void recess(){//announce recess System.out.println(name + " recess"); }//end overridden recess() //An object of the Teacher class can also invoke this // method as a callback mechanism. public void lunch(){//announce recess System.out.println(name + " lunch"); }//end overridden lunch() }//end class Student //=======================================================// //Another Class that implements the CallBack interface. // See description above. This class defines the recess() // method as an empty method. class Dog implements CallBack{ String name; //store name here for later ID Dog(String name){//constructor
11 OpenStax-CNX module: m this.name = name; //save the name to identify the obj }//end constructor //An object of the Teacher class can invoke this method // as the callback mechanism. public void recess(){//announce recess //ignore this callback with an empty method }//end overridden recess() //An object of the Teacher class can also invoke this // method as a callback mechanism. public void lunch(){//announce recess System.out.println(name + " lunch"); }//end overridden lunch() }//end class Dog //=======================================================// //A third Class that implements the CallBack interface, // similar to the other two classes. This class defines // the lunch() method as an empty method. class Cat implements CallBack{ String name; //store name here for later ID Cat(String name){//constructor this.name = name; //save the name to identify the obj }//end constructor //An object of the Teacher class can invoke this method // as the callback mechanism. public void recess(){//announce recess System.out.println(name + " recess"); }//end overridden recess() //An object of the Teacher class can also invoke this // method as a callback mechanism. public void lunch(){//announce recess //ignore this callback with an empty method }//end overridden lunch() }//end class Cat //=======================================================// //Controlling class that ties all the pieces together and // exercises them.
12 OpenStax-CNX module: m class Callback03{ public static void main(string[] args){ //Instantiate Teacher object Teacher missjones = new Teacher(); //Instantiate some Student objects Student tom = new Student("Tom"); Student sue = new Student("Sue"); Student peg = new Student("Peg"); Student bob = new Student("Bob"); Student joe = new Student("Joe"); //Instantiate some Dog objects. Dog spot = new Dog("SpotDog"); Dog fido = new Dog("FidoDog"); Dog brownie = new Dog("BrownieDog"); //Instantiate some Cat objects Cat cleo = new Cat("CleoCat"); Cat kitty = new Cat("KittyKat"); //Register some Student, Dog, and Cat objects with // the Teacher object. missjones.register(tom); missjones.register(spot); missjones.register(sue); missjones.register(cleo); missjones.register(fido); missjones.register(peg); missjones.register(kitty); missjones.register(bob); missjones.register(brownie); //Cause the Teacher object to call recess on all // the objects on the list. missjones.callrecess(); //Cause the Teacher object to call lunch on all // the objects on the list. missjones.calllunch(); }//end main() }//end class Callback03 //=======================================================// 7 Miscellaneous This section contains a variety of miscellaneous information. Housekeeping material Module name: Java0078 Java OOP Callbacks - II File: Java0078.htm
13 OpenStax-CNX module: m Published: 1997 Disclaimers: Financial : Although the Connexions site makes it possible for you to download a PDF le for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF le, you should be aware that some of the HTML elements in this module may not translate well into PDF. I also want you to know that, I receive no nancial compensation from the Connexions website even if you purchase the PDF version of the module. In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge. Aliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX. -end
Java3018: Darkening, Brightening, and Tinting the Colors in a Picture *
OpenStax-CNX module: m44234 1 Java3018: Darkening, Brightening, and Tinting the Colors in a Picture * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution
More informationOpenStax-CNX module: m Java3002r Review * R.G. (Dick) Baldwin
OpenStax-CNX module: m45762 1 Java3002r Review * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract This module contains
More informationJava OOP: Java Documentation
OpenStax-CNX module: m45117 1 Java OOP: Java Documentation R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract Learn to use
More informationJava4340r: Review. R.G. (Dick) Baldwin. 1 Table of Contents. 2 Preface
OpenStax-CNX module: m48187 1 Java4340r: Review R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract This module contains review
More informationJava4350: Form Processing with JSP
OpenStax-CNX module: m48085 1 Java4350: Form Processing with JSP R.L. Martinez, PhD This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract This module
More informationHs01006: Language Features, Arithmetic Operators *
OpenStax-CNX module: m37146 1 Hs01006: Language Features, Arithmetic Operators * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0
More informationJava4320: Web Programming Model *
OpenStax-CNX module: m48058 1 Java4320: Web Programming Model * R.L. Martinez, PhD This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract The purpose
More informationJava4570: Session Tracking using Cookies *
OpenStax-CNX module: m48571 1 Java4570: Session Tracking using Cookies * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract
More informationJava3002: Creating and Manipulating Turtles and Pictures in a World Object
OpenStax-CNX module: m44149 1 Java3002: Creating and Manipulating Turtles and Pictures in a World Object R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons
More informationJava3002: Creating and Manipulating Turtles and Pictures in a World Object *
OpenStax-CNX module: m44149 1 Java3002: Creating and Manipulating Turtles and Pictures in a World Object * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons
More informationAuthoring OpenStax Documents in Apache OpenOffice Writer *
OpenStax-CNX module: m60462 1 Authoring OpenStax Documents in Apache OpenOffice Writer * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License
More informationAP Computer Science A, Clarification of the Java Subset. By: R.G. (Dick) Baldwin
AP Computer Science A, Clarification of the Java Subset By: R.G. (Dick) Baldwin AP Computer Science A, Clarification of the Java Subset By: R.G. (Dick) Baldwin Online: < http://cnx.org/content/col11279/1.4/
More informationINEW Advanced Java Programming. Collection Editor: R.G. (Dick) Baldwin
INEW2338 - Advanced Java Programming Collection Editor: R.G. (Dick) Baldwin INEW2338 - Advanced Java Programming Collection Editor: R.G. (Dick) Baldwin Authors: R.G. (Dick) Baldwin R.L. Martinez, PhD
More informationAccessible Objected-Oriented Programming Concepts for Blind Students using Java. By: R.G. (Dick) Baldwin
Accessible Objected-Oriented Programming Concepts for Blind Students using Java By: R.G. (Dick) Baldwin Accessible Objected-Oriented Programming Concepts for Blind Students using Java By: R.G. (Dick)
More informationMorse1010 Translating Text to Morse Code *
OpenStax-CNX module: m60489 1 Morse1010 Translating Text to Morse Code * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract
More informationUsing Flex 3 in a Flex 4 World *
OpenStax-CNX module: m34631 1 Using Flex 3 in a Flex 4 World * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract Learn how
More informationThe json-simple Java Library. By: R.G. (Dick) Baldwin
The json-simple Java Library By: R.G. (Dick) Baldwin The json-simple Java Library By: R.G. (Dick) Baldwin Online: < http://cnx.org/content/col12010/1.4/ > OpenStax-CNX This selection and arrangement of
More informationPolymorphism - The Big Picture *
OpenStax-CNX module: m34447 1 Polymorphism - The Big Picture * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Learn the essence
More informationThe Essence of OOP using Java, Nested Top-Level Classes. Preface
The Essence of OOP using Java, Nested Top-Level Classes Baldwin explains nested top-level classes, and illustrates a very useful polymorphic structure where nested classes extend the enclosing class and
More informationGAME : Vector Addition *
OpenStax-CNX module: m45012 1 GAME 2302-0125: Vector Addition * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract Learn
More informationGAME Motion Displacement and Vectors
OpenStax-CNX module: m45006 1 GAME 2302-0360 Motion Displacement and Vectors R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract
More informationJava OOP: Modifications to the Turtle and SimpleTurtle Classes
OpenStax-CNX module: m44348 1 Java OOP: Modifications to the Turtle and SimpleTurtle Classes R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution
More informationExercise: Singleton 1
Exercise: Singleton 1 In some situations, you may create the only instance of the class. 1 class mysingleton { 2 3 // Will be ready as soon as the class is loaded. 4 private static mysingleton Instance
More informationJava1486-Fun with Java, Understanding the Fast Fourier Transform (FFT) Algorithm *
OpenStax-CNX module: m49801 1 Java1486-Fun with Java, Understanding the Fast Fourier Transform (FFT) Algorithm * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative
More informationThe AWT Package, Graphics- Introduction to Images
Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Graphics- Introduction to Images Java Programming, Lecture Notes # 170, Revised 09/23/98.
More informationThe AWT Package, Placing Components in Containers, CardLayout. Preface. Introduction
Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Placing Components in Containers, CardLayout Java Programming, Lecture Notes # 120, Revised
More informationSwing from A to Z Some Simple Components. Preface
By Richard G. Baldwin baldwin.richard@iname.com Java Programming, Lecture Notes # 1005 July 31, 2000 Swing from A to Z Some Simple Components Preface Introduction Sample Program Interesting Code Fragments
More informationThe Processing Programming Environment. By: Richard Baldwin
The Processing Programming Environment By: Richard Baldwin The Processing Programming Environment By: Richard Baldwin Online: < http://cnx.org/content/col11492/1.5/ > C O N N E X I O N S Rice University,
More informationJavaBeans, Properties of Beans, Constrained Properties
Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ JavaBeans, Properties of Beans, Constrained Properties Java Programming, Lecture Notes # 512, Revised 02/19/98.
More informationThe Default Application Container - Flex 3 and Flex 4 *
OpenStax-CNX module: m34604 1 The Default Application Container - Flex 3 and Flex 4 * R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License
More informationOS06: Monitors in Java
OS06: Monitors in Java Based on Chapter 4 of [Hai17] Jens Lechtenbörger Computer Structures and Operating Systems 2018 1 Introduction 1.1 OS Plan ˆ OS Motivation (Wk 23) ˆ OS Introduction (Wk 23) ˆ Interrupts
More informationChapter Two Bonus Lesson: JavaDoc
We ve already talked about adding simple comments to your source code. The JDK actually supports more meaningful comments as well. If you add specially-formatted comments, you can then use a tool called
More informationMultimedia Programming with Java Getting Started
Multimedia Programming with Java Getting Started Learn how to download, install, and test a Java multimedia library developed by Mark Guzdial and Barbara Ericson at Georgia Tech. Also learn how to download,
More informationSwing from A to Z Using Focus in Swing, Part 2. Preface
Swing from A to Z Using Focus in Swing, Part 2 By Richard G. Baldwin Java Programming, Lecture Notes # 1042 November 27, 2000 Preface Introduction Sample Program Interesting Code Fragments Summary What's
More informationPosition vs Time Graphs *
OpenStax-CNX module: m54110 1 Position vs Time Graphs * OpenStax HS Physics This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 1 : By the end of this
More informationHow to make a "hello world" program in Java with Eclipse *
OpenStax-CNX module: m43473 1 How to make a "hello world" program in Java with Eclipse * Hannes Hirzel Based on How to make a "hello world" program in Java. by Rodrigo Rodriguez This work is produced by
More informationTutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment
60-212 subir@cs.uwindsor.ca Phone # 253-3000 Ext. 2999 web site for course www.cs.uwindsor.ca/60-212 Dr. Subir Bandyopadhayay Website has detailed rules and regulations All assignments and labs will be
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 31 Static Members Welcome to Module 16 of Programming in C++.
More informationCHAPTER. Knowledge Representation
CHAPTER Knowledge Representation 3 If, for a given problem, we have a means of checking a proposed solution, then we can solve the problem by testing all possible answers. But this always takes much too
More informationAustin Community College Google Apps Calendars Step-by-Step Guide
The topics that will be covered in this workshop: Access (p.2) Calendar Settings (p.2) o General Tab (p.2) o Calendar Tab (p.3) Change Calendar Color (p.3) Calendar Notifications (p.4) Sharing (p.4) o
More informationXna0118-The XNA Framework and. the Game Class
OpenStax-CNX module: m49509 1 Xna0118-The XNA Framework and * the Game Class R.G. (Dick) Baldwin This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 4.0 Abstract
More informationIntersection of sets *
OpenStax-CNX module: m15196 1 Intersection of sets * Sunil Kumar Singh This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 2.0 We have pointed out that a set
More informationPeopleSoft 9.1 PeopleBook: Events and Notifications Framework
PeopleSoft 9.1 PeopleBook: Events and Notifications Framework March 2012 PeopleSoft 9.1 PeopleBook: Events and Notifications Framework SKU hcm91fp2eewh-b0312 Copyright 1988, 2012, Oracle and/or its affiliates.
More informationWeek - 01 Lecture - 04 Downloading and installing Python
Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and
More informationThe need for interfaces
Interfaces The need for interfaces The code for pricing a CallOption and the code for pricing a PutOption by Monte Carlo is identical apart from the specication of the type of the option. The fantasy code
More informationExercise 6 - Addressing a Message
Exercise 6 - Addressing a Message All e-mail messages have to include an address for an e-mail to be delivered, just as a normal letter has to have a house address. An e-mail address is made up of: a user
More informationJava Classes - Using your classes. How the classes you write are being used
Java Classes - Using your classes How the classes you write are being used What s the use of classes? So, you have been writing a few classes by now... What for? The programs you will write will use objects
More informationMidterms Save the Dates!
University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Instance Variables if Statements Readings This Week s Reading: Review Ch 1-4 (that were previously assigned) (Reminder: Readings
More informationInstance 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 informationStaff Directory & Online Classroom: A Picture Book
Staff Directory & Online Classroom: A Picture Book eleventh in a series By Dennis Sulfsted Technology Coordinator Reading Community City Schools Holly Approved 2007 HRF Publications All current Picture
More informationProcessing Image Pixels, Creating Visible Watermarks in Java. Preface
Processing Image Pixels, Creating Visible Watermarks in Java Learn how to write a Java program that can be used to add five different types of visible watermarks to an image. Published: December 19, 2006
More informationPart 2: The Material PART 2
PART 2 With the introduction of what an object is, now we are ready to learn the CONSTRUCTOR concept. Just to refresh our memory, let s take a look at what we have learned in part 1. A sample class declaration,
More informationCOMP200 INTERFACES. OOP using Java, from slides by Shayan Javed
1 1 COMP200 INTERFACES OOP using Java, from slides by Shayan Javed Interfaces 2 ANIMAL picture food sleep() roam() makenoise() eat() 3 ANIMAL picture food sleep() roam() makenoise() eat() 4 roam() FELINE
More informationInDesign UX Design Patterns. by Justin Putney
InDesign UX Design Patterns by Justin Putney InDesign UX Design Patterns Hi, I m Justin Putney, Owner of Ajar Productions. Thanks for downloading this guide! It s full of ways to create interactive user
More informationCPSC 320 Sample Solution, Playing with Graphs!
CPSC 320 Sample Solution, Playing with Graphs! September 23, 2017 Today we practice reasoning about graphs by playing with two new terms. These terms/concepts are useful in themselves but not tremendously
More informationThe Law of Reflection *
OpenStax-CNX module: m42456 1 The Law of Reflection * OpenStax This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract Explain reection of light from
More informationAbout 1. Chapter 1: Getting started with oop 2. Remarks 2. Examples 2. Introduction 2. OOP Introduction 2. Intoduction 2. OOP Terminology 3.
oop #oop Table of Contents About 1 Chapter 1: Getting started with oop 2 Remarks 2 Examples 2 Introduction 2 OOP Introduction 2 Intoduction 2 OOP Terminology 3 Java 3 C++ 3 Python 3 Java 4 C++ 4 Python
More informationUSE #4 TO EXPORT FOR SINGLE PETS OR SKIP TO #5 TO EXPORT FOR
ONLINE REMINDERS Thank you for registering for IntraVet s Online Reminder Solution. Below you will find instructions on how to export your reminder database and how to upload them to the website. It is
More informationCreate a Java project named week10
Objectives of today s lab: Through this lab, students will examine how casting works in Java and learn about Abstract Class and in Java with examples. Create a Java project named week10 Create a package
More informationCIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)
CIS 110: Introduction to Computer Programming Lecture 2 Decomposition and Static Methods ( 1.4) Outline Structure and redundancy in algorithms Static methods Procedural decomposition 9/16/2011 CIS 110
More informationAP Computer Science A Summer Assignment 2017
AP Computer Science A Summer Assignment 2017 The objective of this summer assignment is to ensure that each student has the ability to compile and run code on a computer system at home. We will be doing
More informationProblem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur
Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Introduction to Programming Language Concepts
More informationAdobe InDesign CS6 Revealed (Adobe CS6) PDF
Adobe InDesign CS6 Revealed (Adobe CS6) PDF Graphic design professionals and design students alike have embraced Adobe InDesign as the industry standard for page layout softwareâ and they're mastering
More informationStatic, Final & Memory Management
Static, Final & Memory Management The static keyword What if you want to have only one piece of storage regardless of how many objects are created or even no objects are created? What if you need a method
More informationCS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.
CS 1331 Exam 1 Fall 2016 Name (print clearly): GT account (gpburdell1, msmith3, etc): Section (e.g., B1): Signature: Failure to properly fill in the information on this page will result in a deduction
More informationC. E. McDowell August 25, Baskin Center for. University of California, Santa Cruz. Santa Cruz, CA USA. abstract
Unloading Java Classes That Contain Static Fields C. E. McDowell E. A. Baldwin 97-18 August 25, 1997 Baskin Center for Computer Engineering & Information Sciences University of California, Santa Cruz Santa
More informationExample: Count of Points
Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers
CS 2112 Lecture 20 Synchronization 5 April 2012 Lecturer: Andrew Myers 1 Critical sections and atomicity We have been seeing that sharing mutable objects between different threads is tricky We need some
More informationIntroduction. Paradigm Publishing. SNAP for Microsoft Office SNAP for Our Digital World. System Requirements
Introduction Paradigm Publishing Paradigm understands the needs of today s educators and exceeds the demand by offering the latest technological advancements for coursework settings. With the success of
More informationCOMP 250 Winter 2011 Reading: Java background January 5, 2011
Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP
More information1 10 3:30 5: :30 1:30 206, ICICS/CS
Department of Computer Science Undergraduate Events Events this week Resume Editing Drop-In Session Date: Mon., Feb 1 Time: 11 am 2 pm Location: Rm 255, ICICS/CS EADS Info Session Date: Mon., Feb 1 Time:
More informationVITA VOLUNTEER TRAINING MANUAL
VITA VOLUNTEER TRAINING MANUAL You are about to make a real difference in peoples lives! We hope you are as excited as we are. Table Of Contents... 1 How To Use This Guide... 2 What Type Of Certifications
More informationSummer Assignment for AP Computer Science. Room 302
Fall 2016 Summer Assignment for AP Computer Science email: hughes.daniel@north-haven.k12.ct.us website: nhhscomputerscience.com APCS is your subsite Mr. Hughes Room 302 Prerequisites: You should have successfully
More informationTips from the experts: How to waste a lot of time on this assignment
Com S 227 Spring 2018 Assignment 1 80 points Due Date: Friday, February 2, 11:59 pm (midnight) Late deadline (25% penalty): Monday, February 5, 11:59 pm General information This assignment is to be done
More informationProgramming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism
Programming using C# LECTURE 07 Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism What is Inheritance? A relationship between a more general class, called the base class
More informationCS1004: Intro to CS in Java, Spring 2005
CS1004: Intro to CS in Java, Spring 2005 Lecture #23: OO Design, cont d. Janak J Parekh janak@cs.columbia.edu Administrivia HW#5 due Tuesday And if you re cheating on (or letting others see your) HW#5
More informationWhat is an Affine Transform?
February 9, 2000 Java 2D Graphics, Simple Affine Transforms Java Programming, Lecture Notes # 306 by Richard G. Baldwin baldwin@austin.cc.tx.us Introduction What is an Affine Transform? Don t Panic! What
More informationSpring 2019 Discussion 4: February 11, 2019
CS 61B Inheritance Spring 2019 Discussion 4: February 11, 2019 JUnit Tests 1.1 Think about the lab you did last week where we did JUnit testing. The following code is a few of these JUnit tests from the
More informationHAS-A Relationship. If A uses B, then it is an aggregation, stating that B exists independently from A.
HAS-A Relationship Association is a weak relationship where all objects have their own lifetime and there is no ownership. For example, teacher student; doctor patient. If A uses B, then it is an aggregation,
More informationGUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline
Sequential vs. Event-driven Programming Reacting to the user GUI Program Organization Let s digress briefly to examine the organization of our GUI programs We ll do this in stages, by examining three example
More informationDatabase Systems Concepts *
OpenStax-CNX module: m28156 1 Database Systems Concepts * Nguyen Kim Anh This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 Abstract This module introduces
More informationInheritance 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 informationNew Perspectives on Word 2016 Instructor s Manual 1 of 10
New Perspectives on Word 2016 Instructor s Manual 1 of 10 New Perspectives Microsoft Office 365 And Word 2016 Introductory 1st Edition Shaffer SOLUTIONS MANUAL Full download at: https://testbankreal.com/download/new-perspectives-microsoft-office-365-
More informationName: Magpie Chatbot Lab: Student Guide. Introduction
Magpie Chatbot Lab: Student Guide Introduction From Eliza in the 1960s to Siri and Watson today, the idea of talking to computers in natural language has fascinated people. More and more, computer programs
More informationG51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread
G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals
More informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
More informationCSCI 201L Written Exam #1 Fall % of course grade
Final Score /15 Name SOLUTION ID Extra Credit /0.5 Lecture Section (circle one): TTh 8:00-9:20 TTh 9:30-10:50 TTh 11:00-12:20 CSCI 201L Written Exam #1 Fall 2017 15% of course grade The exam is one hour
More informationLesson 2 page 1. ipad # 17 Font Size for Notepad (and other apps) Task: Program your default text to be smaller or larger for Notepad
Lesson 2 page 1 1/20/14 Hi everyone and hope you feel positive about your first week in the course. Our WIKI is taking shape and I thank you for contributing. I have had a number of good conversations
More informationOutline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations
Outline Computer Science 331 Data Structures, Abstract Data Types, and Their Implementations Mike Jacobson 1 Overview 2 ADTs as Interfaces Department of Computer Science University of Calgary Lecture #8
More informationUS Technology Informational Meeting
US Technology Informational Meeting Tuesday, May 17, 2016 8:00 am B.Y.O.D. Bring Your Own Device Tuesday, May 17, 2016 8:00 am M.S. & H.S. Technology Information No smart phones or cell phones are allowed
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More informationCS506 Web Design & Development Final Term Solved MCQs with Reference
with Reference I am student in MCS (Virtual University of Pakistan). All the MCQs are solved by me. I followed the Moaaz pattern in Writing and Layout this document. Because many students are familiar
More informationSt. Edmund Preparatory High School Brooklyn, NY
AP Computer Science Mr. A. Pinnavaia Summer Assignment St. Edmund Preparatory High School Name: I know it has been about 7 months since you last thought about programming. It s ok. I wouldn t want to think
More informationInvestigate and compare 2-dimensional shapes *
OpenStax-CNX module: m30563 1 Investigate and compare 2-dimensional shapes * Siyavula Uploaders This work is produced by OpenStax-CNX and licensed under the Creative Commons Attribution License 3.0 1 MATHEMATICS
More informationDigital Marketing Manager, Marketing Manager, Agency Owner. Bachelors in Marketing, Advertising, Communications, or equivalent experience
Persona name Amanda Industry, geographic or other segments B2B Roles Digital Marketing Manager, Marketing Manager, Agency Owner Reports to VP Marketing or Agency Owner Education Bachelors in Marketing,
More informationC Language Programming through the ADC and the MSP430 (ESCAPE)
OpenStax-CNX module: m46087 1 C Language Programming through the ADC and the MSP430 (ESCAPE) Matthew Johnson Based on C Language Programming through the ADC and the MSP430 by Matthew Johnson This work
More informationCS112 Lecture: Defining Classes. 1. To describe the process of defining an instantiable class
CS112 Lecture: Defining Classes Last revised 2/3/06 Objectives: 1. To describe the process of defining an instantiable class Materials: 1. BlueJ SavingsAccount example project 2. Handout of code for SavingsAccount
More information