Software Technology Tips

A simple way to get the class structure information of the Class we are using in our application.

Step1: Create the Class object of the class we want to explore at run time or the class which is getting added at runtime.
Step2: As we are looking for the structure of the class, get all Constructors, Fields and methods by invoking respective functions of the Class.
Step3: print them in java console or use them as required.


//create the Class object of class whose structure we want to know or getting added at runtime. e.g.  (java.lang.Float).
Class classObj = Class.forName("java.lang.Float");

//get all fields available in the class
Field fld[] = classObj.getDeclaredFields();

//get all Constructors available in the class
Constructor cnst[] = classObj.getConstructors();

//get all methods available in the class
Method mtd[] = classObj.getMethods();

Use appropriate function to get information about each array element like getName() to get the name of the fields or Consturctors and so on.

Note:  Add the above code in a try.. catch block as the functions throw ClassNotFoundException and SecurityException.

Related Tags:


Author: Partho Banerjee

Related Pages

  • Java Web Services Development
  • Java/JSP/Servlets Projects


Let us Connect!

Awards and Achievements

Red Herringcolor DeloitteFast50 DB ZInnov1   Nascome  DB Stpi

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login