Do you really mean "variables"? Or do you mean "fields"?
In Java, "variable" generally means the local variables used in methods. There is no way in normal Java to find out these names. Depending on how you compiled your class (with or without debug information), there may be no way at all. But very few applications need to know the local variable names. If you think you need to know them, and you are indeed a beginner, it's almost certain that you don't need them, and just need a better design.
In contrast, "field" means the values that are part of an object instance, or a class (static fields). These can be obtained by Java Reflection, using methods of java.lang.Class.
getFields() will get all public fields, inherited or not.
getDeclaredFields() gets all fields, directly declared in the class, whatever their access level.
If you need all fields, in the class and its superclasses, you'll need to code a loop, and use getSuperclass() in the loop.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joined: Feb 26, 2008
try object.getDeclaredFields()method...It will return an array of Field objects reflecting all the fields declared by the class or interface represented by this Class object. This includes public, protected, default (package) access, and private fields, but excludes inherited fields. For further reference see webpage
sorry if the question is worng. i have the JFrame in that i created all the GUI in Netbeans. i want to make the application like coustmizeing the font and color for panels like that. so i have more then 50 JLabels so i don't want to hard code it. i want to write the code to access all the Labels in that Class. and i Want to set the Properties