Why do we need to convert objects into a Map?

The example code you found is about the concept of object mapping. The idea is: you have java objects that carry information, and you want to automatically turn that information into some other format.

Meaning: conceptually, a Student, that is just a collection of key/value pairs, like name is nayan.

The essential part here: this code shows you how to turn a Student object into another "format", in this case, a raw Map with key/value pairs.

You mainly want to use that when persistency comes into play. Meaning: say you want to store your data as JSON. Do you really want to write all the code manually that takes your objects, turns them into a JSON representation, or vice versa? No, you don't (unless for educational purposes).