Architecture (simplified view) method object Reflection plane Object plane Class object Method object.

Slides:



Advertisements
Similar presentations
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.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
New features in JDK 1.5 Can these new and complex features simplify Java development?
L3:CSC © Dr. Basheer M. Nasef Lecture #3 By Dr. Basheer M. Nasef.
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.
Reflection Reflection is the ability of a program to examine and modify the structure and behavior of an object at runtime.
Slide 11.1 Advanced Programming 2004, based on LY Stefanus’s Slides Reflection Reflection is the ability for a class or object to examine itself. Java.
Road Map Introduction to object oriented programming. Classes
Classes and Methods Write a class called C1 containing: A static variable SV of type int. A static method SM with one parameter, of type C1, and a void.
Unit 211 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
03G-1 Reflection In Java For every loaded class, the Java Runtime Environment (JRE) maintains an associated Class object The Class object “ reflects ”
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
13-Jul-15 Reflection. 2 Java looking at Java One of the unusual capabilities of Java is that a program can examine itself You can determine the class.
Generic Subroutines and Exceptions CS351 – Programming Paradigms.
SEG4110 – Advanced Software Design and Reengineering TOPIC H Java Reflection.
Java Reflection. Compile-Time vs Run-Time Some data you know at compile time: int area = radius*radius*3.14; The “3.14” is set – known at compile time.
Object Oriented Programming in Java Lecture 13. Java Reflection Reflection is a feature unique to Java that allows an executing program to examine or.
The Reflection Lucielle Mendez Antonio Bologna.
CS 2430 Day 26. Announcements Exam #2: Wednesday, April 3 –Review in lab on Tuesday, April 2 –Sample problems sent via .
Java the UML Way versjon Only to be used in connection with the book "Java the UML Way", by Else Lervik and.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
In the name of Allah The Proxy Pattern Elham moazzen.
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
Case study Students. Array of objects Arrays can hold objects (ref to objects!) Each cell in an array of objects is null by default Sample: from student.
© Keren Kalif Advanced Java Topics Written by Keren Kalif, Edited by Liron Blecher.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Introduction to Generics
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Module 8: Delegates and Events. Overview Delegates Multicast Delegates Events When to Use Delegates, Events, and Interfaces.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
Static. 2 Objectives Introduce static keyword –examine syntax –describe common uses.
Parametric Polymorphism and Java Generics. Announcements One day extension on HW5 Because of an error in my HW5 config HW6 out, due November 10 Grades.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 1 ArrayLists Section 9.9.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
ITI Introduction to Computing II Lab-5 Dewan Tanvir Ahmed University of Ottawa.
.NET Mobile Application Development XML Web Services.
IAP C# 2011 Lecture 2: Delegates, Lambdas, LINQ Geza Kovacs.
Support standard JavaScript code with static typing Encapsulation through classes and modules Support for constructors, properties and.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Networking with JavaN-1 Outline Client-Server Example Steps required on the server side Steps required on the client side.
Classes - Intermediate
03G-1 Reflection In Java “Reflection is the ability of a program to manipulate as data something representing the state of the program during its own execution.”
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Topics Instance variables, set and get methods Encapsulation
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
Netprog Java RMI1 Remote Method Invocation.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Summary prepared by Kirk Scott
Java and OOP Part 5 – More.
using System; namespace Demo01 { class Program
2.7 Inheritance Types of inheritance
Intro To Classes Review
CSE 413, Autumn 2002 Programming Languages
EE 422C Java Reflection re·flec·tion rəˈflekSH(ə)n/ noun
Lecture 4: RPC Remote Procedure Call Coulouris et al: Chapter 5
Sampath Kumar S Assistant Professor, SECE
Classes & Objects: Examples
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Java Lesson 36 Mr. Kalmes.
JAVA Constructors.
CIS 199 Final Review.
Corresponds with Chapter 5
Presentation transcript:

Architecture (simplified view) method object Reflection plane Object plane Class object Method object

Architecture

Retrieving Class Objects Object.getClass() –From an instance of the object The.class Syntax –No instance available, but type is known Class.forName() –Full name of the class

Inspecting a class Methods Fields Constructors Modifiers Generic type parameters Implemented interfaces …

LAB - 1 TestReflection (from the site)

LAB Calling a remote method in a generic way The client sends to the server –Remote Object ID (integer) –Remote method name (string) –Parameters type (array of Class objects) –Parameter values Server –retrieve remote object from ID –Get a reflecting method class –Receive parameters –Invoke the method

Client public class ClientRefl { public static void main (String args[]) { DatagramSocket aSocket = null; try { aSocket = new DatagramSocket(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(byteStream);

Client os.writeObject(0); //remote ID os.writeObject("concat"); //method name os.writeObject(new Class[] {String.class}); //types os.writeObject(OK! "); //Parameter os.close(); Client Server !! OK! | String.class | concat | 0

Server //Boilerplate code for receiving the message Object [] OT = new Object[1]; OT[0]="OGGETTO REMOTO "; Integer obj_id= (Integer)is.readObject(); //leggo ID oggetto Object obj = OT[(int)obj_id]; Class c = obj.getClass(); //acquisisco classe oggetto... Client Server OK! | String.class | concat | 0

Server String methodName = (String)is.readObject(); // concat Class [] parameterTypes = (Class [])is.readObject(); //array di Class List arguments = new ArrayList (); arguments.add(is.readObject()); //or loop according to size of parameterTypes is.close(); Client Server OK! | String.class | concat | 0

Server (calling the method) Objcet result = null; Method m; try { //m reflects the concat method… m = c.getMethod(methodName, parameterTypes); result = m.invoke(obj, arguments.toArray()); …

LAB: study ClassDeclarationSpy ClassSpy