The document discusses Java reflection and its key concepts. Reflection allows a running program to examine itself and its environment. It enables programs to inspect their own structure, behavior, and configuration. The core reflection API includes classes like Class, Method, Constructor, and Field that allow introspecting classes at runtime. Reflection is commonly used for tasks like dependency injection, dynamic proxy generation, and structural analysis of programs.
After a previous introductory lecture on the basics of reflection in Java, in this lecture we take a closer look at some more advanced reflective features of the language such as dynamic proxies, call stack introspection and instrumentation. This lecture is part of a full course on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme.
An introduction to the basics of reflection in the object-oriented programming language Java, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme.
The concept of Java Reflection API has been discussed here in the presentation. Some code snippets have also been introduces to illustrate the different interfaces and use cases.
http://bd.linkedin.com/in/imranhasanhira
https://www.facebook.com/KonaSoftware
https://www.linkedin.com/company/kona-software-lab-ltd-
After a previous introductory lecture on the basics of reflection in Java, in this lecture we take a closer look at some more advanced reflective features of the language such as dynamic proxies, call stack introspection and instrumentation. This lecture is part of a full course on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme.
An introduction to the basics of reflection in the object-oriented programming language Java, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme.
The concept of Java Reflection API has been discussed here in the presentation. Some code snippets have also been introduces to illustrate the different interfaces and use cases.
http://bd.linkedin.com/in/imranhasanhira
https://www.facebook.com/KonaSoftware
https://www.linkedin.com/company/kona-software-lab-ltd-
A reflection-oriented program component can monitor the execution of an enclosure of code and can modify itself according to a desired goal related to that enclosure.
Reflection is one of those things like multi-threading where everyone with experience of it says “Don’t use it unless you absolutely have to”.
TOPS Technologies Leading IT Training Institute offer training in Php, .Net, Java, iPhone, Android, Software testing and SEO. By TOPS Technologies. http://www.tops-int.com
An introduction to some advanced language features of the object-oriented programming language Ruby, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme. This lecture looks into the Ruby features of higher-order programming (lambdas), singleton methods, mixin modules, reflection and metaprogramming.
Basic java important interview questions and answers to secure a jobGaruda Trainings
P2Cinfotech is one of the leading, Online IT Training facilities and Job Consultant, spread all over the world. We have successfully conducted online classes on various Software Technologies that are currently in Demand. To name a few, we provide quality online training for QA, QTP, Manual Testing, HP LoadRunner, BA, Java Technologies, SEO, Web Technologies, .NET, Oracle DBA etc.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
A reflection-oriented program component can monitor the execution of an enclosure of code and can modify itself according to a desired goal related to that enclosure.
Reflection is one of those things like multi-threading where everyone with experience of it says “Don’t use it unless you absolutely have to”.
TOPS Technologies Leading IT Training Institute offer training in Php, .Net, Java, iPhone, Android, Software testing and SEO. By TOPS Technologies. http://www.tops-int.com
An introduction to some advanced language features of the object-oriented programming language Ruby, part of a full lecture on Programming Paradigms at UCL university in Belgium, focussing on the programming languages Smalltalk, Ruby and Java, with reflection and meta programming as underlying theme. This lecture looks into the Ruby features of higher-order programming (lambdas), singleton methods, mixin modules, reflection and metaprogramming.
Basic java important interview questions and answers to secure a jobGaruda Trainings
P2Cinfotech is one of the leading, Online IT Training facilities and Job Consultant, spread all over the world. We have successfully conducted online classes on various Software Technologies that are currently in Demand. To name a few, we provide quality online training for QA, QTP, Manual Testing, HP LoadRunner, BA, Java Technologies, SEO, Web Technologies, .NET, Oracle DBA etc.
oops concept in java | object oriented programming in javaCPD INDIA
object oriented programming is a key concept for the development of application in windows as well as web based application environment. oops concept maps real world through its concept of classes, objects, inheritance, polymorphism which help in making a robust application.
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
Features
JVM
Architecture
Security
Data Types
Class and Object
Program
First Java Application
Declaring and creating objects
Arrays
Constructors
this keyword
static keyword
Inheritance
Overriding
Access Modifiers
super keyword
final keyword
abstract classes
interfaces
Exceptions (error handling)
User Defining exceptions
Programming II hiding, and replacing members, Serialization, Generics, Linq ExceptionType
enum You will implement this enum in Visual Studio. There are seven members: Assignment 4 -
Implementing a Banking Application Due: See course shell for due date and time Check with
you professor to see if you are permitted to work as a group. The members are self-explanatory.
AccountType enum You will implement this enum in Visual Studio. There are three members:
The application is by far the most complex system that you have attempted so far. It consists of
eleven classes, two structs, one interface and two enums coupled in varying degrees of tightness.
The Bank class is the main driver of the application. It has collection of Accounts and Person
that is initialize appropriately in the static constructor. You will implement the entire system in
Visual Studio. A short description of each type with their members is given below. You are
advised to implement each type in the order that they are described. No method should have a
Console. WriteLine() unless you are explicitly told to output something on the console. Each
type must be in separate files.
Assignment 4, Winter 2022 Assignment 4, Winter 2022 hiding, and replacing members,
Serialization, Generics, ling Uses - Inheritance, Interfaces, Exceptions, EventHandlers,
Collections Operator overloading, Utils class hiding, and replacing members, Serialization,
Generics, Ling [The implementation for this class is given in the appendix. Create a class called
UtIs and copy and 1. Time - this public class variable is of type Day Time. It adds a random
value to the internal field_time and then returns it. past the statements into the appropriate part of
the file] 2. Now - this public class variable is of type Day Time. It adds zero to the internal
field_time You will implement the Utils class in Visual Studio. This class is comprised of three
fields and and then returns it. provides two static properties. It simulates the passage of time.
Each time the Time property is Methods: accessed, it increases the internal field by a random
amount. It is used to time stamped all banking There are no explicitly defined methods. You do
not have to code this class. Just copy the code statements from the appendix of this A short
description of each dass member is given below: document. Properties: There are three
properties. 1. _time - this private class variable is of type DayTime that store the time of this
object. It is initialized (with argument 1_648_600_800 ) at declaration. It is mutated (changed)
whenever either of the properties is accessed. 2. random - this private class variable is of type
Random storing the time of this object. It is initialized (with argument 1_848_800_800) at
declaration. It is mutated (changed) whenever elther of the properties is accessed. 3.
ACCOUNT_TYPE - this private class variable is of type Dictionary. It serves as a lookup table
to match an account type with a particular prefix, It is i.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
Andreas Schleicher presents at the OECD webinar ‘Digital devices in schools: detrimental distraction or secret to success?’ on 27 May 2024. The presentation was based on findings from PISA 2022 results and the webinar helped launch the PISA in Focus ‘Managing screen time: How to protect and equip students against distraction’ https://www.oecd-ilibrary.org/education/managing-screen-time_7c225af4-en and the OECD Education Policy Perspective ‘Students, digital devices and success’ can be found here - https://oe.cd/il/5yV
2. and there we go..!
●
●
Classes like Class, Method, etc..
A running program examining itself and it's environment..
3. Some reflective jargon & The definition
●
Metadata, MetaObjects, Introspection, etc..
●
Definition
○
○
○
The ability of a running program to examine itself and its software environment introspect, and behave accordingly.
This self-examination requires a self-representation - metadata.
In an OO world, metadata is organized into objects - metaobjects.
4. Feature set
Methods of Class for field introspection:
Field getField( String name)
Returns a Field object that represents the specified public member field of this class/interface.
Field[] getFields()
Returns an array of Field objects that represents all the accessible public fields of the this
class/interface.
Field[] getDeclaredField( String name )
Returns a Field object representing the specified declared field by this class/interface.
Field[] getDeclaredFields()
Returns an array of Field objects that represents all the that represents each field declared by this
class/interface.
5. Feature set cont.d..
Methods of Class for field introspection:
Class getType(), Class getDeclaringClass(), String getName(), int
getModifiers(), Object get( Object obj ), void set( Object obj, Object
value ),
On the similar lines, there are set of methods available for Method, Constructor & Annotations.
Hierarchy of members within reflection API:
Member
Method
Field
Constructor
7. Loading & Constructing at will..(1 of 2)
●
●
What web servers do?
○ loading and executing new code..
Load at will
○
Class.forname(String className)
■
Doesn't require class name at compile time
●
Examples:
○
○
Class cls = Class.forName("java.lang.String")
Class cls = Class.forName("java.lang.String[]");
■
System.out.println(String[].class.getName());
- Prints [Ljava.lang.String;
○
○
○
Class cls = Class.forName("[Ljava.lang.String;");
Will primitives work..?
Will primitive arrays work..?
8. Loading & Constructing at will..(2 of 2)
●
Reflective Construction
○
Class.newInstance()
■
○
Doesn't require class name at compile time
java.lang.reflect.Constructor
■
cls.getConstructor( new Class[] {String.class, String.class} )
●
introspects for a constructor of cls Class that takes two String parameters.
Flavours:
getConstructor(Class[]), getDeclaredConstructor(Class[]),
getConstructors(), getDeclaredConstructors()
○
Constructing Arrays
■
■
■
■
Array.newInstance()
Array.newInstance(String.class, 5);
Array.newInstance(String[].class, 5);
Array.newInstance(String.class, new int[] {2, 3});
9. The Joy of Breaking the laws..
#1
Accessing nonpublic members
Output:
Executing private method
120
10. The Joy of Breaking the laws..
#2
Breaking Immutability:
Output:
rue
String is mutable
String is mutable
11. Back to reality..
Plugging in the security module - SecurityManager
- An object that defines a security policy for an application.
- Any action not allowed in the policy throws SecurityException .
- Application can query its security manager for allowed actions
- Default policy file location : java.homelibsecurityjava.policy
- Specifying additional policy file at run time:
java -Djava.security.manager -Djava.security.policy=someURL SomeApp
12. Mastering the cross cutting issues..
What are cross cutting issues in an application?
Business flow Vs Logging
Business flow Vs Exception Handling
Business flow Vs Atomicity
Aspect Oriented Programming
Increasing modularity by allowing separation of cross cutting concerns
Logging
Exception Handling
Logging
Synchronizing
Business Logic
Synchronizing
Exception Handling
Business Logic
13. Dynamic Proxy
The Players:
java.lang.reflect.Proxy
- dynamic proxy-creation facility
Has methods to create a class that can work as a proxy
for another class.
Proxy instance provided, can implement the interfaces
implemented by the actual class; the class for which it
acts as a proxy.
java.lang.reflect.InvocationHandler - Each proxy instance has an associated invocation handler.
When a method is invoked on a proxy instance, the method invocation is encoded and dispatched to the invoke
method of its invocation handler.
Object InvocationHandler.invoke(Object proxy, Method method, Object[] args)
throws Throwable
method - the Method instance corresponding to the interface method invoked on the proxy instance.
args - an array of objects containing the values of the arguments passed in the method invocation on the proxy
instance.
=> Proxy can provide a Class or an instance that implements a given set of interfaces, of which every method call
is intercepted and provided with an opportunity to do some something extra..
14. Call Stacks & Stack Frames 1 of 2
- Each thread of execution has a call stack consisting of stack frames.
- Each frame in the call stack represents a method call.
Call Stack
Stack Frames
- Stack frames contain information pertinent to the
associated method.
- Each new method call corresponds to a new stack frame.
- Frame at the bottom of a call stack will be
main() or run()
StackTraceElement[] java.lang.Throwable.getStackTrace()
- new Throwable().getStackTrace()
- returns StackFrames Since the main() or run()
StackTraceElement provides following details:
File name, Line number, Class name, method name
15. Call Stacks & Stack Frames 2 of 2
Uses:
1.
Logging
2.
Security - Based on the caller's package or class access can be denied
new Throwable().getStackTrace()[1] = ?
Sample Usage:
main()
method1()
method2()
method3()
{
{
{
{
#16
m1(); #27
}
}
m2(); #38 m3() ; #56 StackTraceElement[] elt = new Throwable().getStackTrace();
}
}
Output:
elt[0] = Class : call.stack.introspection.CallStack1SampleApp File : CallStack1SampleApp.java Line : 56 Method :
method3
elt[1] = Class : call.stack.introspection.CallStack1SampleApp File : CallStack1SampleApp.java Line : 37 Method :
method2
elt[2] = Class : call.stack.introspection.CallStack1SampleApp File : CallStack1SampleApp.java Line : 27 Method :
method1
elt[3] = Class : call.stack.introspection.CallStack1SampleApp File : CallStack1SampleApp.java Line : 16 Method :
main
16. Is performance overstated?
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet
we should not pass up our opportunities in that critical 3%. A good programmer will not be lulled into complacency by
such reasoning, he will be wise to look carefully at the critical code; but only after that code has been identified"
— Donald Knuth
Reflective flexibility = Binding the names on run time..
●
Categorizing performance impact:
○ Construction overhead - One time
■ Dependency injection (Spring)
■ Dynamic Proxy for specific methods
■ Reflective code generation
○
○
●
Execution Overhead
■ Method.invoke()
■ Forwarding method through a proxy.
Granularity Overhead
■ Method.invoke() end up doing a lot of unnecessary checks
Granularity overheads should be narrowed whenever possible.
17. Through the JDKs..
●
JDK 1.0
○
●
Class, Object, ClassLoader
JDK1.1
○
●
java.lang.reflect, Field, Method, Constructor
JDK1.2
○
●
●
●
●
●
AccessibleObject, ReflectPermission
JDK1.3
○ Proxy, InvocationHandler, UndeclaredThrowableException,
InvocationTargetException
JDK1.4
○ StackTraceElement
JDK1.5
○ Generics support, Annotations
JDK1.6
○ 'Generified' some methods in Class: getInterfaces(), getClasses() , etc
○ The final parameter of Array.newInstance(Class, int...) is of variable arity.
JDK7
○ ReflectiveOperationException - A "Common superclass of exceptions thrown by reflective
operations in core reflection.
18. References
'Standing on the shoulders of giants'
Java Reflection in Action (In Action series) - Ira Forman and Nate Forman
http://www.javaworld.com/javaworld/jw-09-1997/jw-09-indepth.html?page=1
http://java.sun.com/developer/technicalArticles/ALT/Reflection/
http://docs.oracle.com/javase/tutorial/essential/environment/security.html
http://docs.oracle.com/javase/1.4.2/docs/guide/security/PolicyFiles.html
http://docs.oracle.com/javase/tutorial/reflect/TOC.html
http://java.sun.com/developer/technicalArticles/DynTypeLang/
http://stackoverflow.com/