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 Lab Status?Lab Status? Stuff from the readingStuff from the reading.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab Status?Lab Status? Stuff from the readingStuff from the reading."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Lab Status?Lab Status? Stuff from the readingStuff from the reading –Scope –Documentation and comments –Formatting The String ClassThe String Class Related Object StuffRelated Object Stuff Keyboard Input (if time)Keyboard Input (if time)

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota If you did NOT do the reading… Section 2.10 talked about “Scope”Section 2.10 talked about “Scope” –Java analyzes the file in order from top to bottom –You must declare variables before use –Java lets you declare anywhere before the variable is used –STYLE: I want you to always declare at the top of the method Section 2.11 talked about CommentsSection 2.11 talked about Comments Section 2.12 talked about StyleSection 2.12 talked about Style –Follow the style recommendations in the book –Follow its formatting style –“Javadoc” is cool but not something we need I trust this book - follow its recommendationsI trust this book - follow its recommendations

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota The String Class A Java “Class” is a set of methodsA Java “Class” is a set of methods –The “main” we write is a method –May also define a type of object The String Class = object type for “Strings”The String Class = object type for “Strings” A collection of methods we can useA collection of methods we can use –length() = calculates # characters –toLowerCase() = converts to all lower case –toUpperCase() = converts to all upper case –charAt(n) = returns the “char” at location “n”

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota So what is a String? Not a primitive type; it’s an objectNot a primitive type; it’s an object String foo = “Hello, world!”String foo = “Hello, world!” foo itself isn’t big enough for the textfoo itself isn’t big enough for the text –It points to the string, which resides elsewhere Objects are like that - arbitrarily largeObjects are like that - arbitrarily large –Their variables don’t contain, they point.

5 March 2005 5/18R. Smith - University of St Thomas - Minnesota The Whole Point of Objects Make it easier to write programsMake it easier to write programs –Re-use existing programs –Catch bugs when using existing programs –Catch bugs in newly written programs A “Class” is a way of defining new object typesA “Class” is a way of defining new object types –A new object is always based on an old one “Real” Java Programming“Real” Java Programming –Some “procedural programming” - what we do –Mostly relies on existing “classes” to do the work

6 March 2005 6/18R. Smith - University of St Thomas - Minnesota Let’s try those String Operations The string methodsThe string methods –length() = calculates # characters –toLowerCase() = converts to all lower case –toUpperCase() = converts to all upper case –charAt(n) = returns the “char” at location “n” Syntax:Syntax: –objectName.methodName(args);

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Reading Keyboard Input “Scanner” class - a real class“Scanner” class - a real class –String has shortcuts built into Java –Scanner is a completely “external” class Reading from “System.in”Reading from “System.in” –The opposite of our friend “System.out” Initializing an object variableInitializing an object variable –Scanner keyboard = new Scanner (System.in); To Use, must be DefinedTo Use, must be Defined –import java.util.Scanner; –Imports the class from the “util” package –Put at start of file

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota Scanner methods Scanner Kb = new Scanner(…);Scanner Kb = new Scanner(…); Kb.nextLine() - next line of text (string)Kb.nextLine() - next line of text (string) Kb.nextInt() - next integerKb.nextInt() - next integer Kb.nextDouble() - larger floating pointKb.nextDouble() - larger floating point Kb.nextFloat() - float sized fpKb.nextFloat() - float sized fp Kb.nextLong() - huge integerKb.nextLong() - huge integer Kb.nextByte() - next byte-sized numberKb.nextByte() - next byte-sized number Kb.nextShort() - next short-sized numberKb.nextShort() - next short-sized number

9 March 2005 9/18R. Smith - University of St Thomas - Minnesota Using NextLine Repeat those string experimentsRepeat those string experiments Print out upper, lower, length, and a chosen charPrint out upper, lower, length, and a chosen char Time to do some arithmetic?Time to do some arithmetic?

10 March 2005 10/18R. Smith - University of St Thomas - Minnesota 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 Lab Status?Lab Status? Stuff from the readingStuff from the reading."

Similar presentations


Ads by Google