how is it possible to get the variable name instead in JAVA?
No, it is not possible. The closest thing you could do is to store the variables and their values in a Map<String, Object>
and assign the name of the variable as the key:
//maintain order of the elements by the key
Map<String, Integer> mapVariables = new TreeMap<String, Integer>();
mapVariables.put("a1", a1);
mapVariables.put("a2", a2);
mapVariables.put("a3", a3);
mapVariables.put("a4", a4);