Objectives Understand grammar of OOP Understand equivalent Java code Discuss different implementations of classes and objects.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Object Oriented Programming
Chapter 1 Inheritance University Of Ha’il.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
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.
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
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.
INF 3110/ INF INF Oppgave 6.7 Grammar RuleSemantic Rule decl → var-list : type var-list 1 → var-list 2 ; id var-list.
Written by: Dr. JJ Shepherd
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Inner Classes. Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside another class Inner classes.
Programming Progamz pls. Importance VERY IMPORTANT.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
PrasadL145OOL1 Managing Environments An Exercise in the Design, Analysis, Specification, and Implementation of the Core of an OOP Language. Object-Oriented.
5.4.1: Implementation Method Invocation (define eval-expression (lambda (exp env) (cases expression exp... (method-app-exp (obj-exp method-name rands)
Handling Exceptions in java. Exception handling blocks try { body-code } catch (exception-classname variable-name) { handler-code }
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
Compiler Construction Dr. Noam Rinetzky and Orr Tamir School of Computer Science Tel Aviv University
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
2-Dec-15 Inner Classes By Alguien Soy. 2 Inner classes All the classes so far have been “top level” It is possible (and useful) to define a class inside.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
CS170 ygao JAVA, C4Slide 1. CS170 ygao JAVA, C4Slide 2.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Session 6 Comments on Lab 3 & Implications of Inheritance.
Comp 311 Principles of Programming Languages Lecture 4 The Scope of Variables Corky Cartwright September 3, 2008.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 3 – Extending classes.
OOP Basics Classes & Methods (c) IDMS/SQL News
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
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.
Objects and Classes Gul Agha CS 421 Spring /11/2001CS 322 Fall Characteristics of OOP Object-based  encapsulate state  provide interface.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Compiler Design Lecture 10 Semantic Analysis. int aintegers int a[2][3]array(2, array(3, integer)) int f(int, float, char) int x float x char  int Int.
Pointers and Classes.
Sixth Lecture ArrayList Abstract Class and Interface
Java and OOP Part 5 – More.
Lecture 12 Inheritance.
Interface.
Java Programming Language
CompSci 230 S Programming Techniques
5.4.1: Implementation Method Invocation
Interface.
Introduction to Java Programming
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Lecture 16 - Interfaces Professor Adams.
Unit 3 - The while Loop - Extending the Vic class - Examples
Syntax-Directed Translation
Procedures App B: SLLGEN 1.
3.4 Local Binding Recall Scheme's let: > (let ((x 5)‏ (y 6))
Chapter 1 Review: BNF Grammar for lists:
class PrintOnetoTen { public static void main(String args[]) {
An Example of Inheritance
Recursive Procedures and Scopes
Topics OOP Review Inheritance Review Abstract Classes
Inner Classes.
Topics to cover Instance variables vs. local variables.
CS100A Lect. 12, 8 Oct More About Arrays
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Inheritance and Polymorphism
Presentation transcript:

Objectives Understand grammar of OOP Understand equivalent Java code Discuss different implementations of classes and objects

Class Declarations ::={ }* a-program (class-decls body) ::= class extends { field }* { }* a-class-decl (class-name super-name field-ids method-decls) ::= method ( { }* (,) ) a-method-decl (method-name ids body)

Object Expressions ::= new ( { }* (,) ) new-object-exp (class-name rands) ::= send ( { }* (,) ) method-app-exp (obj-exp method-name rands) ::= super ( { }* (,) ) super-call-exp (method-name rands)

How do we do this in Java? class c2 extends c1Public class c2 extends c1 { field xPublic int x method initialize() set x = 1Public c2() { x = 1; } method m1 (a) +(x, a)Public int m1(int a) { return x+a; } method m2 (c) send self m1 (+(c, 4))Public int m2(int c) { return m1(c+4); } method m3 (a, b) super m1 (a, b)Public int m3(int a, int b) {return super.m1(a,b); } let o1 = new c2() inPublic static void main (String[] args) { c2 o1 = new c2(); send o1 m2 (3)o1.m2(3); }

How do we implement this? “idea” Class Declarations Program Body store class definitions access classes and objects when executing program Method Bodies Object Representation Class Representation Base code is in 5-3.scmImplementation code is in 5-4-x.scm

Interface to Classes Class Declarations elaborate-class-decls! (build repository of classes) Program Body super send new find-method-and-apply (perform send) new-object (allocate new object) object->class-name (what kind of object am I?) Method Bodies Object Representation Class Representation

Simple Implementation object is list of class-name / fields “parts” How do we implement: (elaborate-class-decls! c-decls) (object->class-name o3_rep) (find-method-and-apply ‘m1 ‘c3 o3_rep ‘(7 8)) (new-object ‘c3) Object Representation (o3) a-part c3class-name fields xz a-part c2class-name fields y a-part c1class-name fields xy Class Representation (c3) a-class-decl c3class-name super-namec2 field-ids method-decls zx a-method-decl m1method-name method-ids expmethod-body vu directly from grammar

Flatten Object Fields Object Representation (o3) a-part c3class-name fields xzyxy How do we implement: (elaborate-class-decls! c-decls) (object->class-name o3_rep) (find-method-and-apply ‘m1 ‘c3 o3_rep ‘(7 8)) (new-object ‘c3) c1c3c2 search from right Class Representation (c3) a-class-decl c3class-name super-namec2 field-ids method-decls zx a-method-decl m1method-name method-ids expmethod-body vu directly from grammar

Class Representation (c3) Flatten Class Fields Object Representation (o3) a-part c3class-name fields xzyxy c1c3c2 a-class c3class-name super-namec2 field-length5 field-ids methods zxyyx a-method method-decl super-namec2 field-ids zxyyx a-method-decl m1method-name method-ids expmethod-body vu How do we implement: (elaborate-class-decls! c-decls) (object->class-name o3_rep) (find-method-and-apply ‘m1 ‘c3 o3_rep ‘(7 8)) (new-object ‘c3) flattens class methods