Peer Instruction in Java: Enhancing Learning Experience

undefined
CSE 12 – Basic
Data Structures
Cynthia Bailey Lee
 
Some slides and figures
adapted from Paul Kube’s CSE
12
 
 
CS2 in Java Peer Instruction
Materials by 
 is licensed
under a 
.
Based on a work
at 
.
Permissions beyond the scope of this
license may be available
at 
.
http://peerinstruction4cs.orghttp://peerinstruction4cs.orgInternational LicenseAttribution-NonCommercial 4.0Creative CommonsCynthia Lee  
 
What do I do in class?
 
Think of me as your tutor
Be your guide in inducing 
you
 
to explore
concepts
Create situations and pose problems that
set the scene for 
your
 
exploration
Answer 
your
 
questions
Not
 
spend lecture reading the textbook to
you with slightly different words
 
2
 
What do you do in class?
 
(before class, you prepared yourself by reading; a
reading quiz at the beginning of class will check
your preparation)
1.
I ask a question
2.
You first answer it by yourself
3.
Then discuss in assigned groups of 3-4 students
Like a jury, you must come to a unanimous
decision
Answer the question a second time
4.
I will ask groups to share their insights, and I will
provide additional clarification as needed
 
3
 
Tips for a good group discussion
 
Take turns being the first one to talk
Once you all agree on the answer, 
don’t stop
!
Always 
go over each wrong answer 
and explain why it is
wrong
Also interesting and useful to think about why somebody
might be tempted to choose it—how was Prof. Lovett
hoping to “trick” somebody by including that wrong
answer?
Even if your group-mate has said something very clearly
and correctly, it’s a good idea to 
repeat it yourself
“So, what I think you said was, …”
Might seem pointless, but your brain will remember better
if YOU say it too
 
4
 
Data Structures
 
Map of the course
 
Course topics
 
Abstraction and Abstract Data Types (ADTs)
Application Programmer Interfaces (APIs)
Algorithm Time, Space, and Energy Cost Analysis
Object-oriented Software Design Patterns, including
Inheritance, Composition, Adapter, and Iterator
Software Testing 
and 
the JUnit framework
Java Classes and Interfaces
Collections, and the Java Collections Framework
Java Generics
Arrays, Stacks, Queues, Circular Arrays
Searching and Sorting Algorithms
Trees, Heaps, Binary Search Trees, Abstract Syntax Trees
Hashing and Hash Tables
 
Abstraction
 
o
Abstraction means:
o
Hiding irrelevant details to focus on the
essential features needed to understand and
use a thing
o
Abstraction is an essential tool for managing
complexity
o
Designing, implementing, and using complex
systems would be impossible without
abstraction
 
7
 
Group discussion
 
What is another good “daily life” example
of abstraction?
Maybe I can use yours next quarter instead!
 
One kind of abstraction in
Computer Science: 
Data Types
 
o
Specifying an 
Abstract Data Type ADT)
 
requires
specifying two things:
o
Possible values for instances of the type
o
Operations that can be performed on
those instances
o
Does NOT require specifying:
o
H
ow are those values and operations
implemented
?
 
9
 
ADT Implementers and Users
 
This kind of abstraction is very powerful.
The ADT can be implemented without having to know
details of how it will be used 
(except that it will be used
in accordance with its interface specification)
The ADT can be used without having to know the
details of how it is implemented
 (except that it was
implemented to satisfy its interface specification)
With any specification of an ADT interface:
The ADT can be used infinitely many ways, and…
The ADT can be implemented infinitely many
ways!
This makes designing, implementing, using and
maintaining software easier and more flexible
 
10
 
Example: a String ADT
 
You might define a String abstract data type
along these lines:
Values:  a String is a sequence of zero or more
Unicode 1.0 characters
Operations:
Create a String
Add a character to the end of a String
Say what character is at a particular position
in a String
What other operations might be good to specify
for a String ADT?
 
11
 
ADTs are language-neutral
 
In CSE 12 we will concentrate on implementing
ADT’s in Java
And we will consider many features of Java
that are useful for implementing ADT’s
But always keep in mind that the basic
principles of ADT design and analysis are
language-neutral!
 
12
 
APIs are like ADTs, but specify the
interface in a particular language
 
Users and impelmenters still do things as they
please, but both within a common language
 
Application Programmer Interface
(API)
 
The 
implementer
 of an ADT in a particular
language is a programmer
And, usually, the 
client
 or 
user
 of an ADT is also a
programmer in that language, who wants to use
the ADT as a component in a larger software
application
Therefore the interface to an ADT in a particular
language is said to be the 
Application Programmer
Interface
, or 
API
, for the ADT in that language
 
13
 
Checkpoint: ADTs and APIs
 
Which of the following would be elements of
an 
ADT
 specification, and which would be
elements of an 
API
 specification?
I.
int getValueAtIndex(int index)
throws IndexOutOfBoundsException
II.
Get operation: given an index,
returns the value at that index
 
A.
I
 is part of an 
API
 and 
II
 is part of
an 
ADT
B.
II
 is part of an 
API
 and 
I
 is part of
an 
ADT
C.
Both 
I
 and 
II
 could be part of an 
API
or 
ADT
D.
Other
 
14
 
Discussion
 
ADTs and APIs exist to prevent users from
knowing the implementation details (and
vice versa). But…
Are there times when it would be useful to
know the implementation details of an
ADTs operations or values? Why?
 
Next time
 
Abstraction, continued
The Inheritance and Composition Patterns
Intro to UML
Intro to the Java Collections Framework (JCF)
Intro to Unit Testing with JUnit
   Reading:  Gray, Ch 1 and Ch 2
 
16
 
Thought of the Week
 
“To be a good geek you have to have both
humility
 and 
arrogance
 in equal measures.
The humility is so you’ll admit you don’t know
something and get help/read the docs/etc.
The arrogance is the bit that says 
“I don’t
know that now… but I can and I will soon.”
 
--Thomas Beagle, IT/programmer
 
17
 
Abstraction by interface
The Application Programmer Interface (API) of List specifies
everything an application programmer (client, user) needs
to know in order to use a List.
 
List
 
     insert(element)
     remove(element)
     find(element)
     isEmpty()
 
public interface
 
Same interface, different uses
Any client (user) can make use of a List through its public
Application Programmer Interface (API) without knowledge of
how the List is implemented.
 
Same interface, different implementations
There are many possible implementations of any ADT. The
implementation details are hidden from the user of the ADT,
who can rely just on the ADT’s API.
 
User-defined data types in Java
 
Java has 8 
primitive types
:  
byte, short, int,
long, char, float, double, boolean
And those are all there are: Java does not allow
additional user-defined primitive types
If you want to define a type in Java, you must
define either an 
interface
, or a 
class
Often we will use both interfaces and classes
when implementing an ADT in Java
 
21
 
ADT’s and Java classes
 
An ADT specifies the possible 
values
 that
instances of the ADT can have, and the
operations
 that can be performed on them
A Java class defines instance 
variables
, and
instance 
methods
So, there is a very close relationship between an
ADT and a class!
Variables
 defined in the class correspond to
ADT 
values
Methods
 defined in the class correspond to
ADT 
operations
 
22
 
ADT’s and Java interfaces
 
Usually, instance variables should be 
private
 in a
class
They are considered part of the implementation, not to be
accessed directly from outside the class
Then, we write 
public
 instance methods to
manipulate the instance variables
Mutator
 methods change the values of instance variables;
Accessor
 methods just ‘read out’ the values
This permits precise control over how the instance
variables can be accessed and changed
So, the principle of abstraction suggests we can
concentrate on the public instance methods
Java interfaces do that:  they define a Java type,
but specify only public instance method signatures
(no method bodies, no instance variables)
 
23
Slide Note
Embed
Share

Explore the world of data structures through peer instruction in Java with Cynthia Lee. This approach involves interactive group discussions, problem-solving, and hands-on activities to deepen understanding of key concepts. The course covers topics such as ADTs, APIs, algorithm analysis, object-oriented design, software testing, and Java collections. Embrace the power of abstraction and delve into various data structures like trees, heaps, and hash tables. Enhance your coding skills and collaborate effectively with your peers in a dynamic learning environment.

  • Peer instruction
  • Java
  • Data structures
  • Abstraction
  • Learning experience

Uploaded on Sep 28, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Creative Commons License CS2 in Java Peer Instruction Materials by Cynthia Lee is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Based on a work at http://peerinstruction4cs.org. Permissions beyond the scope of this license may be available at http://peerinstruction4cs.org. CSE 12 Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube s CSE 12

  2. 2 What do I do in class? Think of me as your tutor Be your guide in inducing you to explore concepts Create situations and pose problems that set the scene for yourexploration Answer your questions Notspend lecture reading the textbook to you with slightly different words

  3. 3 What do you do in class? (before class, you prepared yourself by reading; a reading quiz at the beginning of class will check your preparation) 1. I ask a question 2. You first answer it by yourself 3. Then discuss in assigned groups of 3-4 students Like a jury, you must come to a unanimous decision Answer the question a second time 4. I will ask groups to share their insights, and I will provide additional clarification as needed

  4. 4 Tips for a good group discussion Take turns being the first one to talk Once you all agree on the answer, don t stop! Always go over each wrong answer and explain why it is wrong Also interesting and useful to think about why somebody might be tempted to choose it how was Prof. Lovett hoping to trick somebody by including that wrong answer? Even if your group-mate has said something very clearly and correctly, it s a good idea to repeat it yourself So, what I think you said was, Might seem pointless, but your brain will remember better if YOU say it too

  5. Data Structures Map of the course

  6. Course topics Abstraction and Abstract Data Types (ADTs) Application Programmer Interfaces (APIs) Algorithm Time, Space, and Energy Cost Analysis Object-oriented Software Design Patterns, including Inheritance, Composition, Adapter, and Iterator Software Testing and the JUnit framework Java Classes and Interfaces Collections, and the Java Collections Framework Java Generics Arrays, Stacks, Queues, Circular Arrays Searching and Sorting Algorithms Trees, Heaps, Binary Search Trees, Abstract Syntax Trees Hashing and Hash Tables

  7. 7 Abstraction o Abstraction means: o Hiding irrelevant details to focus on the essential features needed to understand and use a thing o Abstraction is an essential tool for managing complexity o Designing, implementing, and using complex systems would be impossible without abstraction

  8. Group discussion What is another good daily life example of abstraction? Maybe I can use yours next quarter instead!

  9. 9 One kind of abstraction in Computer Science: Data Types o Specifying an Abstract Data Type ADT) requires specifying two things: o Possible values for instances of the type o Operations that can be performed on those instances o Does NOT require specifying: o How are those values and operations implemented?

  10. 10 ADT Implementers and Users This kind of abstraction is very powerful. The ADT can be implemented without having to know details of how it will be used (except that it will be used in accordance with its interface specification) The ADT can be used without having to know the details of how it is implemented (except that it was implemented to satisfy its interface specification) With any specification of an ADT interface: The ADT can be used infinitely many ways, and The ADT can be implemented infinitely many ways! This makes designing, implementing, using and maintaining software easier and more flexible

  11. 11 Example: a String ADT You might define a String abstract data type along these lines: Values: a String is a sequence of zero or more Unicode 1.0 characters Operations: Create a String Add a character to the end of a String Say what character is at a particular position in a String What other operations might be good to specify for a String ADT?

  12. 12 ADTs are language-neutral In CSE 12 we will concentrate on implementing ADT s in Java And we will consider many features of Java that are useful for implementing ADT s But always keep in mind that the basic principles of ADT design and analysis are language-neutral! APIs are like ADTs, but specify the interface in a particular language Users and impelmenters still do things as they please, but both within a common language

  13. 13 Application Programmer Interface (API) The implementer of an ADT in a particular language is a programmer And, usually, the client or user of an ADT is also a programmer in that language, who wants to use the ADT as a component in a larger software application Therefore the interface to an ADT in a particular language is said to be the Application Programmer Interface, or API, for the ADT in that language

  14. 14 Checkpoint: ADTs and APIs Which of the following would be elements of an ADT specification, and which would be elements of an API specification? I. int getValueAtIndex(int index) throws IndexOutOfBoundsException II. Get operation: given an index, returns the value at that index A. I is part of an API and II is part of an ADT B. II is part of an API and I is part of an ADT C. Both I and II could be part of an API or ADT D. Other

  15. Discussion ADTs and APIs exist to prevent users from knowing the implementation details (and vice versa). But Are there times when it would be useful to know the implementation details of an ADTs operations or values? Why?

  16. 16 Next time Abstraction, continued The Inheritance and Composition Patterns Intro to UML Intro to the Java Collections Framework (JCF) Intro to Unit Testing with JUnit Reading: Gray, Ch 1 and Ch 2

  17. 17 Thought of the Week To be a good geek you have to have both humility and arrogance in equal measures. The humility is so you ll admit you don t know something and get help/read the docs/etc. The arrogance is the bit that says I don t know that now but I can and I will soon. --Thomas Beagle, IT/programmer

  18. Abstraction by interface public interface List insert(element) remove(element) find(element) isEmpty() The Application Programmer Interface (API) of List specifies everything an application programmer (client, user) needs to know in order to use a List.

  19. Same interface, different uses Any client (user) can make use of a List through its public Application Programmer Interface (API) without knowledge of how the List is implemented.

  20. Same interface, different implementations There are many possible implementations of any ADT. The implementation details are hidden from the user of the ADT, who can rely just on the ADT s API.

  21. 21 User-defined data types in Java Java has 8 primitive types: byte, short, int, long, char, float, double, boolean And those are all there are: Java does not allow additional user-defined primitive types If you want to define a type in Java, you must define either an interface, or a class Often we will use both interfaces and classes when implementing an ADT in Java

  22. 22 ADT s and Java classes An ADT specifies the possible values that instances of the ADT can have, and the operations that can be performed on them A Java class defines instance variables, and instance methods So, there is a very close relationship between an ADT and a class! Variables defined in the class correspond to ADT values Methods defined in the class correspond to ADT operations

  23. 23 ADT s and Java interfaces Usually, instance variables should be private in a class They are considered part of the implementation, not to be accessed directly from outside the class Then, we write public instance methods to manipulate the instance variables Mutator methods change the values of instance variables; Accessormethods just read out the values This permits precise control over how the instance variables can be accessed and changed So, the principle of abstraction suggests we can concentrate on the public instance methods Java interfaces do that: they define a Java type, but specify only public instance method signatures (no method bodies, no instance variables)

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#