Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter 8, Arrays, next –Graphics after the exam Method documentationMethod documentation Primitive vs reference variablesPrimitive vs reference variables Scope of Variables, calling methodsScope of Variables, calling methods UML DiagramsUML Diagrams

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota Method Documentation Let’s get more specificLet’s get more specific Each method starts with the followingEach method starts with the following –A block comment /* containing the following –A grammatical sentence describing what the method does. –@param argname A description of the argument –@return A description of the retuned data, if not void Next comes the method headingNext comes the method heading –“public static void” for plain methods –“public void” or “public type” for object methods –“public” alone for constructors

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota Computers prefer data that fits The Pentium processor (CPU)The Pentium processor (CPU) –“Arithmetic logic unit” ALU –“Registers” for calculating results Primitive types “fit”Primitive types “fit” –Integers, doubles, chars, etc, fit perfectly in the registers –The variable’s contents are its value Strings and objects don’t fitStrings and objects don’t fit –They contain more than one primitive object –They fit in RAM, but not in individual registers “Reference variables”“Reference variables” –They say where the data is in RAM –Variables for objects, strings, etc.

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota Working with reference variables Straight comparisons don’t workStraight comparisons don’t work –Example: string1 == string2 versus string1.equals(string2) –The == compares the reference variables –The “.equals” looks at the primitives that make it up –You rarely care if two reference variables match Same is true for objectsSame is true for objects –bankAccount1 == bankAccount2 What can this possibly mean?What can this possibly mean? It has an answer: are they both pointing to the same account objectIt has an answer: are they both pointing to the same account object –Note that we aren’t checking if they have the same balance Or the same last transactionOr the same last transaction

5 March 2005 5/18R. Smith - University of St Thomas - Minnesota Examples str1 = JOptionPane(“Type ‘aaa’”);str1 = JOptionPane(“Type ‘aaa’”); str2 = JOptionPane(“Type ‘aaa’”);str2 = JOptionPane(“Type ‘aaa’”); Both have the same contentsBoth have the same contents –Each is a separate String object The Java compiler doesn’t create extra objectsThe Java compiler doesn’t create extra objects –String a = “test”; –String b = “test”; –It is true that a == b Each time you say ‘new’ you get a new objectEach time you say ‘new’ you get a new object

6 March 2005 6/18R. Smith - University of St Thomas - Minnesota “Scope” of variables Declaring a variable in a methodDeclaring a variable in a method –It exists INSIDE that method only! Declaring arguments to a methodDeclaring arguments to a method –The same sort of thing –Each argument is like a local variable

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Passing arguments TO a method A “fill in the blanks” exerciseA “fill in the blanks” exercise You use a variable name from INSIDE the methodYou use a variable name from INSIDE the method When the method runs,When the method runs, –Primitive variables are copied to the argument varialbes –Reference variables are copies to the argument variables –The method uses those vaules with the method’s names

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota UML Diagrams At the top: Object NameAt the top: Object Name Next, minus signs: fieldsNext, minus signs: fields Last, plus signs, list of methodsLast, plus signs, list of methods –Method name –Argument list in parentheses –Colon –Returned value (say ‘void’ if none) Constructor methodsConstructor methods –Given object name for method name –No returned value, not even ‘void’

9 March 2005 9/18R. Smith - University of St Thomas - Minnesota Lab 13? Due ThursdayDue Thursday Do we need time today/Tuesday for it?Do we need time today/Tuesday for it?

10 March 2005 10/18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions? Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Change in order of topicsChange in order of topics –Starting Chapter."

Similar presentations


Ads by Google