Question: Is there a way that I can print out all names and values of an `Object` where `Object` can be of any class?

**i.e.** If `Object` was `Person` and `Person` had a member variable `Integer age;` - **I need a method** that could receive an instance of `Object` (where the `Object` is `Person` in this case but could be any other type of object) and print out `age - 35` where `age` is the member variable `name` and `35` is its `value`.

Something like:

```
public Map<String, String> getNamesAndValues(Object object) {
  Map<String, String> namesAndValues = new HashMap<>();
  //Populate namesAndValues Map here using object in signature.
  return namesAndValues;
}

```

If variables are `private` or `protected` then it should check for `getters` as well.

Answer: 
You could use Java reflection to analyze all fields of a given object and print them with their values. For more information, look at the reflection doc: 
<http://docs.oracle.com/javase/tutorial/reflect/member/index.html>
I have created some methods a while ago to accomplish what you want/need:

```
public final class MyObjectUtils {

    private static List<Field> getAllFields(Class<?> clazz) {
        if (clazz.equals(Object.class)) {
            return Collections.emptyList();
        }
        List<Field> fields = new ArrayList<Field>();
        fields.addAll(getAllFields(clazz.getSuperclass()));
        fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
        return fields;
    }

    private static List<Field> getModifiableFields(Class<?> clazz) {
        List<Field> fields = getAllFields(clazz);
        List<Field> realFields = new ArrayList<Field>();
        for (Field field : fields) {
            if (!(java.lang.reflect.Modifier.isStatic(field.getModifiers()) || java.lang.reflect.Modifier
                    .isFinal(field.getModifiers()))) {
                realFields.add(field);
            }
        }
        return realFields;
    }

    public static Map<String, Object> getFieldsAndData(Object object) throws IllegalAccessException {
        List<Field> fields = getModifiableFields(object.getClass());
        Map<String, Object> values = new LinkedHashMap<String, Object>();
        for (Field field : fields) {
            if (!field.isAccessible()) {
                field.setAccessible(true);
            }
            values.put(field.getName(), field.get(object));
        }
        return values;
    }
}

```

It is not a straight answer, but you can adapt it to your needs.