15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.

Slides:



Advertisements
Similar presentations
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Advertisements

Inheritance Inheritance Reserved word protected Reserved word super
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
More Inheritance Abstract Classes Interfaces Briana B. Morrison CSE 1302C Spring 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Chapter 6 Class Hierarchies, Inheritance, and Interfaces  This is a very good chapter for us at this point in time.  We have been programming hard this.
Lecture 9 Concepts of Programming Languages
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
CMSC 341 Java Review. 08/03/2007 CMSC 341 Java Review 2 Important Java Concepts and Terminology JRE is the Java Runtime Environment and it creates a virtual.
Inheritance using Java
Polymorphism & Interfaces
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
1 Review of Java Higher Level Language Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – Selection –Flow of.
INHERITANCE, POLYMORPHISM, CLASS HIERARCHIES AND GENERICS.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
CMSC 202 Generics. Nov Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
Generics and Collections. Introduction Generics New feature of J2SE 5.0 Provide compile-time type safety Catch invalid types at compile time Generic methods.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Lists and the Collection Interface Review inheritance & collections.
Computer Science 209 Software Development Java Collections.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
11/28/2015B.Ramamurthy1 Object-Oriented Design and Java B.Ramamurthy.
8. Inheritance “Is-a” Relationship. Topics Creating Subclasses Overriding Methods Class Hierarchies Abstract Class Inheritance and GUIs The Timer Class.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
1 Review of Java Basic Concepts –Names and Reserved Words –Expressions and Precedence of Operators –Flow of Control – conditional statements –Flow of Control.
COP INTERMEDIATE JAVA Designing Classes. Class Template or blueprint for creating objects. Their definition includes the list of properties (fields)
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
COMP 121 Week 8: Generic Collections. Objectives To understand type variables and how they are used in generic programming To be able to implement and.
Coming up: Inheritance
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Inheritance & Method Overriding BCIS 3680 Enterprise Programming.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Inheritance a subclass extends the functionality of a superclass a subclass inherits all the functionality of a superclass don't reinvent the wheel – "stand.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Chapter 20 Generic Classes and Methods
A tree set Our SearchTree class is essentially a set.
Lecture 9 Concepts of Programming Languages
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Chapter 9: Polymorphism and Inheritance
A tree set Our SearchTree class is essentially a set.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Object-Oriented Programming
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
CIS 199 Final Review.
Final and Abstract Classes
Lecture 9 Concepts of Programming Languages
Presentation transcript:

15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming

User-defined Classes Default and over-loaded constructors Static/non-static attributes & methods Access modifiers (public, private, protected) Encapsulation (getters and setters) ToString, Equals, CompareTo, HashCode methods Overloaded methods (same name, diff. parameters) Declaring and instantiating objects (new, superclass Object)

Package Is a collection of related classes that can be imported into projects Allows reusing classes in multiple projects without physically storing them in a project’s source code E.g.: java.io.*, java.util.*

Objected-Oriented Programming Concepts

Inheritance Organizes related classes in a hierarchy allowing reusability extensibility of common code Subclasses extend the functionality of a superclass Subclasses inherit all the methods of the superclass (excluding constructors and privates) Subclasses can override methods from the superclass Subclass declaration: accessModifier class subclassName extends superclassName

Polymorphism A concept which simplifies the processing of objects in the same hierarchy Allows to use the same method call for different objects that implement the method in the hierarchy

Abstract A class that is not completely implemented. Contains one or more abstract methods (methods with no bodies; only signatures) that subclasses must implement Can not be used to instantiate objects Abstract class header: accessModifier abstract class className Abstract method signature: accessModifier abstract returnType methodName ( args ); Subclass signature: accessModifier class subclassName extends className

Interface A special abstract class in which all the methods are abstract Contains only abstract methods that subclasses must implement Interface header: accessModifier interface interName Abstract method signature: accessModifier abstract returnType methodName ( args ); Subclass signature: accessModifier class subclassName implements interName1, interName2,..

Java Generic Collections

Generic Collections Classes that represent data-structures Generic or parameterized since the elements’ data-type is given as a parameter* E.g.: LinkedList, Queue, ArrayList, HashMap, Tree Provide methods for: Iteration Bulk operations Conversion to/from arrays *The data-type passed as parameter to a collection’s constructor can not be of the type Object, the unknown type ?, or a primitive data- type. The data-type must be a Class.

ArrayList Class Is a subclass of Collection Implements a resizable array Provides methods for array manipulation Generic or parameterized Declaration and Instantiation: ArrayList arrayListName = New ArrayList ();

ArrayList Methods Add, Get, Set, Clear, Remove, Size, IsEmpty, Contains, IndexOf, LastIndexOf, AsList etc. Basic Iterator: for (int i = 0; i < arrayListName.size(); i++) { // Get object at index i ClassName obj = arrayListName.get(i) // Process obj } Advanced Iterator: for (ClassName obj : arrayListName) { // Process obj } Iterator Object

Generic Methods Generic or parameterized methods receive the data-type of elements as a parameter E.g.: a generic method for sorting elements in an array (be it Integers, Doubles, Objects etc.)

Why Generic Methods? Consider writing a method that takes an array of objects, a collection, and puts all objects in the array into the collection Generic Method

Why Generic Methods? (contd.) Consider writing a print method that takes arrays of any data-type

Generic Classes Provide a means for describing a class in a type-independent manner

Generic Classes with Wildcards Wildcards denote “unknown” or “any’ type (resembles ) Wildcards can restrict the data-type to a particular hierarchy