CSE 115 Week 11 March 24 - 28, 2008

advertisement
CSE 115
Week 11
March 24 - 28, 2008
Announcements




March 26 – Exam 7
March 28 – Resign Deadline
Lab 7 turned in by 3/30 can earn 20%
bonus
March 31 – Exam 8
Week’s Notes


Graphics package – see Javadocs
We’ve used most things except for
elements in the graphics package
proper. If you want to “draw” on the
drawing canvas, you need these
elements.
Week’s Notes



Collections are containers that hold
onto objects
Library of collections live in the
java.util package in Java
Main functionality we need to be
concerned with are: insertion,
deletion, and search
Week’s Notes

In Java, when we create a collection,
we need to state what type of thing is
stored inside it. This changes slightly
the look of a variable declaration.
java.util.Collection<Stuff> collectionOfStuff;
Week’s Notes

When we have a collection and want
to do something to all elements of that
collection we use the for-each loop to
help us iterate over all elements of
that collection.
For-each loop syntax
for(Type identifier1: identifier2) {
//code to execute for each element
}

Where:
– identifier2 is the name of the collection that you are
iterating over
– Type identifier1 is the creation of a reference to
each element of the collection to use as you are iterating.
Boolean expressions



Expressions that evaluate to either
true or false
boolean is a type built into Java
However, boolean is not a class
Boolean values and
operators


Methods can return boolean values
Can combine boolean values using
logic operators
&& (logical and)
|| (logical or)
! (logical not)
Operators that return a
boolean value





Comparison operators return boolean
values as well. These operators work
on numeric values.
< (less than)
> (greater than)
<= (less than or equal to)
>= (greater than or equal to)
Operators that return a
boolean value

There are two equality operators in Java:
== (equality)
!= (not equal)


These work on numeric values as you would
expect from arithmetic
But are also defined on references where
they compare if the references are the
same.
Download