Programming Languages and Techniques (CIS120)
|
|
- Constance Richardson
- 5 years ago
- Views:
Transcription
1 Programming Languages and Techniques (CIS120) Lecture 29 April 3, 2014 Overriding, Enums, Iterators
2 public class Ref<T> { private T contents; public void add(t e) { contents = e; Quiz (on paper) public boolean contains(object o) { // what should we put here?? public static void main(string[] args) { Ref<Point> r = new Ref<Point>(); r.add(new Point(1,2)); System.out.println(r.contains(null)); // should print false System.out.println(r.contains(new Point(1,2))); // should print true
3 Method Overriding
4 A Subclass can Override its Parent public class C { public void printname() { System.out.println( I m a C ); public class D extends C { public void printname() { System.out.println( I m a D ); // somewhere in main C c = new D(); c.printname(); What gets printed to the console? 1. I m a C 2. I m a D 3. NullPointerExcepQon 4. NoSuchMethodExcepQon
5 A Subclass can Override its Parent public class C { public void printname() { System.out.println( I m a C ); public class D extends C { public void printname() { System.out.println( I m a D ); // somewhere in main C c = new D(); c.printname(); Our ASM model for dynamic dispatch already explains what will happen when we run this code. Useful for changing the default behavior of classes. But can be confusing and difficult to reason about if not used carefully.
6 Overriding Example Workspace Stack Heap C c = new D(); c.printname(); Class Table Object String tostring(){ boolean equals C extends C() { void printname(){ D extends D() { void printname(){
7 Overriding Example Workspace Stack Heap Class Table c.printname(); c D Object String tostring(){ boolean equals C extends C() { void printname(){ D extends D() { void printname(){
8 Overriding Example Workspace Stack Heap Class Table.printName(); c D Object String tostring(){ boolean equals C extends C() { void printname(){ D extends D() { void printname(){
9 Overriding Example Workspace Stack Heap Class Table System.out. println( I m a D ); c D Object String tostring(){ this boolean equals C extends C() { void printname(){ D extends D() { void printname(){
10 Difficulty with Overriding class C { public void printname() { System.out.println("I'm a " + getname()); public String getname() { return "C"; class E extends C { public String getname() { return "E"; What gets printed to the console? 1. I m a C 2. I m a E 3. I m an E 4. NullPointerExcepQon // in main C c = new E(); c.printname();
11 class C { Difficulty with Overriding public void printname() { System.out.println("I'm a " + getname()); public String getname() { return "C"; class E extends C { public String getname() { return "E"; // in main C c = new E(); c.printname(); The C class might be in another package, or a library... Whoever wrote E might not be aware of the implicaqons of changing getname. Overriding What gets the printed method to the causes console? the behavior of printname to change! 1. I m a C 2. I m a E Overriding can break invariants/ 3. I m an E abstracqons relied upon by the 4. NullPointerExcepQon superclass.
12 Digression: EnumeraQons See: ChatDemo.java
13 Poll Have you started HW 08? 1. yes 2. no
14 EnumeraQons (a.k.a. Enum Types) Java supports enumerated type constructors. These are a bit like OCaml s datatypes. They can be nested inside of other classes: e.g. Command.Type public static enum Type { CONNECT, NICK, JOIN, NAMES, MESG, LEAVE, MOD, UNMOD, KICK
15 Using Enums: Switch Cases // Use of the 'enum' from Command Command.Type t = switch (t) { case CONNECT : System.out.println("Got CONNECT!"); break; case MESG : System.out.println("Got MESG!"); break; default: System.out.println("default"); MulQ- way branch, similar to OCaml s match Works for: primiqve data int, byte, char, etc., Enum types, String Not pacern matching! (Cannot bind subcomponents of an Enum) The default keyword specifies the catch all case.
16 What will be printed by the following program? Command.Type t = Command.Type.CONNECT; switch (t) { case CONNECT : System.out.println("Got CONNECT!"); case MESG : System.out.println("Got MESG!"); case NICK : System.out.println("Got NICK!"); default: System.out.println("default"); 1. Got CONNECT! 2. Got MESG! 3. Got NICK! 4. default 5. something else
17 break GOTCHA: Must use explicit break to avoid fallthrough without break, the code of the next branch will be run too! The program in the quiz prints all of the strings: Got CONNECT! Got MESG! Got NICK! default
18 EnumeraQons Enum types are just a convenient way of defining a class along with methods of a class. Enum types (implicitly) extend java.lang.enum They can contain constant data properqes As classes, they can have methods: e.g. to access a field Intended to represent constant data values. AutomaQcally generated staqc methods: valueof : converts a String to an Enum Command.Type c = Command.Type.valueOf ("CONNECT"); values: returns an Array of all the enumerated constants Command.Type[] varr = Command.Type.values();
19 Accessing elements in a collecqon
20
21 Interfaces* of the CollecQons Library Iterable<E> Map<K,V> Collection<E> SortedMap<K,V> List<E> Deque<E> Set<E> SortedSet<E> *not all of them!
22 Iterator and Iterable interface Iterator<E> { public boolean hasnext(); public E next(); public void delete(); // optional interface Iterable<E> { public Iterator<E> iterator(); Challenge: given a List<Book> how would you add each book s data to a catalogue using an iterator?
23 While Loops interface Iterator<E> { public boolean hasnext(); public E next(); public void delete(); // optional example with while loops: List<Book> shelf = // create a list of Books //iterate through the elements on the shelf Iterator<Book> iter = shelf.iterator(); while (iter.hasnext()) { Book book = iter.next(); catalogue.addinfo(book); numbooks = numbooks+1;
24 For Loops interface Iterator<E> { public boolean hasnext(); public E next(); public void delete(); // optional example with for loops: List<Book> shelf = // create a list of Books //iterate through the elements on the shelf for (Iterator<Book> iter = shelf.iterator(); iter.hasnext();) { Book book = iter.next(); catalogue.addinfo(book); numbooks = numbooks+1;
25 syntax: New: For- each Loops example: //repeat body for each element in collection for (type var : coll) { body ; element type array or instance of Iterable<E> List<Book> shelf = // create a list of books //iterate through the elements on a shelf for (Book book : shelf) { catalogue.addinfo(book); numbooks = numbooks+1;
26 Another example: For- each Loops (Cont d) int[] arr = // create an array of ints //count the non-zero elements of an array for (int elt : arr) { if (elt!= 0) cnt = cnt+1; For- each can be used to iterate over arrays or any class that implements the Iterable<E> interface (notably Collection<E> and its subinterfaces).
27 Iterator example public static void iteratorexample() { List<Integer> nums = new LinkedList<Integer>(); nums.add(1); nums.add(2); nums.add(7); int numelts = 0; int sumelts = 0; Iterator<Integer> iter = nums.iterator(); while (iter.hasnext()) { Integer v = iter.next(); sumelts = sumelts + v; numelts = numelts + 1; What is printed by iteratorexample()? 1. sumelts = 0 numelts = 0 2. sumelts = 3 numelts = 2 3. sumelts = 10 numelts = 3 4. NullPointerExcepQon 5. Something else System.out.println("sumElts = " + sumelts); System.out.println("numElts = " + numelts);
28 For- each version public static void foreachexample() { List<Integer> nums = new LinkedList<Integer>(); nums.add(1); nums.add(2); nums.add(7); int numelts = 0; int sumelts = 0; for (Integer v : nums) { sumelts = sumelts + v; numelts = numelts + 1; System.out.println("sumElts = " + sumelts); System.out.println("numElts = " + numelts);
Programming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 March 30, 2018 Overriding Methods, Equality, Enums, Iterators Chapters 25 and 26 Method Overriding When a subclass replaces an inherited method
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 29 Enums & Iterators Announcements Prof. Benjamin Pierce is lecturing today Will be teaching 120 again next Spring Enumerations Enumerations (a.k.a.
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 November 7, 2018 Overriding Methods, Equality, Enums, Iterators Chapters 25 and 26 Announcements HW7: Chat Server Available on Codio / Instructions
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 April 2, 2014 Generics and CollecCons Midterm 2 is Friday Announcements Towne 100 last names A - L DRLB A1 last names M - Z Review sessions: Tonight!
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 November 8, 2017 Overriding Methods, Equality, Enums Chapter 26 Announcements HW7: Chat Server Available on Codio / InstrucNons on the web site
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 27 Mar 23, 2012 Generics, CollecBons and IteraBon Announcements CIS Course Faire TODAY at 3PM, here HW08 is due on Monday, at 11:59:59pm Midterm 2
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 36 April 23, 2014 Overriding and Equality HW 10 has a HARD deadline Announcements You must submit by midnight, April 30 th Demo your project to your
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 31 April 3, 2013 Overriding, Equality, and Casts Announcements HW 09 due Tuesday at midnight More informajon about exam 2 available on Friday Unfinished
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 28 March 30, 2016 Collections and Equality Chapter 26 Announcements Dr. Steve Zdancewic is guest lecturing today He teaches CIS 120 in the Fall Midterm
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (IS120) Lecture 29 November 11, 2015 Overriding, Enums, ExcepFons HW07: PennPals is available Due Tuesday: November 17 th Start Early! Announcements Emphasizes: Java
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 29 April 7, 2014 ExcepEons Read Chapter 28 Announcements Homework 9 available later today, due Tuesday April 15 th at midnight Focus: working with
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 27 March 28, 2018 Java Generics Collections and Equality Chapters 25 & 26 Announcements HW7: Chat Server Available on Codio / Instructions on the web
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 27 March 23 rd, 2016 Generics and Collections Chapter 25 HW #6 due Tuesday Announcements I will be away all next week (FP workshop in Germany) Monday's
More informationJava Review: Objects
Outline Java review Abstract Data Types (ADTs) Interfaces Class Hierarchy, Abstract Classes, Inheritance Invariants Lists ArrayList LinkedList runtime analysis Iterators Java references 1 Exam Preparation
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int
More informationJAVA COLLECTION FRAMEWORK & SETS
JAVA COLLECTION FRAMEWORK & SETS Ch07.4-5 & Ch10.5 Presentation for use with the textbook 1. Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 24 October 29, 2018 Arrays, Java ASM Chapter 21 and 22 Announcements HW6: Java Programming (Pennstagram) Due TOMORROW at 11:59pm Reminder: please complete
More informationCIS 120 Midterm II November 16, 2012 SOLUTIONS
CIS 120 Midterm II November 16, 2012 SOLUTIONS 1 1. Java vs. OCaml (22 points) a. In OCaml, the proper way to check whether two string values s and t are structurally equal is: s == t s = t s.equals(t)
More informationPIC 20A Collections and Data Structures
PIC 20A Collections and Data Structures Ernest Ryu UCLA Mathematics Last edited: March 14, 2018 Introductory example How do you write a phone book program? Some programmers may yell hash table! and write
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 26 November 3, 2017 The Java ASM, Java Generics Chapter 24 Announcements HW7: Chat Server Available on Codio / InstrucNons on the web site Due Tuesday,
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write
More informationCIS 120 Midterm II November 16, Name (printed): Pennkey (login id):
CIS 120 Midterm II November 16, 2012 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing
More information10/30/2010. Introduction to Control Statements. The if and if-else Statements (cont.) Principal forms: JAVA CONTROL STATEMENTS SELECTION STATEMENTS
JAVA CONTROL STATEMENTS Introduction to Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. In Java, control
More informationAnother IS-A Relationship
Another IS-A Relationship Not all classes share a vertical relationship. Instead, some are supposed to perform the specific methods without a vertical relationship. Consider the class Bird inherited from
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Information Technology and Engineering Iterator (part II) Inner class Implementation: fail-fast Version of March 20, 2011 Abstract These
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More information2IP15 Programming Methods
Lecture 5: Iteration Abstraction 2IP15 Programming Methods From Small to Large Programs Tom Verhoeff Eindhoven University of Technology Department of Mathematics & Computer Science Software Engineering
More informationSoftware 1 with Java. Recitation No. 6 (Collections)
Software 1 with Java Recitation No. 6 (Collections) Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework Interfaces Implementations Algorithms 2
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 26 March 26, 2015 Inheritance and Dynamic Dispatch Chapter 24 public interface Displaceable { public int getx(); public int gety(); public void move
More informationCS313D: ADVANCED PROGRAMMING LANGUAGE
CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science Department Lecture 3: C# language basics Lecture Contents 2 C# basics Conditions Loops Methods Arrays Dr. Amal Khalifa, Spr 2015 3 Conditions and
More informationJava classes cannot extend multiple superclasses (unlike Python) but classes can implement multiple interfaces.
CSM 61B Abstract Classes & Interfaces Spring 2017 Week 5: February 13, 2017 1 An Appealing Appetizer 1.1 public interface Consumable { public void consume (); public abstract class Food implements Consumable
More informationTopic 10: The Java Collections Framework (and Iterators)
Topic 10: The Java Collections Framework (and Iterators) A set of interfaces and classes to help manage collections of data. Why study the Collections Framework? very useful in many different kinds of
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationCS 3 Introduction to Software Engineering. 5: Iterators
CS 3 Introduction to Software Engineering 5: Iterators Questions? 2 PS1 Discussion Question You are to choose between two procedures, both of which compute the minimum value in an array of integers. One
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 31 November 17, 2017 I/O & Histogram Demo Chapters 28 Announcements HW8: SpellChecker Available on the website and Codio Due next Tuesday, November
More informationCSC 1214: Object-Oriented Programming
CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:
More informationCIS 120 Final Exam May 7, Name (printed): Pennkey (login id):
CIS 120 Final Exam May 7, 2014 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 37 April 22, 2016 Encapsulation & Hashing How is the Game Project going so far? 1. not started 2. got an idea 3. submitted design proposal 4. started
More informationCS/ENGRD 2110 SPRING Lecture 5: Local vars; Inside-out rule; constructors
1 CS/ENGRD 2110 SPRING 2017 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 Announcements 2 1. Writing tests to check that the code works when the precondition
More informationFollowing is the general form of a typical decision making structure found in most of the programming languages:
Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined
More informationOutline. iterator review iterator implementation the Java foreach statement testing
Outline iterator review iterator implementation the Java foreach statement testing review: Iterator methods a Java iterator only provides two or three operations: E next(), which returns the next element,
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Iterator 1 (part I) Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 26, 2013 Abstract These lecture notes are meant to be looked
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 25 November 1, 2017 Inheritance and Dynamic Dispatch (Chapter 24) Announcements HW7: Chat Client Available Soon Due: Tuesday, November 14 th at 11:59pm
More informationLecture 8: Iterators and More Mutation
Integrated Introduction to Computer Science Fisler, Nelson Contents 1 Traversing Lists 1 2 Motivating Iterators 2 3 Writing an Iterator 3 4 Writing Sum with an Iterator 4 Objectives By the end of this
More informationSoftware 1 with Java. Java Collections Framework. Collection Interfaces. Online Resources. The Collection Interface
Java Collections Framework Collection: a group of elements Based Design: Software 1 with Java Java Collections Framework s s Algorithms Recitation No. 6 (Collections) 2 Collection s Online Resources Collection
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Iterator 1 (part I) Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 26, 2013 Abstract These lecture notes are meant to be looked
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 34 April 18, 2013 Swing II: Layout & Designing a GUI app How is HW10 going so far? 1. not started 2. started reading 3. got an idea for what game to
More information1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8
Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(
More informationDM550 / DM857 Introduction to Programming. Peter Schneider-Kamp
DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ ABSTRACT DATATYPES 2 Abstract Datatype (ADT)
More informationCollections and Iterators. Collections
Collections and Iterators Based on the notes from David Fernandez-Baca and Steve Kautz Based on The Java Tutorial (http://docs.oracle.com/javase/tutorial/java/) Bryn Mawr College CS206 Intro to Data Structures
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationPrelim 1. CS 2110, October 1, 2015, 5:30 PM Total Question Name True Short Testing Strings Recursion
Prelim 1 CS 2110, October 1, 2015, 5:30 PM 0 1 2 3 4 5 Total Question Name True Short Testing Strings Recursion False Answer Max 1 20 36 16 15 12 100 Score Grader The exam is closed book and closed notes.
More informationCS 302 Week 9. Jim Williams
CS 302 Week 9 Jim Williams This Week P2 Milestone 3 Lab: Instantiating Classes Lecture: Wrapper Classes More Objects (Instances) and Classes Next Week: Spring Break Will this work? Double d = new Double(10);
More informationenum Types 1 1 The keyword enum is a shorthand for enumeration. Zheng-Liang Lu Java Programming 267 / 287
enum Types 1 An enum type is an reference type limited to an explicit set of values. An order among these values is defined by their order of declaration. There exists a correspondence with string names
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
More informationObject-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007
Object-Oriented Design Lecture 14 CSU 370 Fall 2007 (Pucella) Friday, Nov 2, 2007 (These notes are very rough, and differ somewhat from what I presented in class; I am posting them here to supplemental
More informationINDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line
A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Iterator 1 (part I) Marcel Turcotte School of Electrical Engineering and Computer Science Version of March 24, 2013 Abstract These lecture notes are meant to be looked
More informationJava Fundamentals (II)
Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class
More informationJava Control Statements
Java Control Statements An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationIntroduction to Java https://tinyurl.com/y7bvpa9z
Introduction to Java https://tinyurl.com/y7bvpa9z Eric Newhall - Laurence Meyers Team 2849 Alumni Java Object-Oriented Compiled Garbage-Collected WORA - Write Once, Run Anywhere IDE Integrated Development
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 25 March 18, 2013 Subtyping and Dynamic Dispatch Announcements HW07 due tonight at midnight Weirich OH cancelled today Help your TAs make the most
More informationCIS 120 Final Exam 19 December 2014 SOLUTIONS
CIS 120 Final Exam 19 December 2014 SOLUTIONS 1 1. Java Concepts: True or False (10 points) All of the following questions pertain to Java. a. T F If s and t are variables of type String such that s ==
More informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationCSE 143 Lecture 26. Advanced collection classes. (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, ,
CSE 143 Lecture 26 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, 15.3-15.4, 16.4-16.5 slides created by Marty Stepp, adapted by Alyssa Harding
More informationWelcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018
Welcome to CSE 142! Whitaker Brand University of Washington, Winter 2018 1 What is computer science? computers? science? programming? late lonely nights in front of the computer? ALGORITHMIC THINKING al
More information(A) 99 ** (B) 100 (C) 101 (D) 100 initial integers plus any additional integers required during program execution
Ch 5 Arrays Multiple Choice Test 01. An array is a ** (A) data structure with one, or more, elements of the same type. (B) data structure with LIFO access. (C) data structure, which allows transfer between
More information3. Java - Language Constructs I
Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationPull Lecture Materials and Open PollEv. Poll Everywhere: pollev.com/comp110. Lecture 12. else-if and while loops. Once in a while
Pull Lecture Materials and Open PollEv Poll Everywhere: pollev.com/comp110 Lecture 12 else-if and while loops Once in a while Fall 2016 if-then-else Statements General form of an if-then-else statement:
More informationLecture 22: Java. Overall Structure. Classes & Objects. Every statement must end with ';' Carl Kingsford, , Fall 2015
Carl Kingsford, 0-0, Fall 0 Lecture : Java Overall Structure Classes & Objects Every function in Java must be inside a class, which are similar to Go's struct s. For example: 8 9 0 8 9 class MyProgram
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationJava Collections. Wrapper classes. Wrapper classes
Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being
More informationJava Collections. Engi Hafez Seliem
Java Collections Engi- 5895 Hafez Seliem Wrapper classes Provide a mechanism to wrap primitive values in an object so that the primitives can be included in activities reserved for objects, like as being
More informationWrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321
Wrapper Classes To treat values as objects, Java supplies standard wrapper classes for each primitive type. For example, you can construct a wrapper object from a primitive value or from a string representation
More informationLe L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements
Course Name: Advanced Java Lecture 3 Topics to be covered Control Statements Introduction The control statement are used to control the flow of execution of the program. This execution order depends on
More information1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003
1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to
More informationCS 201, Fall 2016 Oct 28th Exam 2. Question 1. [5 points] Consider the following static method:
CS 201, Fall 2016 Oct 28th Exam 2 Name: Question 1. [5 points] Consider the following static method: public static int mystery(int[] arr) { int x = 0; for (int i = 0; i < arr.length; i++) { x += arr[i];
More informationExample: Count of Points
Example: Count of Points 1 class Point { 2... 3 private static int numofpoints = 0; 4 5 Point() { 6 numofpoints++; 7 } 8 9 Point(int x, int y) { 10 this(); // calling the constructor with no input argument;
More informationCS/ENGRD 2110 FALL Lecture 5: Local vars; Inside-out rule; constructors
1 CS/ENGRD 2110 FALL 2018 Lecture 5: Local vars; Inside-out rule; constructors http://courses.cs.cornell.edu/cs2110 Announcements 2 A1 is due tomorrow If you are working with a partner: form a group on
More informationCONDITIONAL EXECUTION: PART 2
CONDITIONAL EXECUTION: PART 2 yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Review: The if-else statement The switch statement A look
More informationGoal. Generic Programming and Inner classes. Minor rewrite of linear search. Obvious linear search code. Intuitive idea of generic linear search
Goal Generic Programming and Inner classes First version of linear search Input was array of int More generic version of linear search Input was array of Comparable Can we write a still more generic version
More informationCOE318 Lecture Notes Week 4 (Sept 26, 2011)
COE318 Software Systems Lecture Notes: Week 4 1 of 11 COE318 Lecture Notes Week 4 (Sept 26, 2011) Topics Announcements Data types (cont.) Pass by value Arrays The + operator Strings Stack and Heap details
More informationDiscover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.
Java SE11 Development Java is the most widely-used development language in the world today. It allows programmers to create objects that can interact with other objects to solve a problem. Explore Java
More informationAbout this exam review
Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review
More informationMany strategies have been developed for this, but they often produce surprising results.
Interfaces C++ is among those languages offering multiple inheritance: a class may inherit from more than one direct superclass. This adds flexibility, but it also brings problems. A class may inherit
More informationCOMP 202 Java in one week
COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of
More informationInheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8
Inheritance, cont. Notes Chapter 6 and AJ Chapters 7 and 8 1 Preconditions and Inheritance precondition what the method assumes to be true about the arguments passed to it inheritance (is-a) a subclass
More informationPractice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course
: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order
More informationTiming for Interfaces and Abstract Classes
Timing for Interfaces and Abstract Classes Consider using abstract classes if you want to: share code among several closely related classes declare non-static or non-final fields Consider using interfaces
More informationName: Pennkey (eg, sweirich): CIS 120 Final Exam May 8, 2012
Name: Pennkey (eg, sweirich): CIS 120 Final Exam May 8, 2012 My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing this examination.
More informationEXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction
More informationI pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.
Name: Covers Chapters 1-3 50 mins CSCI 1301 Introduction to Programming Armstrong Atlantic State University Instructor: Dr. Y. Daniel Liang I pledge by honor that I will not discuss this exam with anyone
More information