Source Code : Get all object accessible public fields
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Get all object accessible public fields
import java.lang.reflect.Field;
import java.util.Date;
public class Main {
public static void main(String[] args) throws Exception {
GetFields object = new GetFields();
Class clazz = object.getClass();
// Get all object accessible public fields.
Field[] fields = clazz.getFields();
System.out.println("Number of fields = " + fields.length);
for (Field field : fields) {
System.out.println("Field name = " + field.getName());
System.out.println("Field type = " + field.getType().getName());
}
Field field = clazz.getField("id");
System.out.println("Field name = " + field.getName());
System.out.println("Field type = " + field.getType().getName());
}
}
class GetFields {
public Long id;
protected String name;
private Date birthDate;
Double weight;
}
Thank with us