public class TestName { public static Object getObjectPropertyValue(Object obj,String propertyName)throws Exception{ Field field=obj.getClass().getField(propertyName); return field.get(obj); } public static void main(String[] args) throws Exception { dataObject da=new dataObject("test"); System.out.println(getObjectPropertyValue(da, "name")); } } class dataObject{ public String name; dataObject(String s){ this.name=s; } }