I want to ask that is it compulsory in islam for men to shave the armpit and pubic hair? If we will not shave what will be the precautions? If it is compulsory to shave how and when we should shave?
Muslims are encouraged to remove pubic hair and to shave armpits.
I heard the Prophet (saws) saying. "Five practices are characteristics of the Fitra (nature): removing the pubic hair, clipping the nails, depilating the hair of the armpits; and circumcision and cutting the moustaches short (for the males). (Sahih Al-Bukhari Hadith 7.779, narrated by Abu Huraira)
Time limit is forty days.
A time limit has been prescribed for us for clipping the moustache, cutting the nails, plucking hair under the armpits, shaving the pubic region: that it should not be neglected for more than forty nights. (Sahih Al-Bukhari Hadith 7.779, narrated by Abu Huraira)
The point is to remove hair from these places. How will you do it, it's your choice (as long as you're not ruining your health).
And Allah knows the best.