Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.

Slides:



Advertisements
Similar presentations
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Advertisements

Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
CS 211 Inheritance AAA.
Inheritance Inheritance Reserved word protected Reserved word super
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CS180 Review Questions. Administriva Final Exam –Friday 8am MTHW 210 –No GUI programming question –Format 35 multiple choice questions 4 programming.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
Part-B1 Stacks. Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
1 Topic 10 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.”
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
OOP Languages: Java vs C++
Multiple Choice Solutions True/False a c b e d   T F.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Introduction to Java Prepared by: Ahmed Hefny. Outline Classes Access Levels Member Initialization Inheritance and Polymorphism Interfaces Inner Classes.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the.
1 Abstract Classes “I prefer Agassiz in the abstract, rather than in the concrete.” CS Computer Science II.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Created by Terri Street Copyright, 2000  1,000,0001,000,000  500,000500,000  250,000250,000  125,000125,000  64,00064,000  32,00032,000  16,00016,000.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Inheritance (Part 5) Odds and ends 1. Static Methods and Inheritance  there is a significant difference between calling a static method and calling a.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 5:Interfaces and Abstract Classes
Modern Programming Tools And Techniques-I
Inheritance and Polymorphism
Agenda Warmup AP Exam Review: Litvin A2
Programming Language Concepts (CIS 635)
Java Programming: Guided Learning with Early Objects
Wrapper Classes ints, doubles, and chars are known as primitive types, or built-in types. There are no methods associated with these types of variables.
null, true, and false are also reserved.
Java Programming Language
Chapter 9 Carrano Chapter 10 Small Java
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Topics OOP Review Inheritance Review Abstract Classes
CIS 110: Introduction to computer programming
Presentation transcript:

Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You’ll learn much less if you just look at the question, then the answer, and go “Okay, that makes sense” (as opposed to actively attempting to think about a solution first).

Choose a category. You will be given the answer. You must give the correct question. Click to begin.

Click here for Final Jeopardy

Data Structures Jolly Java Crafty Coding 10 Point 20 Points 30 Points 40 Points 50 Points 10 Point 20 Points 30 Points 40 Points 50 Points 30 Points 40 Points 50 Points Typing & Hierarchy Ominous OCaml

Write in Java: let x: int ref = ref 1

int x = 1;

Write in Java: let y (x: int): int = x * x + 1

int y(int x) { return x * x + 1; }

Write in Java: map [3; 1; 2] fun x -> x + 1

int[] a = [3, 1, 2]; for (int j = 0; j < a.length; j++) { a[j]++; }

Write in Java: let new_counter (): (unit -> unit * unit -> int) = let x: int ref = ref 0 in (fun () -> x := !x + 1, fun () -> !x)

public class Counter { private int x; public Counter() { x = 0; } public void increment() { x++; } public int get() { return x; } }

Write in Java: type 'a tree = | Empty | Node of 'a tree * 'a * 'a tree

class Node { // use null for empty tree public Node left, right; public E element; }

Give an example of data that can be modeled as ('a, 'b set) map

A classroom of students, each with a set of grades.

Give an example of data that can be modeled as List >

A bookshelf of phone books.

What is the main difference between OCaml and Java data structures?

Mutability.

What is one implementation strategy for the map ADT?

A set of key-value pairs, or a BST with no repeated elements and a key for each element.

What are two implementation strategies for the set ADT?

A list with no repeats, a BST with no repeats, or a map with dummy keys.

What are the static and dynamic types of x in the following? Iterator x = new Scanner();

Static type: Iterator Dynamic type: Scanner

Name two major differences between interfaces and abstract classes.

1. A class can extend one class but implement many interfaces. 2. An interface cannot contain implementation code; an abstract class can.

What is dynamic dispatch? How does it work in the abstract machine model?

Dynamic dispatch: what code (e.g. method body) is executed depends on the dynamic type of the object. Type found by “pointer chasing” in the abstract model to determine the dynamic type.

List l = new LinkedList (); l.add(new A()); l.add(new B()); D d = l.get(0); Draw an inheritance tree for classes A, B, C, and D.

D C B A

List i = new ArrayList (); ArrayList j = new ArrayList (); List k; For each, state whether valid. Assume they run independently. i = j; j = i; k = i; k = j;

i = j; // Okay j = i; // Bad k = i; // Bad k = j; // Bad

What is a parent of all classes? Name two of its methods.

Object String toString(); boolean equals(Object o); (among others)

What is the difference between overriding and overloading? Which uses dynamic type, and which uses static type?

Overriding: redefining a method in a child class (same signature). Dynamic type. Overload: methods with same name, but different arguments. Static type.

What does protected keyword mean?

Denotes a field that only the class and its subclasses can access.

Describe two classes in the I/O library, explain what operations you could perform with it. Describe two different exceptions that may be thrown.

File – can open, create, delete files. Can throw FileNotFoundException. Reader – (abstract class) allows you to read characters from a stream. Can throw IOExceptions (of which there are many flavors).

Name three different uses of the static keyword in Java; explain the effect on each kind of entity.

Classes: static nested classes can be accessed without enclosing instance, e.g. new Outer.Inner(); instead of (new Outer()).Inner(); Methods: static methods belong to the class, e.g. Math.cos(80); Variables: static methods belong to the class, and are shared by all instances.

Complete the method: // Returns twice the number if odd, // else the number if even. int foo(int x);

int foo(int x) { if (x % 2 == 0) // even return x; else return x * 2; }

Design classes/interfaces for the situation: You are writing a Blackboard-alternative software for a class. The software has a dropbox for students to submit assignments (each assignment is either a text document, a code ZIP, or an image diagram). Assignments are identified by a numerical ID. The professor wants to be able to: - access all documents submitted for a given assignment, in the order they were submitted - assign a grade to each assignment

Sample, this has no fixed solution! interface Assignment { int getGrade(); void assignGrade(int x); File getFile(); } class Text extends Assignment … class Code extends Assignment… class Diagram extends Assignment… class DropBox { List getFilesForAssignment(int assignment_id); }

Complete the method: // Returns the number, // or 0 if not a numerical string. // You should use Integer.parseInt int getIntFrom(String s);

int getIntFrom(String s) { int x = 0; try { x = Integer.parseInt(s); } catch (NumberFormatEx..) { // Leave x = 0. } return 0; }

Complete the method: // Recursive method that returns // true if string is palindrome. boolean isPalindrome(String s);

boolean isPalindrome(String s) { if (s.length() <= 1) return true; if (s.charAt(0) == s.charAt(s.length()-1)) { String tmp = s.substring(1, s.length()-1); return isPalindrome(tmp); } else { return false; } }

Complete the method: // Reverse array in place. void reverseArray(Object[] o);

void reverseArray(Object[] o) { for (int i = 0; i < o.length/2; i++) { Object tmp = o[i]; o[i] = o[o.length-i-1]; o[o.length-i-1] = tmp; } }

Make your wager

At the beginning of the year, we prescribed a design process to translate informal specifications into code. What are the four steps of the “design process”?

1. Understand the problem. 2. Formalize the interface. 3. Write test cases. 4. Implement required behavior.