I am a student. Do I need to buy mental ray to experiment and write shaders?
No, a demo version of mental ray 2.1 with the full API is available with the book Rendering with mental ray, second edition. A mental ray 3.1 demo will be included of the second edition of the book Programming mental ray, available in Q2 2002. (The 2.1 and 3.1 APIs are nearly identical, shaders are compatible.