Introflection. Dave Landers BEA Systems, Inc.

Size: px
Start display at page:

Download "Introflection. Dave Landers BEA Systems, Inc."

Transcription

1 Introflection Dave Landers BEA Systems, Inc.

2 Agenda What is Introflection? Primary Classes and Objects Loading Classes Creating Objects Invoking Methods Java Beans Proxy

3 What is Introflection? Reflection plus Introspection Public Domain form of Skintroflection ejskin Product Launch at Colorado Software Summit 2000

4 Reflection Dynamic discovery of information about a Class Fields Methods Constructors Interfaces and Superclasses Use of this information Construct classes Invoke Methods Set Fields Dynamic Proxy

5 Introspection Gather information about a Java Bean Properties Events Methods Uses Bean s BeanInfo class, if available Otherwise uses Reflection and applies Design Patterns

6 Factory Example Uses of Reflection Construct objects not known at compile time Specified thru properties, command line, etc. Method Interception Testing, debugging, logging What is that system doing with this class? Add behavior when you can t subclass, etc. Discover capabilities of objects and classes Code Inspection Testing and analysis tools Code generation tools

7 When NOT to Use Reflection When an Interface will do the job If you can capture the API in an Interface, then do it When a design pattern or API exists Look at existing patterns to see if the problem has been solved

8 Reflection Classes java.lang.class java.lang.reflect.method java.lang.reflect.constructor java.lang.reflect.field java.lang.reflect.modifier java.lang.reflect.array java.lang.reflect.proxy java.lang.reflect.invocationhandler

9 java.lang.class Represents a class Starting point for all reflection operations Gives you information about the class Name, Package Interfaces, Superclasses Methods, Fields, Constructors Protection and Modifiers Abstract, Interface, or Concrete Can instantiate objects

10 Class Instances How do you get a Class instance? Dynamically load a Class By name Reference a Class by Name Using the class keyword Get the Class for an Object getclass()

11 Dynamic Class Loading Class.forName(String classname) Class c = Class.forName("java.lang.String"); Use the full class name (with package) Loads and initializes the class No compiler check on the class name Careful of errors in the name string No need to know the class name until runtime

12 Exceptions - Class.forName() ClassNotFoundException If the class can not be loaded LinkageError Incompatible change in dependant class ExceptionInInitializerError Static initializer threw exception

13 The class keyword Class c = String.class; More convenient than Class.forName() If you know the class name at compile time Compiler verifies that class exists Does not throw checked exceptions Unless class becomes unavailable at runtime Generates synthetic methods and fields Uses Class.forName() internally Except for primitives (int.class Integer.TYPE)

14 Get the Class for an Object anobject.getclass() Returns the runtime type of the object instance Not the declared type Example Object foo = new String( ); foo has declared type Object The instance of foo is a String foo.getclass() will return String.class

15 Object.getClass() Better than MyClass.class if you have an object of the right type No need to bother the ClassLoader The class is already loaded and the Object knows its type Use.getClass() rather than String.class No generated synthetic methods Remember, they use Class.forName() internally Careful of declared vs. runtime types

16 Class and Arrays Class[] is NOT the same as the Class object for an array Use class keyword just as with other types int[][].class not int.class[][] Building array classes with Class.forName() is weird Same weird name is output by getname [Ljava.lang.Object; not java.lang.object[] Try Array.newInstance(Foo.class,0).getClass()

17 Object Creation aclass.newinstance() Returns a new object instance for the Class Uses default constructor Class c = Class.forName( FooImpl ); Foo thefoo = (Foo) c.newinstance(); Same as Foo thefoo = new FooImpl();

18 Class.newInstance() Exceptions These would be checked by the compiler if we were not doing reflection... InstantiationException Can not instantiate - abstract, primitive, etc. No default constructor IllegalAccessException Class was not public, etc. ExeptionInInitializerError Static initialization failed

19 And Class.newInstance() Exceptions Throws whatever the constructor throws Even checked Exceptions! But wait? Class.newInstance() only declares InstantiationException, IllegalAccessException See example ExceptionTest

20 Exceptions - Class.newInstance() Java Language Spec, First Edition, Section : If evaluation of [the equivalent] class instance creation expression would complete abruptly, then the call to the newinstance method will complete abruptly for the same reason. No mention in JLS-2

21 Try This try { myclass.newinstance(); } catch (MyException e) { } Won t compile Compiler will not let you catch undeclared exception Should usually catch a generic Throwable Use instanceof to check for known types

22 Constructors with Arguments java.lang.reflect.constructor Mostly like Method We ll look at Method later Has newinstance() method vs. Method s invoke aclass.getconstructor(class[] params) aclass.getconstructors() aclass.getdeclaredconstructor(...) aclass.getdeclaredconstructors()

23 Exceptions Constructor.newInstance() InstantiationException IllegalAccessException ExceptionInInitializerError IllegalArgumetException Arguments don t match InvocationTargetException If the Constructor throws anything gettargetexception() To retrieve the original Throwable

24 Code Break ThingFactory Returns an implementation of a Thing Based on System Property This is a common pattern Other common Factory sensors Operating System GUI or Command Line or Server mode Thread state or Application Status Configuration objects

25 java.lang.reflect.method Access information about a method Protection and Modifiers public, private, static, synchronized, etc. Declaring class Parameters Exceptions Return type Can invoke methods Method.invoke()

26 Get a Method from Class aclass.getmethod( String name, Class[] argtypes ) Get a particular public method Looks in this class and all super-classes Parameters must be exactly as declared public void foo(number num); Will not be found with getmethod("foo", new Class[] { Integer.class } ); Even though Integer extends Number

27 Other Method methods aclass.getmethods() Gets array of all public methods in this class and all superclasses aclass.getdeclaredmethod(...) aclass.getdeclaredmethods() Any method (not just public) Only those that are declared in the class No inherited methods Use aclass.getsuperclass()

28 Method Invocation amethod.invoke( Object obj, Object[] args ) Invoke a method on obj Like obj.method(args[0], args[1], ); obj must be instance of declaring Class of method Use null for static methods args are the method s parameters Must match method s parameter types Primitives should be wrapped Example: use Integer if method takes int Cast return to the method s return type Primitive return types will be wrapped

29 Method Invocation Exceptions getmethod() NoSuchMethodException There is no method with that signature invoke() IllegalAccessException Method was private, etc. IllegalArgumentException Arguments don t match parameters InvocationTargetException The method threw an exception Use gettargetexception() to get the original exception

30 Code Break AutoConfiguration Abstract base class Automatically set up a Configuration object from System Properties Automatically maps set methods to corresponding properties in subclasses MyConfiguration extends AutoConfiguration Concept can be applied to Servlets, Applets, GUIs, etc.

31 Code Break? ActionDispatcher Implements ActionListener Gets ActionCommand from event Uses that as a method name Executes method in response to the action DispatchExample.java Creates some buttons Sets ActionCommand to method name

32 Introspection Java Beans Introspector BeanInfo

33 Java Beans Bean properties and events match Design Pattern getfoo() & setfoo() Property named foo Introspector figures this out

34 java.beans.introspector Retrieve BeanInfo for a Java Bean Or any class that follows Java Beans Design Pattern Introspector.getBeanInfo() BeanInfo Information on Properties Methods Events More

35 Introspector Uses BeanInfo class if available Bean named Foo might have FooBeanInfo in some package in bean info search path Introspector uses this if available Skips reflection BeanInfo can be used for Tricks Remapping properties, methods to different names Can set getfoo() and setbar() for property baz

36 BeanInfo abeaninfo.getpropertydescriptors() PropertyDescriptor getname() getpropertytype() getreadmethod getwritemethod() getbeandescriptor() getmethoddescriptors() geteventsetdescriptors()

37 Code Break AutoConfiguration implementation using Introspector BeanInfo example

38 Dynamic Proxy Proxies Delegation Method Interception Wrapping classes with extra implementation Aspect Oriented Programming Dynamic Implementations

39 Proxy Proxy & InvocationHandler New in JDK 1.3 Generates classes That implement your interface(s) At runtime Actually feeds bytecodes to a ClassLoader Cool! All methods on the interfaces call InvocationHandler.invoke() You write this

40 Proxy Proxy.newProxyInstance( ClassLoader classloader, Class[] interfaces, InvocationHandler handler ) There are other ways to create a Proxy, but this is the simplest Returns an object that implements all interfaces Can be cast to any of those interfaces

41 InvocationHandler public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable proxy The object on which the method was called method The method that was called args The arguments that were passed Returns whatever the method should return Throws whatever exception the method throws

42 Code Break LoggingProxy Wrap it around any object that implements an interface and all method calls are logged Example what are they doing with my database? Connection c = (Connection) LoggingProxy.newProxyInstance( myconn ); they.setconnection( c );

43 Code Break Magic Bean Magic interface implementer Knows about get/set methods Only need to provide partial implementation of some methods Great idea for configuration objects Repetitive get/set implementations are boring Magic implementation could be extended with Persistence and Initialization File, Database, JMX, etc.

44 Conclusion Introflection is a powerful tool But Skintroflection is better Innovation Without Effort principals Dynamic Class and Object creation Method Invocation Proxies Use in conjunction with Interfaces Design Patterns OO practices Watch out for those Exceptions

45 References The Java Language Specification Reflection and Proxy Overview Installed JDK: docs/guide/reflection/index.html Reflection Tutorial

46 References JavaBeans Spec JavaBeans Docs Installed JDK: docs/guide/beans/index.html JavaBeans Tutorial

47 References ejskin Colorado Software Summit 2000 CD-ROM

48 Thank You Please fill out the Evaluations Examples On the CD Can t wait? Reflection Beyond the Class class (CSS, 1999)

Lecture 9 : Basics of Reflection in Java

Lecture 9 : Basics of Reflection in Java Lecture 9 : Basics of Reflection in Java LSINF 2335 Programming Paradigms Prof. Kim Mens UCL / EPL / INGI (Slides partly based on the book Java Reflection in Action, on The Java Tutorials, and on slides

More information

Introduction to Reflection

Introduction to Reflection Introduction to Reflection Mark Allen Weiss Copyright 2000 1 What is Reflection The Class class Outline of Topics Run Time Type Identification (RTTI) Getting Class Information Accessing an arbitrary object

More information

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: reflection

Chair of Software Engineering. Java and C# in depth. Carlo A. Furia, Marco Piccioni, Bertrand Meyer. Java: reflection Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: reflection Outline Introductory detour: quines Basic reflection Built-in features Introspection Reflective method invocation

More information

JAVA. Reflection API. Java, summer semester

JAVA. Reflection API. Java, summer semester JAVA Reflection API 26.2.2013 1 Overview Reflection changes structure/state of objects Introspection exploring a structure of objects similar to RTTI in C++ but more powerful allows obtaining information

More information

Reflection. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 28

Reflection. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 28 Reflection Computer Science and Engineering College of Engineering The Ohio State University Lecture 28 Motivating Problem Debugger/visualization tool Takes an object, any object Displays the methods one

More information

CS5233 Components Models and Engineering

CS5233 Components Models and Engineering CS5233 Components Models and Engineering (Komponententechnologien) Master of Science (Informatik) Reflection Seite 1 Java Reflection Reflection Reflection is when you see yourself. Why would you like to

More information

Advanced programming for Java platform. Introduction

Advanced programming for Java platform. Introduction Advanced programming for Java platform Introduction About course Petr Hnětynka hnetynka@d3s.mff.cuni.cz http://d3s.mff.cuni.cz/teaching/vsjava/ continuation of "Java (NPRG013)" basic knowledge of Java

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J3

EPITA Première Année Cycle Ingénieur. Atelier Java - J3 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 Imagination From 2 Plan 1 Imagination From Plan 1 Imagination From What is Reflection is the process

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J3

EPITA Première Année Cycle Ingénieur. Atelier Java - J3 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 Imagination From? Architecture of Reflexivity in Java 2 Find Methods With Annotations Imagination From?

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J3

EPITA Première Année Cycle Ingénieur. Atelier Java - J3 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 Imagination From? Architecture of Reflexivity in Java 2 Find Methods With Annotations Imagination From?

More information

Software-Architecture Annotations, Reflection and Frameworks

Software-Architecture Annotations, Reflection and Frameworks Software-Architecture Annotations, Reflection and Frameworks Prof. Dr. Axel Böttcher 3. Oktober 2011 Objectives (Lernziele) Understand the Java feature Annotation Implement a simple annotation class Know

More information

Reflection (in fact, Java introspection)

Reflection (in fact, Java introspection) Reflection (in fact, Java introspection) Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team Elevator speech So programs are programs and data is data. However, programs can be represented

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages! Reflection Dr. Hyunyoung Lee! 1 Reflection and Metaprogramming Metaprogramming: Writing (meta)programs that represent and manipulate other programs Reflection: Writing (meta)programs

More information

Ira R. Forman Nate Forman

Ira R. Forman Nate Forman Ira R. Forman Nate Forman M A N N I N G Java Reflection in Action by Ira R. Forman and Nate Forman Sample Chapter 1 Copyright 2004 Manning Publications contents Chapter 1 A few basics Chapter 2 Accessing

More information

Concepts of Object-Oriented Programming Peter Müller

Concepts of Object-Oriented Programming Peter Müller Concepts of Object-Oriented Programming Peter Müller Chair of Programming Methodology Autumn Semester 2017 1.2 Introduction Core Concepts 2 Meeting the Requirements Cooperating Program Parts with Well-Defined

More information

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Java Reflection

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Java Reflection CSCE 314 TAMU Fall 2017 1 CSCE 314: Programming Languages Dr. Flemming Andersen Java Reflection CSCE 314 TAMU Fall 2017 Reflection and Metaprogramming Metaprogramming: Writing (meta)programs that represent

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. 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 information

INTROSPECTION. We need to begin with a more basic concept called type introspection

INTROSPECTION. We need to begin with a more basic concept called type introspection REFLECTION 1 INTROSPECTION We need to begin with a more basic concept called type introspection The ability of a program to examine the type and properties of an object at runtime A few programming languages

More information

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code

Java Security. Compiler. Compiler. Hardware. Interpreter. The virtual machine principle: Abstract Machine Code. Source Code Java Security The virtual machine principle: Source Code Compiler Abstract Machine Code Abstract Machine Code Compiler Concrete Machine Code Input Hardware Input Interpreter Output 236 Java programs: definitions

More information

Class, Variable, Constructor, Object, Method Questions

Class, Variable, Constructor, Object, Method Questions Class, Variable, Constructor, Object, Method Questions http://www.wideskills.com/java-interview-questions/java-classes-andobjects-interview-questions https://www.careerride.com/java-objects-classes-methods.aspx

More information

Java reflection. alberto ferrari university of parma

Java reflection. alberto ferrari university of parma Java reflection alberto ferrari university of parma reflection metaprogramming is a programming technique in which computer programs have the ability to treat programs as their data a program can be designed

More information

LINGI2252 PROF. KIM MENS REFLECTION (IN JAVA)*

LINGI2252 PROF. KIM MENS REFLECTION (IN JAVA)* LINGI2252 PROF. KIM MENS REFLECTION (IN JAVA)* * These slides are part of the course LINGI2252 Software Maintenance and Evolution, given by Prof. Kim Mens at UCL, Belgium Lecture 10 a Basics of Reflection

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs. Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP 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 information

Programming Language Concepts: Lecture 10

Programming Language Concepts: Lecture 10 Programming Language Concepts: Lecture 10 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 10, 16 February 2009 Reflection

More information

Introduction to Programming Using Java (98-388)

Introduction 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 information

A Static Alternative To Java Dynamic Proxies

A Static Alternative To Java Dynamic Proxies A Static Alternative To Java Dynamic Proxies Abstract The Proxy design pattern is often used in applications, but induces generally an implementation overhead. To simplify the developer work, the Java

More information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

Background. Reflection. The Class Class. How Objects Work

Background. Reflection. The Class Class. How Objects Work Background Reflection Turing's great insight: programs are just another kind of data Source code is text Manipulate it line by line, or by parsing expressions Compiled programs are data, too Integers and

More information

Programming by Delegation

Programming by Delegation Chapter 2 a Programming by Delegation I. Scott MacKenzie a These slides are mostly based on the course text: Java by abstraction: A client-view approach (4 th edition), H. Roumani (2015). 1 Topics What

More information

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE

More information

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 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

More information

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August Polymorphism, Dynamic Binding and Interface 2 4 pm Thursday 7/31/2008 @JD2211 1 Announcement Next week is off The class will continue on Tuesday, 12 th August 2 Agenda Review Inheritance Abstract Array

More information

Cours / TP. Tutorial to Java Reflection API. Class / ClassLoader / Field-Method Introspection.

Cours / TP. Tutorial to Java Reflection API. Class / ClassLoader / Field-Method Introspection. Cours / TP Tutorial to Java Reflection API Class / ClassLoader / Field-Method Introspection Arnaud.nauwynck@gmail.com This document: http://arnaud.nauwynck.chez-alice.fr/ Intro-JavaIntrospection.pdf Outline

More information

Polymorphism. return a.doublevalue() + b.doublevalue();

Polymorphism. return a.doublevalue() + b.doublevalue(); Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces

More information

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance? CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look

More information

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

(800) Toll Free (804) Fax   Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented

More information

What is Inheritance?

What is Inheritance? Inheritance 1 Agenda What is and Why Inheritance? How to derive a sub-class? Object class Constructor calling chain super keyword Overriding methods (most important) Hiding methods Hiding fields Type casting

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

EPITA Première Année Cycle Ingénieur. Atelier Java - J3

EPITA Première Année Cycle Ingénieur. Atelier Java - J3 EPITA Première Année Cycle Ingénieur marwan.burelle@lse.epita.fr http://www.lse.epita.fr Overview 1 Imagination From? Getting Class Architecture of Reflexivity in Java 2 ClassSpy Breaking Circularity 3

More information

Material Java type system Reflection

Material Java type system Reflection CS1706 Intro to Object Oriented Dev II -Fall 04 Announcements Week 15 Final Exam: Tues. Dec. 14 @ 3:25pm Material Java type system Reflection Java Type System Type System is a set of values and the operations

More information

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt. Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Summer Semester 2015 Proxy Pattern From the client s point of view, the proxy

More information

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000 The Object Class Mark Allen Weiss Copyright 2000 1/4/02 1 java.lang.object All classes either extend Object directly or indirectly. Makes it easier to write generic algorithms and data structures Makes

More information

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : An interface defines the list of fields

More information

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE COURSE NAME: OBJECT ORIENTED PROGRAMMING COURSE CODE: OOP521S NQF LEVEL: 6 DATE: NOVEMBER 2015 DURATION: 2 HOURS

More information

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java

More information

RTTI and Reflection. Run-Time Type Information. Overview. David Talby. Advantages of Static Typing. Typing. Advantages II.

RTTI and Reflection. Run-Time Type Information. Overview. David Talby. Advantages of Static Typing. Typing. Advantages II. RTTI and Reflection David Talby Overview Static typing Run-Time Type Information in C++ Reflection in Java Dynamic Proxies in Java Syntax, uses and misuses for each Typing Static Typing, or Strong Typing:

More information

Selected Java Topics

Selected Java Topics Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings

More information

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt. Summer Term 2018 1 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Proxy Pattern 2 From the client s point of view, the proxy

More information

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt.

Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt. Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Winter Semester 16/17 Proxy Pattern From the client s point of view, the proxy

More information

Architecture of so-ware systems

Architecture of so-ware systems Architecture of so-ware systems Lecture 13: Class/object ini

More information

OOP Reflection. Kasper Østerbye Mette Jaquet Carsten Schuermann. IT University Copenhagen

OOP Reflection. Kasper Østerbye Mette Jaquet Carsten Schuermann. IT University Copenhagen OOP Reflection Kasper Østerbye Mette Jaquet Carsten Schuermann IT University Copenhagen 1 Today's schedule Reflection modelling a domain vs. modelling objects Testing Example: Checking that all fields

More information

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level CSE1720 Click to edit Master Week text 08, styles Lecture 13 Second level Third level Fourth level Fifth level Winter 2014! Thursday, Feb 27, 2014 1 General Info Continuation of Chapter 9 Read Chapter

More information

DESIGN PATTERN - INTERVIEW QUESTIONS

DESIGN PATTERN - INTERVIEW QUESTIONS DESIGN PATTERN - INTERVIEW QUESTIONS http://www.tutorialspoint.com/design_pattern/design_pattern_interview_questions.htm Copyright tutorialspoint.com Dear readers, these Design Pattern Interview Questions

More information

Advanced Java Programming

Advanced Java Programming Advanced Java Programming Length: 4 days Description: This course presents several advanced topics of the Java programming language, including Servlets, Object Serialization and Enterprise JavaBeans. In

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

Chapter 14 Abstract Classes and Interfaces

Chapter 14 Abstract Classes and Interfaces Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden

More information

Dynamic Class Loading

Dynamic Class Loading Dynamic Class Loading Philippe Collet Partially based on notes from Michel Buffa Master 1 IFI Interna,onal 2012-2013 h4p://dep,nfo.unice.fr/twiki/bin/view/minfo/soceng1213 P. Collet 1 Agenda Principle

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

COE318 Lecture Notes Week 10 (Nov 7, 2011)

COE318 Lecture Notes Week 10 (Nov 7, 2011) COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:

More information

Compaq Interview Questions And Answers

Compaq Interview Questions And Answers Part A: Q1. What are the difference between java and C++? Java adopts byte code whereas C++ does not C++ supports destructor whereas java does not support. Multiple inheritance possible in C++ but not

More information

So, What is an Aspect?

So, What is an Aspect? Introduction to AspectJ Aspect-oriented paradigm AspectJ constructs Types of Join Points Primitive Lexical designators Type designators Control flow Types of Advice Before After Around Receptions Join

More information

Definition of DJ (Diminished Java)

Definition of DJ (Diminished Java) Definition of DJ (Diminished Java) version 0.5 Jay Ligatti 1 Introduction DJ is a small programming language similar to Java. DJ has been designed to try to satisfy two opposing goals: 1. DJ is a complete

More information

developer.* The Independent Magazine for Software Professionals Factory Chain: A Design Pattern for Factories with Generics by Hugo Troche

developer.* The Independent Magazine for Software Professionals Factory Chain: A Design Pattern for Factories with Generics by Hugo Troche developer.* The Independent Magazine for Software Professionals Factory Chain: A Design Pattern for Factories with Generics by Hugo Troche Introduction The recent Java 5 (a.k.a. Java 1.5) generics implementation

More information

interface MyAnno interface str( ) val( )

interface MyAnno interface str( ) val( ) Unit 4 Annotations: basics of annotation-the Annotated element Interface. Using Default Values, Marker Annotations. Single-Member Annotations. The Built-In Annotations-Some Restrictions. 1 annotation Since

More information

Brief Summary of Java

Brief Summary of Java Brief Summary of Java Java programs are compiled into an intermediate format, known as bytecode, and then run through an interpreter that executes in a Java Virtual Machine (JVM). The basic syntax of Java

More information

Java Class Loading and Bytecode Verification

Java Class Loading and Bytecode Verification Java Class Loading and Bytecode Verification Every object is a member of some class. The Class class: its members are the (definitions of) various classes that the JVM knows about. The classes can be dynamically

More information

Java: introduction to object-oriented features

Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java: introduction to object-oriented features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

More information

C a; C b; C e; int c;

C a; C b; C e; int c; CS1130 section 3, Spring 2012: About the Test 1 Purpose of test The purpose of this test is to check your knowledge of OO as implemented in Java. There is nothing innovative, no deep problem solving, no

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception Ariel Shamir 1 Run-time Errors Sometimes when the computer

More information

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Java for Programmers Course (equivalent to SL 275) 36 Contact Hours Course Overview This course teaches programmers the skills necessary to create Java programming system applications and satisfies the

More information

COMP 401 FACTORIES. Instructor: Prasun Dewan

COMP 401 FACTORIES. Instructor: Prasun Dewan COMP 401 FACTORIES Instructor: Prasun Dewan NEW CONCEPTS Factory Classes Static Factory Methods Indirection Binding Time Reading Files Static Blocks Reflection Multi-Exception Catch Block Abstract Factories

More information

WA1278 Introduction to Java Using Eclipse

WA1278 Introduction to Java Using Eclipse Lincoln Land Community College Capital City Training Center 130 West Mason Springfield, IL 62702 217-782-7436 www.llcc.edu/cctc WA1278 Introduction to Java Using Eclipse This course introduces the Java

More information

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception 22 November 2007 Ariel Shamir 1 Run-time Errors Sometimes

More information

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages References Exceptions "Handling Errors with Exceptions", Java tutorial http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html CSE 413, Autumn 2005 Programming Languages http://www.cs.washington.edu/education/courses/413/05au/

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

public static boolean isoutside(int min, int max, int value)

public static boolean isoutside(int min, int max, int value) See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static

More information

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Atelier Java - J1. Marwan Burelle.  EPITA Première Année Cycle Ingénieur. marwan.burelle@lse.epita.fr http://wiki-prog.kh405.net Plan 1 2 Plan 3 4 Plan 1 2 3 4 A Bit of History JAVA was created in 1991 by James Gosling of SUN. The first public implementation (v1.0) in 1995.

More information

type conversion polymorphism (intro only) Class class

type conversion polymorphism (intro only) Class class COMP 250 Lecture 33 type conversion polymorphism (intro only) Class class Nov. 24, 2017 1 Primitive Type Conversion double float long int short char byte boolean non-integers integers In COMP 273, you

More information

CS506 Web Design & Development Final Term Solved MCQs with Reference

CS506 Web Design & Development Final Term Solved MCQs with Reference with Reference I am student in MCS (Virtual University of Pakistan). All the MCQs are solved by me. I followed the Moaaz pattern in Writing and Layout this document. Because many students are familiar

More information

COE318 Lecture Notes Week 8 (Oct 24, 2011)

COE318 Lecture Notes Week 8 (Oct 24, 2011) COE318 Software Systems Lecture Notes: Week 8 1 of 17 COE318 Lecture Notes Week 8 (Oct 24, 2011) Topics == vs..equals(...): A first look Casting Inheritance, interfaces, etc Introduction to Juni (unit

More information

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Modern Programming Languages. Lecture Java Programming Language. An Introduction Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

Exceptions. Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Exceptions. Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology Exceptions Algorithms Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Exceptions ± Definition

More information

Java Overview An introduction to the Java Programming Language

Java Overview An introduction to the Java Programming Language Java Overview 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 information

CS260 Intro to Java & Android 03.Java Language Basics

CS260 Intro to Java & Android 03.Java Language Basics 03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance

More information

Java Object Model. Or, way down the rabbit hole

Java Object Model. Or, way down the rabbit hole Java Object Model Or, way down the rabbit hole 1 Type Definition: a set of values and a set of operations that can be applied to those values Java is a strongly-typed language: compiler & runtime system

More information

Page 1

Page 1 Java 1. Core java a. Core Java Programming Introduction of Java Introduction to Java; features of Java Comparison with C and C++ Download and install JDK/JRE (Environment variables set up) The JDK Directory

More information

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points.

Java for Non Majors. Final Study Guide. April 26, You will have an opportunity to earn 20 extra credit points. Java for Non Majors Final Study Guide April 26, 2017 The test consists of 1. Multiple choice questions 2. Given code, find the output 3. Code writing questions 4. Code debugging question 5. Short answer

More information

Today. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at Interfaces.

Today. Book-keeping. Inheritance. Subscribe to sipb-iap-java-students. Slides and code at  Interfaces. Today Book-keeping Inheritance Subscribe to sipb-iap-java-students Interfaces Slides and code at http://sipb.mit.edu/iap/java/ The Object class Problem set 1 released 1 2 So far... Inheritance Basic objects,

More information

Comp215: Thinking Generically

Comp215: Thinking Generically Comp215: Thinking Generically Dan S. Wallach (Rice University) Copyright 2015, Dan S. Wallach. All rights reserved. Functional APIs On Wednesday, we built a list of Objects. This works. But it sucks. class

More information

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar Exceptions Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and Classes CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

CS 251 Intermediate Programming Methods and More

CS 251 Intermediate Programming Methods and More CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with

More information

6.Introducing Classes 9. Exceptions

6.Introducing Classes 9. Exceptions 6.Introducing Classes 9. Exceptions Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Learning

More information

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP 2013 Empowering Innovation DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP contact@dninfotech.com www.dninfotech.com 1 JAVA 500: Core JAVA Java Programming Overview Applications Compiler Class Libraries

More information

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107

Index. Index. More information. block statements 66 y 107 Boolean 107 break 55, 68 built-in types 107 A abbreviations 17 abstract class 105 abstract data types 105 abstract method 105 abstract types 105 abstraction 92, 105 access level 37 package 114 private 115 protected 115 public 115 accessors 24, 105

More information