CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE116: Introduction to Computer Science 2 Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Mixing types in expressions Operators such as +, -, * and / are overloaded: the same name has many different values + overloaded as String concatenation.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Grouping Objects 3 Iterators, collections and the while loop.
CSE 115 / 503 Introduction to Computer Science For Majors I Carl Alphonce 219 Bell Hall.
Primitives in Java Java has eight primitive types –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double,
Loops – While, Do, For Repetition Statements Introduction to Arrays
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 02 / 20 / 2008 Instructor: Michael Eckmann.
CSE 115 / 503 Introduction to Computer Science For Majors I Carl Alphonce 219 Bell Hall.
Grouping objects Collections and iterators. 04/11/2004Lecture 4: Grouping Objects2 Main concepts to be covered Collections Loops Iterators Arrays.
CS 106 Introduction to Computer Science I 02 / 19 / 2007 Instructor: Michael Eckmann.
CSE 115 / 503 Introduction to Computer Science I
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Grouping objects Collections and iterators. Main concepts to be covered Collections Loops Iterators.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
CS 2430 Day 1. Agenda Load NetBeans Introduction Syllabus Review some array operations.
Grouping objects Collections and iterators Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
JAVA COLLECTIONS M. TAIMOOR KHAN (ADAPTED FROM SWINBURNE NOTES)
Grouping objects Iterators. Iterator type Third variation to iterate over a collection Uses a while loop and Iterator object But NO integer index variable.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Interfaces. In order to work with a class, you need to understand the public methods  methods, return types,…  after you instantiate, what can you do.
Grouping objects Iterators, collections and the while loop Equality and Equality == and equals(…)
© 2004 Pearson Addison-Wesley. All rights reserved October 5, 2007 Arrays ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor:
Iterators. Iterator  An iterator is any object that allows one to step through each element in a list (or, more generally, some collection).
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Objects as a programming concept
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Agenda Warmup Finish 2.4 Assignments
CS2011 Introduction to Programming I Arrays (I)
CSE 501N Fall ‘09 13: Interfaces and Multiple Representation
Collections and iterators
Java Programming Review 1
Arrays October 6, 2006 ComS 207: Programming I (in Java)
February , 2009 CSE 113 B.
slides created by Alyssa Harding
Collections and iterators
Presentation transcript:

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:

Lab 6 remarks Learn process –start small, with something that has some minimal functionality (e.g. putting a JFrame up on the screen) –test functionality/behavior of program frequently –build overall functionality incrementally, in small steps Notice that all classes implementing an interface are similar –in lab 6, several tools implement the ITool interface –these tools generally fit into the program the same way –figure out one tool first (e.g. SquareTool), and the rest will follow –works for other projects too! Labs 7 and 8 –we will not spell out detailed steps –you should apply process on your own –seek guidance/assistance as needed, from TAs or instructor

Agenda Review from last class Introduction to primitive types The while loop The foreach loop

Review Collections –Collection interface add/remove/iterator methods –HashSet class –LinkedList class Iterators –Iterator interface next/hasNext methods

Collections: concepts interface: java.util.Collection –E is the type of element contained in the collection – replace by an actual type concrete implementations (examples): –java.util.HashSet at most one of each internal order irrelevant to client –java.util.LinkedList multiples permitted maintains order; client can determine order

Collections: usage example To declare a variable of type HashSet of String: HashSet names; To create a HashSet of String object, and assign its reference to the variable declared above: names = new HashSet ();

Collections: usage example (continued) To add a String to the HashSet: names.add(“Fred”); To remove a String from the HashSet: names.remove(“Fred”);

Primitives in Java Java has eight primitive types; today we will see one of them: –boolean –integral types: signed: long, int, short, byte unsigned: char –floating point types: double, float Values of the primitive types are not objects –no properties –no capabilities

boolean values: true, false operations: &&“and” ||“or” !“not”

Control structure overview while statement while ( ) true false

boolean expressions hasNext()’s return type is boolean call to hasNext() can be used to control while loop

Last time java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); java.util.Iterator it; it = coll.iterator(); System.out.println(it.next());

Notice repetition java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); java.util.Iterator it; it = coll.iterator(); System.out.println(it.next());

replace repetition with while loop java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); java.util.Iterator it; it = coll.iterator(); while (it.hasNext()) { System.out.println(it.next()); }

for-each loop – process each element of a collection of elements of type E: for (E item : collection) { // do something with item } Example: to print out each String in coll: for (String s : coll ) { System.out.println(s); } Declared as: HashSet Declared as: HashSet

while loop java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); java.util.Iterator it; it = coll.iterator(); while (it.hasNext()) { System.out.println(it.next()); }

for-each loop: no explicit iterator java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); for (String s : coll) { System.out.println(s); }

for-each loop vs. while loop java.util.Collection coll; coll = new java.util.LinkedList (); coll.add("Fred"); coll.add("Wilma"); coll.add("Pebbles"); coll.add("Dino"); coll.add("Fred"); System.out.println("The collection: " + coll); Iterator it; it = coll.iterator(); for (String s : coll) { while (it.hasNext()) { System.out.println(s);String s = it.next(); } System.out.println(s); }