• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is introspection?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi friend, pl'z help me
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pinakin,
Welcome to JavaRanch!

The JavaDoc provides a good description of Introspection. Were you looking for anything more specific?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is more fun to introspection! You can learn a lot about the constructors, methods and variables of any class, not just JavaBeans, by starting with a Class object. You can get one of those in (at least) two ways:

Class c = Class.forName( fully.qualified.className );
Class c = anyObject.getClass();

Look in the Class javadoc for getConstructors, getFields, getMethods, etc. HERE is a toy program I made to educate myself in reflection. The Reflector class might be interesting. Or just strange.
[ June 30, 2005: Message edited by: Stan James ]
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by pinakin raval:
hi friend, pl'z help me



Answer: not an advanced question.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Introspection:

It is the cutting edge of java programming.
Introspection helps to get the attributes or property values of a qualified class during runtime.
Sample code has been given below to explain the core concepts of Introspection.
This code is in working condition, you can use it just by copying it.

Hope this would meet you need.


import java.beans.PropertyDescriptor;
import java.beans.Introspector;
import java.beans.IntrospectionException;

public class SampleClass
{
public void callSample()
{
SampleBean sample = new SampleBean();
//Object value=null;
try
{
PropertyDescriptor[] accessors = Introspector.getBeanInfo(sample.getClass()).getPropertyDescriptors();
System.out.println("Length>>>>>>>>>>>" +accessors.length);
for ( int i=0; i<accessors.length; i++)
{
System.out.println("Property Name >>>>>>>>>>>" +accessors[i].getDisplayName());
System.out.println("Read Method >>>>>>>>>>>" +accessors[i].getReadMethod());
System.out.println("Property Type >>>>>>>>>>>" +accessors[i].getPropertyType());
try
{
Object value = accessors[i].getReadMethod().invoke(sample,null);
System.out.println("The value is "+value.toString());
}
catch ( Throwable iae )
{
}
}
}
catch ( IntrospectionException ie )
{
ie.printStackTrace();
}
}
public static void main(String a[])
{
SampleClass sc = new SampleClass();
sc.callSample();
}

}


// Seperate class

public class SampleBean
{
private String name="Inbakumar";
private String phoneNumber="12345678";

public String getName()
{
return name;
}


public String getPhoneNumber()
{
return phoneNumber;
}

}
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by pinakin raval:
hi friend, pl'z help me



There's a forum called "Java in General" that would be ideal for this question.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick O'Shay:


There's a forum called "Java in General" that would be ideal for this question.



I should add: (Beginner)
 
A wop bop a lu bob a womp bam boom. Tutti frutti ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic