lecture17-String+IO

lecture17-String+IO - Lecture 17: Objects: I/O Data Lecture...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
cture 7: bjects: O Data Lecture 17: Objects: I/O, Data CS 170, Section 000 9 ctober 2009 29 October 2009 10/29/2009 CS170, Section 000, Fall 2009 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lecture Plan ± Review of String, File objects from last lecture nstructor ethods ¾ constructor methods ± Homework 5: Breaking the Caesar cipher ± Due Wednesday, Nov 4 th (new date) ¾ Chapter 8 (conclusion): Reading/Writing Files ¾ More objects for Text input/output ¾ Finding more information: Java API documentation ¾ Managing Data: objects to make your life easier ¾ ArrayList : resizable general array object ashtable neral fast dictionary/lookup object ¾ Hashtable : general, fast, dictionary/lookup object CS170, Section 000, Fall 2009 2
Background image of page 2
The String Class: Ch 8.1-8.4 Constructing a String String object String s1 = new String("Welcome to Java“); String s2 = new String(“Welcome”); ring comparison Constructor method String comparison if (s1.equals(s2)){ System.out.println(“strings are the same”); }else{ System.out.println(“s1 != s2”); 3 }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
String object in more depth (Ch. 7.1) Contains sequence of characters Æ object data /a.k.a. data field a.k.a. property Provides useful methods like equals(), length() Æ define behavior of an object , can access object data 10/29/2009 CS170, Section 000, Fall 2009 4
Background image of page 4
String object in more depth (Ch. 7.1) Contains sequence of characters bject data/a k a ata field ka property Æ object data/a.k.a. data field a.k.a. property Provides useful methods like equals(), length() efine ehavior f an object, can access object data Æ define behavior of an object, can access object data Distinction between class type and class instance : class String ( type of object), that defines operations and type of values it can hold: st like t double oolean just like int, double, boolean class instance s1 of type String: an actual variable that holds specific value (e.g., “Java”) st like t t um=10; just like int vs. int Num=10; 10/29/2009 CS170, Section 000, Fall 2009 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Constructors (Ch 7.3) Constructor : method invoked when an object is created with the new operator Has the same name as the class, e.g., constructor for String class is defined in method String(…) Some String constructors (of many available): http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html String () : initializes a newly created String object so that it represents an empty character sequence. t i i i i l) I iti li lt d S t i b j t String ( String original): Initializes a newly created String object so that it contains a copy of the argument string. 10/29/2009 CS170, Section 000, Fall 2009 6
Background image of page 6
StringBuilder Constructors Similar to String, but allows to modify object data (character sequence) Can be created empty, from a string, etc… http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html java.lang.StringBuilder +StringBuilder() Constructs an empty string builder with capacity 16.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

lecture17-String+IO - Lecture 17: Objects: I/O Data Lecture...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online