Java Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types
|
|
|
- David Walters
- 9 years ago
- Views:
Transcription
1 Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts with a class Method names, argument/return types, fields Java has a construct called interface which can be used formally for this purpose public interface List { Recall: A List Interface public void insert (Object element); public void delete (Object element); public boolean contains (Object element); public int size (); The interface specifies the methods without saying anything about the implementation Matches idea of ADT (Abstract Data Type) Any class that implements List can be stored in a variable of type List Another Java Interface Example void scramble(); boolean move(char d); class IntPuzzle implements IPuzzle { public void scramble() { public int tile(int r, int c) { public boolean move(char d) { Name of interface: IPuzzle A class implements this interface by implementing instance methods as specified in the interface The class may implement other methods as well Interface Notes An interface is not a class! Cannot be instantiated Incomplete specification A class header must assert implements I for Java to recognize that the class implements interface I A class may implement several interfaces: class X implements IPuzzle, IPod { Why an interface construct? Good software engineering Can specify and enforce boundaries between different parts of a team project Can use interface as a type Allows more generic Reduces duplication
2 Example of Code Duplication Suppose we have two implementations of puzzles: Class IntPuzzle uses an int to hold state Class ArrayPuzzle uses an array to hold state Assume client wants to use both implementations Perhaps for benchmarking both implementations to pick the best one Assume client has a display method to print out puzzles What would the display method look like? Class Client{ IntPuzzle p1 = new IntPuzzle(); ArrayPuzzle p2 = new ArrayPuzzle(); display(p1)display(p2) public static void display(intpuzzle p){ public static void display(arraypuzzle p){ Code duplicated because IntPuzzle and ArrayPuzzle are different Observation Two display methods are needed because IntPuzzle and ArrayPuzzle are different types, and parameter p must be one or the other But the inside the two methods is identical! Code relies only on the assumption that the object p has an instance method tile(int,int). Is there a way to avoid this duplication? Puzzle Client One Solution: Abstract Classes abstract class Puzzle { abstract class IntPuzzle extends Puzzle { public int tile(int r, int c) { class ArrayPuzzle extends Puzzle { public int tile(int r, int c) { public static void display(puzzle p){ Puzzle Client Another Solution: Interfaces class IntPuzzle implements IPuzzle { public int tile(int r, int c) { class ArrayPuzzle implements IPuzzle { public int tile(int r, int c) { Extending vs. Implementing A class can extend just one superclass Multiple inheritance can cause conflicts Example: Which of 2 inherited methods to use when both have identical signatures? But a class can implement multiple interfaces Multiple interfaces don t conflict because there are no implementations To share between two classes Put shared in a common superclass Interfaces cannot contain
3 More on Interfaces Interface methods Interface methods are implicitly public and abstract No static methods are allowed in interfaces Interface constants Interface constants are public, static, and final Can inherit multiple versions of constants Compiler detects this When this occurs, fully qualified names are required Interface Types IntPuzzle IPuzzle ArrayPuzzle Interface names can be used in type declarations IPuzzle p1, p2; A class that implements the interface is a subtype of the interface type IntPuzzle and ArrayPuzzle are subtypes of IPuzzle IPuzzle is a supertype of IntPuzzle and ArrayPuzzle Interfaces Classes Java Type Hierarchy IPuzzle IPod IRon AClass BClass Unlike Java classes, Java types do not form a tree! A class may implement several interfaces An interface may be implemented by several classes The type hierarchy does form a dag (directed acyclic graph) Static Type vs. Dynamic Type Every variable (more generally, every expression that denotes some kind of data) has a static* or compile-time type Derived from declarations you can see it Known at compile time, without running the program Does not change Every object ever created also has a dynamic or runtime type Obtained when the object is created using new Not known at compile time you can t see it * Warning! No relation to Java keyword static Example int i = 3, j = 4; Integer x = new Integer(i+3*j-1); System.out.println(x.toString()); static type of the variables i,j and the expression i+3*j-1 is int static type of the variable x and the expression new Integer(i+3*j-1) is Integer static type of the expression x.tostring() is String (because tostring() is declared in the class Integer to have return type String) dynamic type of the object created by the execution of new Integer(i+3*j-1) is Integer Reference vs. Primitive Types Reference types Classes, interfaces, arrays E.g.: Integer x: Primitive types int, long, short, byte, boolean, char, float, double (Integer) int value: 13 String tostring() x: 13
4 Why Both int and Integer? Some data structures work only with reference types (HashMap, ArrayList, Stack,) Primitive types are more efficient for (int i = 0; i < n; i++) { Upcasting and Downcasting Applies to reference types only Used to assign the value of an expression of one (static) type to a variable of another (static) type upcasting: subtype supertype downcasting: supertype subtype Note that the dynamic type does not change! A crucial invariant: If the value of an expression E is an object O then the dynamic type of O is a subtype of the static type of E Example of upcasting: Upcasting Object x = new Integer(13); Static type of expression on rhs is Integer Static type of variable x on lhs is Object Integer is a subtype of Object, so this is an upcast Static type of expression on rhs must be a subtype of static type of variable on lhs compiler checks this Upcasting is always type correct preserves the invariant automatically Example of downcasting: Downcasting Integer x = (Integer)y; Static type of y is Object (say) Static type of x is Integer Static type of expression (Integer)y is Integer Integer is a subtype of Object, so this is a downcast In any downcast, dynamic type of object must be a subtype of static type of cast expression Implies that a runtime check is needed to maintain invariant (and only time it is needed) ClassCastException if failure Is the Runtime Check Necessary? Yes, because dynamic type of object may not be known at compile time void bar() { foo(new Integer(13)); String("x") void foo(object y) { int z = ((Integer)y).intValue(); Upcasting with Interfaces Java allows upcasting: IPuzzle p1 = new ArrayPuzzle(); IPuzzle p2 = new IntPuzzle(); Static types of right-hand side expressions are ArrayPuzzle and IntPuzzle, respectively Static type of left-hand side variables is IPuzzle Rhs static types are subtypes of lhs static type, so this is OK
5 Why Upcasting? Subtyping and upcasting can be used to avoid duplication Back to puzzle example: you and client agree on interface IPuzzle interface IPuzzle{ void scramble(); boolean move(char d); Puzzle Code using IPuzzle Interface Client class IntPuzzle implements IPuzzle { public int tile(int r, int c) { class ArrayPuzzle implements IPuzzle { public int tile(int r, int c) { Method Dispatch Which tile method is invoked? Depends on dynamic type of object p (IntPuzzle or ArrayPuzzle) We don't know what this dynamic type is, but whatever it is, we know it has a tile method (since any class that implements IPuzzle must have a tile method) Method Dispatch At compile-time Check that the static type of p (namely IPuzzle) has a tile method with the right type signature? No error At runtime Go to the object that is the value of p, find its dynamic type, look up its tile method The compile-time check guarantees that an appropriate tile method exists Note Upcasting and downcasting do not change the object they merely allow it to be viewed at compile time as a different static type Another Use of Upcasting Heterogeneous Data Structures Example: IPuzzle[] pzls = new IPuzzle[9]; pzls[0] = new IntPuzzle(); pzls[1] = new ArrayPuzzle(); An expression pzls[i] is of type IPuzzle Objects created on right hand sides are of subtypes of IPuzzle
6 Java instanceof Example: if (p instanceof IntPuzzle) { True if dynamic type of p is a subtype of IntPuzzle Usually used to check if a downcast will succeed Example Suppose twist is a method implemented only in IntPuzzle void twist(ipuzzle[] pzls) { for (int i = 0; i < pzls.length; i++) { if (pzls[i] instanceof IntPuzzle) { IntPuzzle p = (IntPuzzle)pzls[i]; p.twist(); Avoid Useless Downcasting Subinterfaces bad void moveall(ipuzzle[] pzls) { for (int i = 0; i < pzls.length; i++) { if (pzls[i] instanceof IntPuzzle) ((IntPuzzle)pzls[i]).move("N"); else ((ArrayPuzzle)pzls[i]).move("N"); Suppose you want to extend the interface to include more methods IPuzzle: scramble, move, tile ImprovedPuzzle: scramble, move, tile, samloyd good void moveall(ipuzzle[] pzls) { for (int i = 0; i < pzls.length; i++) pzls[i].move("n"); Two approaches Start from scratch and write an interface Extend the IPuzzle interface void scramble(); boolean move(char d); interface ImprovedPuzzle extends IPuzzle { void SamLoyd(); IPuzzle is a superinterface of ImprovedPuzzle ImprovedPuzzle is a subinterface of IPuzzle ImprovedPuzzle is a subtype of IPuzzle An interface can extend multiple superinterfaces A class that implements an interface must implement all methods declared in all superinterfaces C A B Interfaces E D G interface C extends A,B { class F extends D implements A { class E extends D implements A,B { F Classes I
7 Conclusion Interfaces have two main uses Software engineering: good fences make good neighbors Subtyping Subtyping is a central idea in programming languages Inheritance and interfaces are two methods for creating subtype relationships
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
CS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 25 Multiple Inheritance and Interfaces Dan Grossman 2012 Multiple Inheritance Why not allow class C extends C1,C2,...{...} (and C C1 and C C2)? What everyone
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages Corky Cartwright Swarat Chaudhuri November 30, 20111 Overview I In OO languages, data values (except for designated non-oo
CSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
language 1 (source) compiler language 2 (target) Figure 1: Compiling a program
CS 2112 Lecture 27 Interpreters, compilers, and the Java Virtual Machine 1 May 2012 Lecturer: Andrew Myers 1 Interpreters vs. compilers There are two strategies for obtaining runnable code from a program
Implementation Aspects of OO-Languages
1 Implementation Aspects of OO-Languages Allocation of space for data members: The space for data members is laid out the same way it is done for structures in C or other languages. Specifically: The data
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
Inheritance, overloading and overriding
Inheritance, overloading and overriding Recall with inheritance the behavior and data associated with the child classes are always an extension of the behavior and data associated with the parent class
SE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin
SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages
Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class
CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,
Chapter 13 - Inheritance
Goals Chapter 13 - Inheritance To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn about protected and package
Basic Programming and PC Skills: Basic Programming and PC Skills:
Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of
Semantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
Programming Languages Featherweight Java David Walker
Programming Languages Featherweight Java David Walker Overview Featherweight Java (FJ), a minimal Javalike language. Models inheritance and subtyping. Immutable objects: no mutation of fields. Trivialized
Data Structures and Algorithms Written Examination
Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
CS193j, Stanford Handout #10 OOP 3
CS193j, Stanford Handout #10 Summer, 2003 Manu Kumar OOP 3 Abstract Superclass Factor Common Code Up Several related classes with overlapping code Factor common code up into a common superclass Examples
Designing with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219
Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing
Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.
Arrays Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays: http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html 1 Grid in Assignment 2 How do you represent the state
Introduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
Comp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer
Lecture 10: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
Abstract Class & Java Interface
Abstract Class & Java Interface 1 Agenda What is an Abstract method and an Abstract class? What is Interface? Why Interface? Interface as a Type Interface vs. Class Defining an Interface Implementing an
Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013
Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper
Java Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
Pemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Polymorphism. Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding. Polymorphism.
Why use polymorphism Upcast revisited (and downcast) Static and dynamic type Dynamic binding Polymorphism Polymorphism A polymorphic field (the state design pattern) Abstract classes The composite design
Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
Lab Experience 17. Programming Language Translation
Lab Experience 17 Programming Language Translation Objectives Gain insight into the translation process for converting one virtual machine to another See the process by which an assembler translates assembly
Part I. Multiple Choice Questions (2 points each):
Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1
The Java Series Java Essentials I What is Java? Basic Language Constructs Slide 1 What is Java? A general purpose Object Oriented programming language. Created by Sun Microsystems. It s a general purpose
Part 3: GridWorld Classes and Interfaces
GridWorld Case Study Part 3: GridWorld Classes and Interfaces In our example programs, a grid contains actors that are instances of classes that extend the Actor class. There are two classes that implement
CMSC 202H. ArrayList, Multidimensional Arrays
CMSC 202H ArrayList, Multidimensional Arrays What s an Array List ArrayList is a class in the standard Java libraries that can hold any type of object an object that can grow and shrink while your program
Introducing Variance into the Java Programming Language DRAFT
Introducing Variance into the Java Programming Language A Quick Tutorial DRAFT Christian Plesner Hansen Peter von der Ahé Erik Ernst Mads Torgersen Gilad Bracha June 3, 2003 1 Introduction Notice: This
Generic Types in Java. Example. Another Example. Type Casting. An Aside: Autoboxing 4/16/2013 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK.
Generic Types in Java 2 GENERIC TYPES AND THE JAVA COLLECTIONS FRAMEWORK Lecture 15 CS2110 Spring 2013 When using a collection (e.g., LinkedList, HashSet, HashMap), we generally have a single type T of
CS170 Lab 11 Abstract Data Types & Objects
CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
C++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
CSE 1020 Introduction to Computer Science I A sample nal exam
1 1 (8 marks) CSE 1020 Introduction to Computer Science I A sample nal exam For each of the following pairs of objects, determine whether they are related by aggregation or inheritance. Explain your answers.
Rigorous Software Development CSCI-GA 3033-009
Rigorous Software Development CSCI-GA 3033-009 Instructor: Thomas Wies Spring 2013 Lecture 5 Disclaimer. These notes are derived from notes originally developed by Joseph Kiniry, Gary Leavens, Erik Poll,
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
Stack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A
Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
Analysis of a Search Algorithm
CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,
Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
Introduction to Programming System Design. CSCI 455x (4 Units)
Introduction to Programming System Design CSCI 455x (4 Units) Description This course covers programming in Java and C++. Topics include review of basic programming concepts such as control structures,
Lecture 9. Semantic Analysis Scoping and Symbol Table
Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax
C++FA 5.1 PRACTICE MID-TERM EXAM
C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer
1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders
Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix
Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld
LINKED DATA STRUCTURES
LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger
UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 61B Fall 2014 P. N. Hilfinger Unit Testing with JUnit 1 The Basics JUnit is a testing framework
Visualising Java Data Structures as Graphs
Visualising Java Data Structures as Graphs John Hamer Department of Computer Science University of Auckland [email protected] John Hamer, January 15, 2004 ACE 2004 Visualising Java Data Structures
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Software Engineering Techniques
Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary
Practical Session 4 Java Collections
Practical Session 4 Java Collections Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack The Collections class Wrapper classes Collection A group
Limitations of Data Encapsulation and Abstract Data Types
Limitations of Data Encapsulation and Abstract Data Types Paul L. Bergstein University of Massachusetts Dartmouth [email protected] Abstract One of the key benefits provided by object-oriented programming
7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),
Arrays Has special language support Iterators Collections in Java Iterator (i) Collections (also called containers) Collection (i) Set (i), HashSet (c), TreeSet (c) List (i), ArrayList (c), LinkedList
13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
Introduction: Abstract Data Types and Java Review
Introduction: Abstract Data Types and Java Review Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Welcome to Computer Science E-119! We will study fundamental data structures.
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
An Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
The Interface Concept
Multiple inheritance Interfaces Four often used Java interfaces Iterator Cloneable Serializable Comparable The Interface Concept OOP: The Interface Concept 1 Multiple Inheritance, Example Person name()
KITES TECHNOLOGY COURSE MODULE (C, C++, DS)
KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL
PLV Goldstein 315, Tuesdays and Thursdays, 6:00PM-7:50PM. Tuesdays and Thursdays, 4:00PM-5:30PM and 7:50PM 9:30PM at PLV G320
CRN:22430/21519 Pace University Spring 2006 CS122/504 Computer Programming II Instructor Lectures Office Hours Dr. Lixin Tao, [email protected], http://csis.pace.edu/~lixin Pleasantville Office: G320, (914)773-3449
Exception Handling. Overloaded methods Interfaces Inheritance hierarchies Constructors. OOP: Exception Handling 1
Exception Handling Error handling in general Java's exception handling mechanism The catch-or-specify priciple Checked and unchecked exceptions Exceptions impact/usage Overloaded methods Interfaces Inheritance
Chapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
MCI-Java: A Modified Java Virtual Machine Approach to Multiple Code Inheritance
This is pre-print of a paper that will appear in the Proceedings of: 3 rd Virtual Machine Research & Technology Symposium Usenix VM 4, May 6-7, 24, San Jose, alifornia. MI-Java: Modified Java Virtual Machine
C# and Other Languages
C# and Other Languages Rob Miles Department of Computer Science Why do we have lots of Programming Languages? Different developer audiences Different application areas/target platforms Graphics, AI, List
Compile-time type versus run-time type. Consider the parameter to this function:
CS107L Handout 07 Autumn 2007 November 16, 2007 Advanced Inheritance and Virtual Methods Employee.h class Employee public: Employee(const string& name, double attitude, double wage); virtual ~Employee();
Lecture Notes on Linear Search
Lecture Notes on Linear Search 15-122: Principles of Imperative Computation Frank Pfenning Lecture 5 January 29, 2013 1 Introduction One of the fundamental and recurring problems in computer science is
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Class 16: Function Parameters and Polymorphism
Class 16: Function Parameters and Polymorphism SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 16 Fall 2011 1 / 15
Chapter 3: Restricted Structures Page 1
Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both
Inside the Java Virtual Machine
CS1Bh Practical 2 Inside the Java Virtual Machine This is an individual practical exercise which requires you to submit some files electronically. A system which measures software similarity will be used
Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
JAVA - EXCEPTIONS. An exception can occur for many different reasons, below given are some scenarios where exception occurs.
http://www.tutorialspoint.com/java/java_exceptions.htm JAVA - EXCEPTIONS Copyright tutorialspoint.com An exception orexceptionalevent is a problem that arises during the execution of a program. When an
Introduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
Structural Design Patterns Used in Data Structures Implementation
Structural Design Patterns Used in Data Structures Implementation Niculescu Virginia Department of Computer Science Babeş-Bolyai University, Cluj-Napoca email address: [email protected] November,
Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions
Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment
