1 CS1110 Wrapper classes, stepwise refinement 27 Sept Prelim: Tuesday, 6 Oct, 7:30–9:00PM, Statler Auditorium Thursday: no reading. Be there or be square.

Slides:



Advertisements
Similar presentations
1 Value vs. reference semantics. Recall: Value semantics value semantics: Behavior where variables are copied when assigned to each other or passed as.
Advertisements

1 CS Sept. Customizing a class & testing Quiz 2 on Tuesday 15 Sept Purpose of a constructor (slide 5) Evaluating a new expression (slide 6) Fields;
Java Software Solutions
1 CS1110 Stepwise refinement, wrapper classes 29 Sept Prelim: 8PM Thursday 8 October (next week) If you have a conflict and have not been contacted, .
DISCUSSION OF SOME QUESTIONS ON PRELIM 2 Lecture 23 CS2110 – Spring 2015.
For use of Cleveland State's IST410 Students only 1 Vectors and Collections.
1 A Sorting Example (a start for Lab 4 problem number 3)
Chapter Day 6. © 2007 Pearson Addison-Wesley. All rights reserved2-2 Agenda Day 5 Questions from last Class?? Problem set 1 DUE Problem set 2 posted 
Using final We use the notion of constant data to represent data that cannot be changed. public class Test { static final int someInt = 10; static final.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Inheritance and interfaces A class C1 is derived from class C2, then C1 is called subclass, and C2 is called superclass Superclass-parent, base class Subclass.
1 More on Arrays Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 – 7.2 Reading for this lecture:
Static Class Members Wrapper Classes Autoboxing Unboxing.
EnPh 131 Lec B04 Introduction Course syllabus Course components ….
1 CS100J 05 February 2005 Today’s topic: Customizing a class (continued) Quiz 1 is today Quiz 2 is next Tuesday Quote for the day: There is no reason anyone.
Comparing Objects in Java. The == operator When you define an object, for instance Person p = new Person("John", 23); we talk about p as if its value.
Chapter 11 Abstract Classes and Interfaces 1. Abstract method New modifier for class and method: abstract An abstract method has no body Compare: abstract.
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Class Library, Formatting, Wrapper Classes, and JUnit Testing
1 CS1110 Lecture Sept Developing (String-processing) programs; class Vector; wrapper classes Prelim: 7:30-9PM Thursday 7 October. Last name A-K:
ARRAYLIST Collections of Data. ArrayLists Array lists can grow and shrink as needed ArrayList is a generic class (similar to C++ template) ArrayList has.
1 Chapter 10 Object-Oriented Thinking. 2 Class Abstraction and Encapsulation Class abstraction means to separate class implementation details from the.
CS125 Exam Review Winter Some Exam Info Tuesday (22nd) at 4:00-6:30pm in the PAC CHECK YOUR SEAT!!! Read Final Exam Information on website –Practice.
Introduction to Java University of Sunderland CSE301 Harry R. Erwin, PhD.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
1 CS2111 Spring Instructor: David Gries You job: Come to class each week, take part. My job in first few weeks: Get you to under- stand and be facile.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Winter 2006CISC121 - Prof. McLeod1 Last Time Misc. useful classes in Java: –String –StringTokenizer –Math –System.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
1 CS Sept 2010 Inside-out rule; use of this, super Developing methods (using Strings). Read sec. 2.5, stepwise refinement Listen to Plive, 2.5.1–2.5.4.
10-Nov-15 Java Object Oriented Programming What is it?
Defining Classes II. Today’s topics  Static methods  Static variables  Wrapper classes  References  Class parameters  Copy constructor.
1 CS100J Wrapper classes, stepwise refinement 19 Feb When insults had class "A modest little person, with much to be modest about." Churchill "I never.
1 CS1110 lecture 4 9 Sept. Customizing a class & testing Classes: fields; getter & setter methods. Secs (p. 45) & 3.1 (pp. 105–110 only) Constructors.
Some Standard Classes Goals The Object class The String class Wrapper classes The Math class Random Numbers.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
Programming in Java (COP 2250) Lecture 8 Chengyong Yang Fall, 2005.
Introduction to Java COM379 (Part-Time) University of Sunderland Harry R Erwin, PhD.
1 CS100J Classes, stepwise refinement 14 Feb 2007 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
Section 4 Boxing classes Boxing classes Array initialization Array initialization Lists: recursion and iteration Lists: recursion and iteration.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Using Classes and Objects. We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: Object creation.
CSC 1051 M.A. Papalaskari, Villanova University Everyday objects: Strings and Wrappers CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari.
1 CS1110 Wrapper classes, stepwise refinement 30 September Chocolate bar has grooves that divide it into squares. This is one example. Others would be.
© 2004 Pearson Addison-Wesley. All rights reserved September 7, 2007 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
CONTENTS Wrapper Class Enumeration Garbage Collection Import static.
1 CS100J 08 September 2005 Today’s topic: Customizing a class (continued) Quote for the day: There is no reason anyone would want a computer in their home.
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
1 CS1110 Stepwise refinement, more on classes 24 Sep 2009 Application of String processing and stepwise refinement. Miscellaneous points about classes.
1 CS1110 Classes, stepwise refinement 17 Feb 2009 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of.
1 CS September 2008 Discussion of Methods: Executing method calls.If-statements. The return statement in a function. Local variables. For this and.
Chapter 3 Using Classes and Objects 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Outline Creating Objects The String Class Packages Formatting Output Enumerated Types Wrapper Classes Components and Containers Images.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
3-1 Creating Objects A variable holds either a primitive type or a reference to an object A class name can be used as a type to declare an object reference.
Wrapper Classes  Java offers a convenient way to incorporate, or wrap, a primitive data type into an object, for example, wrapping int into the class.
1 CS1110 Classes, stepwise refinement 12 Feb 2009 Rsrecah on spleilng Aoccdrnig to a rscheearch at Cmabirgde Uinervtisy, it deosn't mttaer in waht oredr.
Wrapper Classes Use wrapper objects in Collections when you can’t use primitive types Primitive TypeWrapper Class byteByte shortShort intInteger longLong.
1 CS Sep 2011 Miscellaneous points about classes. More on stepwise refinement. Next: wrapper classes. Section 5.1 of class text Need Help? Make.
CS202 Java Object Oriented Programming Introduction to Collection Classes Chengyu Sun California State University, Los Angeles.
© 2004 Pearson Addison-Wesley. All rights reserved January 27, 2006 Formatting Output & Enumerated Types & Wrapper Classes ComS 207: Programming I (in.
1 CS1110 Classes, wrapper classes, Vectors. 10 Feb 2012 Miscellaneous points about classes. Discussion of wrapper classes and class Vector Use the text.
Coming up ArrayList ArrayList vs Array – Declaration – Insertion – Access – Removal Wrapper classes Iterator object.
Lecture 20: Wrapper Classes and More Loops
CS1110 Classes, stepwise refinement 23 Sep 2009
Chapter 10 Thinking in Objects
CS1110 Wrapper classes, stepwise refinement 23 Feb
Grouped Data Arrays, and Array Lists.
Presentation transcript:

1 CS1110 Wrapper classes, stepwise refinement 27 Sept Prelim: Tuesday, 6 Oct, 7:30–9:00PM, Statler Auditorium Thursday: no reading. Be there or be square (or lost)! Recursion can be a difficult topic, but we’ll make it easy. Learning Strategies Center posts a lot of great info on study skills, taking exams, time & stress management, etc. lsc.sas.cornell.edu/Sidebars/Study_Skills_Resources/SKResources.html Every day after classes, retrieve your notes and read them. Takes little time, and yet: 1. really makes material “stick” in one’s mind, and 2. helps you figure out what you don’t understand early on, so you can get it straightened out faster. This was a real game-changer for me. Professor Lillian Lee

2 Wrapper classes. Read Section 5.1 a0 Integer ??? 5 Soon, need to deal with an int value as an object. "Wrapper class" Integer provides this capability. Instance of class Integer contains, or "wraps", one int value. Can’t change value. immutable. Integer(int) Integer(String) toString() equals(Object) intValue() Static components: MIN_VALUE MAX_VALUE toString(int) toBinary(int) valueOf(String) parseInt(String) Static components provide important extra help.

3 Each primitive type has a corresponding wrapper class. When you want to treat a primitive value of that type as an object, then just wrap the primitive value in an object of the wrapper class! Primitive typeWrapper class intInteger longLong floatFloat doubleDouble charCharacter booleanBoolean Each wrapper class has: Instance methods, e.g. equals, constructors, toString, Useful static constants and methods. You don't have to memorize the methods of the wrapper classes. But be aware of them and look them up when necessary. Use Gries/ Gries, Section 5.1, and ProgramLive, 5-1 and 5-2, as references. Integer k= new Integer(63); int j= k.intValue();

Class Vector 4 An instance of class Vector maintains an expandable/shrinkable list of objects. Use it whenever you need to maintain a list of things. Values of primitive types cannot be placed directly into the list of a Vector. That’s why we have the wrapper classes. In the interactions pane, we will do a few things, like these: import java.util.*; Vector v= new Vector(); v v.add(new Integer(2)); v.add(3); v.add(‘c’); In newer versions of Java, v.add(1) is allowed; the 1 is wrapped in an Integer object and the name of that object is added to v. Doesn’t work in older versions.

Example of a program that deals with Strings Creating a web page giving liberal studies courses 5 Java program reads the online Courses of Study webpages and extracts the courses that are liberal studies courses in A&S and CALS. It builds tables of A&S, CALS, CA, HA, KCM, LA, and SBA courses and produces the liberal studies course website String manipulation is key concern of this lecture. But OO structure of the program will also be discussed

Example of a program that deals with Strings Creating a web page giving liberal studies courses 6 Java program: read online Courses of Study webpages and extract liberal studies courses. Build tables of A&S, CALS, CA, HA, KCM, LA, and SBA courses. Produce liberal-studies website String manipulation is key concern of this lecture. But OO structure of the program will also be discussed CA: cultural analysis HA: historical analysis etc.

7 Class Webpage 7 Fields contain: url, as a String url, as an object of class set of links on the page … Methods: Webpage(String url) (constructor) isHtmlPage() getLinks() getReader() = an object that lets one read the webpage line by line …

8 Class DeptLink 8 Fields contain: dept name link to its webpage in CoS Vector of all its courses American Studies

99 /** Constructor: an instance who dept name and link are contained in s. s has the form … dept name … where the xxx is a relative URL in directory LibStudies.prefix Note: if s is not proper, dept name and link will be null. */ American Studies The form is: … dept name …

10 /** Constructor: an instance who dept name and link are contained in s. s has the form … dept name … where the xxx is a relative URL in directory LibStudies.prefix Note: if s is not proper, dept name and link will be null. */ public DeptLink(String s) { } Remove … <a href=" from s; Set k to index of "> of the a tag; Store the link xxx in local variable lk; s= s.substring(k+2); Set k to index of ; Store dept name and lk in dept and link.

11 Class Courses 11 Fields contain: course e.g. ANTHR 1200 title everything else you see to the left category HA-AS, HA CA-AS, CA SBA-AS, SBA etc. ANTHR 1400 The Comparison of (CA-AS)

12 /** Constructor: instance for course given by s, in form: course name title cat contains the category. If s not proper, course, title, category will be null. */ public Course (String s, String cat) { }