Вы находитесь на странице: 1из 5

Reflection Api in java | Techartifact

1 of 5

http://www.techartifact.com/blogs/2009/10/reflection-api-in-java.html

About
Disclaimer

564Subscribers 237Fans 70Followers


Home
Oracle ADF
Java
Spring
.NET
News
Join Us
2

Reflection Api in java


Vinay 20 Oct 2009 Java, reflection api, Reflection Api in java Views: 5,657 views
The Reflection API allows Java code to examine classes and objects at run time. The new reflection
classes allow you to call another classs methods dynamically at run time. With the reflection classes, you
can also examine an instances fields and change the fields contents.
Reflection is commonly used by programs which require the ability to examine or modify the runtime
behavior of applications running in the Java virtual machine. This is a relatively advanced feature and
should be used only by developers who have a strong grasp of the fundamentals of the language. With
that caveat in mind, reflection is a powerful technique and can enable applications to perform operations
which would otherwise be impossible.
Uses of Reflection
Extensibility Features
An application may make use of external, user-defined classes by creating instances of extensibility
objects using their fully-qualified names.
Class Browsers and Visual Development Environments
A class browser needs to be able to enumerate the members of classes. Visual development environments
can benefit from making use of type information available in reflection to aid the developer in writing
correct code.
Debuggers and Test Tools
Debuggers need to be able to examine private members on classes. Test harnesses can make use of
reflection to systematically call a discoverable set APIs defined on a class, to insure a high level of code
coverage in a test suite.
Drawbacks of Reflection
Reflection is powerful, but should not be used indiscriminately. If it is possible to perform an operation
without using reflection, then it is preferable to avoid using it. The following concerns should be kept in
mind when accessing code via reflection.

13-02-2013 16:02

Reflection Api in java | Techartifact

2 of 5

http://www.techartifact.com/blogs/2009/10/reflection-api-in-java.html

Performance Overhead
Because reflection involves types that are dynamically resolved, certain Java virtual machine
optimizations can not be performed. Consequently, reflective operations have slower performance than
their non-reflective counterparts, and should be avoided in sections of code which are called frequently in
performance-sensitive applications.
Security Restrictions
Reflection requires a runtime permission which may not be present when running under a security
manager. This is in an important consideration for code which has to run in a restricted security context,
such as in an Applet.
Exposure of Internals
Since reflection allows code to perform operations that would be illegal in non-reflective code, such as
accessing private fields and methods, the use of reflection can result in unexpected side-effects, which
may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and
therefore may change behavior with upgrades of the platform.
References
http://java.sun.com/docs/books/tutorial/reflect/
http://www.javacommerce.com/displaypage.jsp?name=index.sql&id=18272
1 Vote
2

Vinay
I am software professional, working on Java/J2EE/ADF technologies i.e
Java,J2ee,Oracle ADF,hibernate,J2ee,PL/sql,Apps for 5+ years.I am
passionate about learning new technologies.I am sharing my knowledge. Give
your views and suggestion on vinay[at]techartifact.com
More Posts - Website
Follow Me:

Related Posts
creating a basic skeleton to invoke an AM in Java Class in Oracle ADF
01 Feb 2013

13-02-2013 16:02

Reflection Api in java | Techartifact

3 of 5

http://www.techartifact.com/blogs/2009/10/reflection-api-in-java.html

Java program to SORT MAP based on KEYS


08 Jan 2013
Why use hashMap when ConcurrentHashMap is there | Techartifact
12 Dec 2012

2 Responses to Reflection Api in java


Trackbacks/Pingbacks
1. Java Reflection Api: More Drawbacks Unstable Terrain
2. PimpThisBlog.com

Leave a Reply
Name (*)

Email (will not be published) (*)

Website

Web Page Blocked


You have tried to access a web page
which is in violation of your internet
usage policy.
URL:
googleads.g.doubleclick.net/pagead
/ads?client=ca-

Archives

13-02-2013 16:02

Reflection Api in java | Techartifact

4 of 5

http://www.techartifact.com/blogs/2009/10/reflection-api-in-java.html

Web Page Blocked

Top Post
Thread Pool in java - 122,281 views
Implementation of thread Pool in java - 44,349 views
Oracle ADF interview Question Part 1 - 40,108 views
Serialization Vs Externalization - 36,453 views
Anonymous Classes in Java - 35,272 views
What is Ext-Js(Extended JavaScript) - 31,741 views
Interview question on thread in Java - 30,427 views
Interface vs Abstract Class - 29,911 views
Marker interface in java - 29,040 views
Hello World Tutorial in ADF - 23,440 views

You have tried to


access a web page
which is in
violation of your
internet usage
policy.
URL:
googleads.g.doubleclick.net/pagead
/ads?client=capub-7884501643823458&
output=html&
h=600&
slotname=2524100578&
w=160&
lmt=1360751142&
flash=11.4.402&
url=http%3A%2F
%2Fwww.techartifact.com%2Fblogs%2F2009
api-in-java.html&
dt=1360751143747&
bpp=4&
shv=r20130206&

13-02-2013 16:02

Reflection Api in java | Techartifact

5 of 5

http://www.techartifact.com/blogs/2009/10/reflection-api-in-java.html

Tags

ADF ajax ASP.NET ASP.NET 2.0 C#.NET C#.NET 2.0 code example column Design Pattern
Example extjs features get hashmap hibernate J2EE Java Java design Pattern Javascript Jetspeed2 Jquery
JSF JSF 2.0 lifecycle managed bean Memory method Microsoft Mysql Open Portal Open Source

Oracle ADF portal programmatically row Spring sql server table Task flow Techartifact Tips value
view object Web Development XML

Go To Top
Copyright 2009-2012 Techartifact.com

Web Page Blocked


Disclaimer
About

13-02-2013 16:02

Вам также может понравиться