New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

Chapter 3: Object Interaction

by: AnnMarie

Chapter 3: Object Interaction CSC 120

Marketplace > Louisiana Tech University > ComputerScienence > CSC 120 > Chapter 3 Object Interaction

GPA 3.028

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

These notes information about chapter 3 and contains 13 sections.
Debra Blackman
Class Notes
25 ?





Popular in ComputerScienence

This 7 page Class Notes was uploaded by AnnMarie on Friday January 8, 2016. The Class Notes belongs to CSC 120 at Louisiana Tech University taught by Debra Blackman in Winter 2015. Since its upload, it has received 37 views. For similar materials see INTRODUCTION TO COMPUTER PROGRAM in ComputerScienence at Louisiana Tech University.

Popular in ComputerScienence


Reviews for Chapter 3: Object Interaction


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 01/08/16
Chapter 3: Object Interaction In this chapter the main concepts discussed are abstraction, modularization, object creation, object diagrams, method calls, and debuggers. Java constructs discussed in this chapter are class types, logic operaors, string concatenation, module operator, object construction, method calls, and the keyword this. The textbook uses clock-display to explain abstraction, modularization, class types, class diagrams, object diagrams, object references, logic operators, string concatenation, module operator, object construction, and method calls. The mail-system project assists in explaining debuggers and the this keyword. 3.1 The Clock Example The clock-display project is used to discuss the interaction of objects. The clock-display is a digitial clock that displays hours and minutes, separated by a colon. The display is in European-syle 24-hour due to building a 12-hour clock display being slighlty more difficult.Also they leave this slightly more difficult problem as a challenge exercise. 3.2 Abstraction and Modularization As we have seen in the previous chapter projects the complexity of the issue was simple enough to limit it to one class. However, for complex problems keeping track of all the details at the same time becomes difficult. For instance if you had to remember all the components that make up a car you would at somepoint lose track of something. To assist in solving a complex problem we use a technique called divide and conquer. This allows us to divide a complex problem into sub-problems, and then divide the sub-problems into sub-sub-problems, and so one. Once we solve one of the sub-problems, we dont think of about the details of that part anymore, but treat the solution as a building block for the next problem. In other words we abstract from the solution of a sub-problem to focus on the higher level of a problem. Modularization is the process of dividing an complex problem into independent modules. By dividing a complex problem into independent modules it allows you or someone else to work on separate modules independently instead of having to look at the whole problem at once. To summarize we can see that abstraction is the ability to ignore details of parts, to focus attention on a higher level of a problem. Whereas, modularization is process of dividing large things (problems) into smaller part. The two work hand-in-hand just like the term divide and conquer. 3.3 Abstraction in Software We can use abstraction and modularization in software developement. To help maintian an overview of a complex program, we try to identify the subcomponents as if they are simple parts. We abstract from their inner complexities. In object-orientated programming, the components and subcomponents are objects (instances). We see this concept in use in the clock-display program. 3.4 Modularization in The Clock Example If you look at a clock display can you see a way to divide the clock up into smaller parts? If you think that the answer is yes, then you are correct because the clock display consists of a single display with four digits – two digits for hours and two digits for minutes. Now, abstract away from the low-level view of four digits, what do you see? Well, you should be able to see that the display can be viewed as two separate two-digit displays. If you think of the behavior of the minutes display, you can say that it starts at 0 and rolls back to 0 after 59. This also affects the behavior of the hours display because it starts at 0 and increases by one each time the minutes display rolls back to 0. Abstracting away from how the minutes and hours work we can view these two items as objects that can display values from zero up to a given limit. The value can be increamed, but, if the value reaches the limit, it rolls over to zero. Congradulations, we just used abstraction and modularization when thinking of how create a clock display. To create the clock display, we first want to create a class for a two-digit number display and then give it an accessor method to get its value and two mutator methods to set the value and to increament it. Once we have defined this class, we can create two objects of the class with different limits to construct the whole clock display. 3.5 Implementing The Clock Display To create the clock display, we first want to create a class for a two-digit number display. The display needs to store two values. One is the limit to which it can count before rolling over to zero. The other is the current value. The following code shows the class for the two-digit number display. public class NumberDisplay { private int limit; private int value; //Constructor and methods are omitted. } Now, lets think a bit more about the complete clock display. We would build a complete clock display by having an object that has, internally, two number displays (one for the hours and one for the minutes). Each of the number displays would be a field in the clock display. The following code shows the ClockDisplay class: public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; //Constructor and methods are omitted. } Notice that the type NumberDisplay is being used instead of int, String, ect. The concept is called class defined types. This allows the field to hold objects of that class. This the field hours is capable of holding the object NumberDisplay and access the fields of limit and value. The same goes for minutes. 3.6 Class Diagrams vs Object Diagrams Aclass diagram shows the classes of an application and the relationships between them.An object diagram shoes the objects and their relationships at one moment in time during the execution of an application. The following image is a class diagram: As you can see the the class diagram shows the static view of the relationship between the classes of the application. In the next image you will see that the object diagram shows information about objects at runtime and presents the relationship in a dynamic view. The object diagram also shows another important detail: when a variable stoes an object, the object is not stored in the variabe directly, but rather an object reference is stored in the variable. The diagram above shows the variable as a white box and the referring object is shown as an arrow. The object referred to is stored outside the referring object, and the object reference links the two. 3.7 Primitive Types and Object Types In Java there are two different kinds of type: primitive types and object types. Primitive types are all predefined in Java. They include int and boolean. Object types are defined by classes. Object types are different from primitive types because: 1. Primitive types are not instantiated. 2. In the memory, only their value is stored, directly. No reference to an instance is stored. 3. In the memory, the allocated space is fixed, whatever their value. The allocated space of an object vary, for instance either the object is intantiated or not. 4. Primitive types don't have methods. 5. Aprimitive type can't be inherited. Inherentence in Java is later explained in the text but I would suggest that you keep the list above in mind when having to explain the difference between primitive and object types. 3.8 The ClockDisplay Source Code If you look at the source code for NumberDisplay you will notice some logic operators in the setValue method. Logic operators operate on boolean values and produce a new boolean value as a result. The three most important logical operatores are and, or, and not. These operators are written in Java as: && (and) || (or) ! (not) The following expressions show how these operators work. a && b is true if both a and b are true. a || b is true if either a or b or both are true. !a is true if a is false and false if a is true. In the getDisplayValue method you will notice the same string concatenation that we say in 2.9. The + sign is used in string concatenation but it is also used for the addition operator. The best way to figure out what the + sign is being used for is to look at the left hand of the sign to see if “” is being used. If it is then you are using the + for string concatenation. The increment method contains the modulo operator (%). The modulo opeator calculates the remainder of an integer dividision. For instance, the expression 27 % 4 would result a 3. 3.9 Objects Creating Objects The constructors for ClockDisplay create a new clock by creating and storing two NumberDisplay objects. This concept is called object creation. Object can create other objects using the new operator. The new operator does two things – first it creates a new object of the named class, second it executes the constructor of that class. The source code below shows how this can be implented. public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; // remaining fields are omitted. public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay; } // remaining constructor and methods are omitted. } 3.10 Multiple Constructors When you right-click on the ClockDisplay to create a new ClockDisplay object you might have notice two menue options. This is because the ClockDisplay class contains two constructors. One constructor with no parameters and another with parameters. This allows you to create a ClockDisplay object with alternative constructors. It is common for class definitions to contain alternative versions of constructors or methods that provide various ways of achieving a particular task via their distinctive sets of parameters. This practice is known as overloading a constructor or method. Overloading allows a class to contain more than one constructor or more than one method of the same name, as long as each has a distinctive set of parameter types. 3.11 Method Calls Method calls invoke methods. There are two kinds of method calls internal and external. Internal method call is the implementation of methods calling on other methods of the same class as part of their implementation. Internal method calls have the following syntax: methodName(parameter-list); An external method call is a the implementation of of methods calling on other methods of other objects using the dot notation. This allows a method to be called outside of the class. External method calls have the following syntax: object.methodName(paramter-list); The set if methods an object makes available to other objects is called its interface. The topic of interfaces are discussed in chapter five and so on through the book. 3.12 The null null is a special value in Java. Object fields are initialized to null by default. It is perfered that you test for null and you can do the following to perform such task. private numberDisplay hours; if(hours != null){ .... } hours = null; 3.13 Another Example of Object Interaction Instead of code reading the text introduces using the debugger to gain a deeper understanding about how a program executes.Adebugger is a software tool that helps in examining how an application executes. It typically provides functions to stop and start a program at select points in the source code, and to examine the values of variables. In the MailItem class, the constructor conatins an odd keyword – this. The keyword this allows us to refer to a field instead of a parameter with the same name. In other word, it allows name overloading. The syntax to allow name overloading is as follows: this.fieldName = parameterName; 3.13 Using a Dubugger As mentioned before a dubugger will typically provide functions to stop and start a program at select points in the source code. The functions that are available through BlueJ are breakpoints and step.A breakpoint is a flag attached to a line of source code that will stop the execution of a method when it is reached. Abreakpoint can be setup by opening the BlueJ editor, selecting the appropriate line and then selecting Set/Clear Breakpoint from the tools menue of the editor. The breakpoint should look like a stop sign. The dubugger window has three areas for variable display, titled static variables, instance variables, and local variables. The Step button allows the next line of code to executed and then it stops again. This allows you to walk through the program line by line. If the next line of code is a method the debugger allows you step into the method. This is done using the Step Into command. When you use this command it will put you into the method and stop at the first line of source code for that method. Keywords: Abstraction, modularization, divide and conquer, class diagram, object diagram, object reference, overloading, internal method call, external method call, dot notation, debugger, breakpoint


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Jennifer McGill UCSF Med School

"Selling my MCAT study guides and notes has been a great source of side revenue while I'm in school. Some months I'm making over $500! Plus, it makes me happy knowing that I'm helping future med students with their MCAT."

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.