know about modifiers of a class object, using reflection of java
Page 1 of 1 • Share •
know about modifiers of a class object, using reflection of java
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:
and the output will be
- 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

- Course(s):
- BIT
Blood Group: O+
Posts: 673
Points: 1269

Re: know about modifiers of a class object, using reflection of java
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?
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

- Course(s):
- BIT
Blood Group: O+
Posts: 4187
Points: 6601

Re: know about modifiers of a class object, using reflection of java
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 !!
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

- Course(s):
- BIT
Blood Group: O+
Posts: 673
Points: 1269

Re: know about modifiers of a class object, using reflection of java
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
_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.
|About me|My Blog|

BIT0122-Amit- Founder

- Course(s):
- BIT
Blood Group: O+
Posts: 4187
Points: 6601

Re: know about modifiers of a class object, using reflection of java
I think you will find your answer from HERE
_________________________________________________________________
Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী

BIT0112-Rokon- Programmer

- Course(s):
- BIT
Blood Group: O+
Posts: 673
Points: 1269

Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
Active Topics!

» Understanding Timestamp Based Protocol
» Hi from Newbie
» Compare an image from a list of images in the sql database....tell which image is matching
» Sending email without email ID
» teach yourself c by herbert schildt pdf
» .NET MVC3: Unable to find the requested .Net Framework Data Provider. It may not be installed.
» SAD Slides: 4.1, 4.2
» QA topic Presentation - Urgent Notice