know about modifiers of a class object, using reflection of java 5 5 1

know about modifiers of a class object, using reflection of java

View previous topic View next topic Go down

know about modifiers of a class object, using reflection of java

Post by BIT0112-Rokon on Fri Aug 20, 2010 6:15 am

In Java there is a very interesting part named Java reflection. Ive some idea about it. Today in this text, Im going to show you how know about built-in class modifier. For say, String is class. But do you know what is the class modifier ? While programming we use lots of built-in class. If you are interested to know the class modifier of those built-in class, this text for you. Now Im going to show you how to know about it. Its very easy, just compile the code given below:


Code:


import java.lang.reflect.Modifier;
import javax.swing.JFrame;

public class ClassModifier {
   public static void main(String[] args) {
      getClassModifier(String.class);
      getClassModifier(Double.class);
      getClassModifier(JFrame.class);
   }

   private static void getClassModifier(Class clazz) {
      int modifier = clazz.getModifiers();
      
if (Modifier.isPublic(modifier)) {
         System.out.println(clazz.getName() + " class modifier is public");
      }
      if (Modifier.isProtected(modifier)) {
         System.out
               .println(clazz.getName() + " class modifier is protected");
      }

      
      if (Modifier.isPrivate(modifier)) {
         System.out.println(clazz.getName() + " class modifier is private");
      }
      if (Modifier.isStatic(modifier)) {
         System.out.println(clazz.getName() + " class modifier is static");
      }
      if (Modifier.isFinal(modifier)) {
         System.out.println(clazz.getName() + " class modifier is final");
      }
      if (Modifier.isAbstract(modifier)) {
         System.out.println(clazz.getName() + " class modifier is abstract");
      }
   }
}


and the output will be


java.lang.String class modifier is public
java.lang.String class modifier is final
java.lang.Double class modifier is public
java.lang.Double class modifier is final
javax.swing.JFrame class modifier is public

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon
Programmer
Programmer

Course(s):
  • BIT

Blood Group: O+
Posts: 673
Points: 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: know about modifiers of a class object, using reflection of java

Post by BIT0122-Amit on Fri Aug 20, 2010 7:35 pm

what you described is the process of finding out the modifier of a class.
My question is, why would I want to know the class modifier of a specific class?

Can you give one or more practical scenarios?

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|

BIT0122-Amit
Founder
Founder

Course(s):
  • BIT

Blood Group: O+
Posts: 4187
Points: 6601

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: know about modifiers of a class object, using reflection of java

Post by BIT0112-Rokon on Fri Aug 20, 2010 10:40 pm

I actually wanted to introduce you guys about the new term that is Java Reflection. It is unique features of Java. Using Java Reflection you can inspect Java classes at runtime. Using reflection you can get information about Java classes, constructor,Fields, methods, getters setters, Private fields and methods, Annotations, generics, arrays, dynamic proxy, dynamic class loading and reloading and so on.......

Btw it is advance topics of java. if you are interested about it, ping
here

cheers !!

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon
Programmer
Programmer

Course(s):
  • BIT

Blood Group: O+
Posts: 673
Points: 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: know about modifiers of a class object, using reflection of java

Post by BIT0122-Amit on Fri Aug 20, 2010 11:26 pm

bit0112-rokon wrote:I actually wanted to introduce you guys about the new term that is Java Reflection. It is unique features of Java. Using Java Reflection you can inspect Java classes at runtime. Using reflection you can get information about Java classes, constructor,Fields, methods, getters setters, Private fields and methods, Annotations, generics, arrays, dynamic proxy, dynamic class loading and reloading and so on.......

Btw it is advance topics of java. if you are interested about it, ping
here



cheers !!


I asked why I would use it, not what I can do when I use it Neutral

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|

BIT0122-Amit
Founder
Founder

Course(s):
  • BIT

Blood Group: O+
Posts: 4187
Points: 6601

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Re: know about modifiers of a class object, using reflection of java

Post by BIT0112-Rokon on Sat Aug 21, 2010 12:42 am

I think you will find your answer from HERE

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon
Programmer
Programmer

Course(s):
  • BIT

Blood Group: O+
Posts: 673
Points: 1269

View user profile http://blog.codexplo.org

Back to top Go down

View previous topic View next topic Back to top


Permissions in this forum:
You cannot reply to topics in this forum