You can drink coffee before your exam while keeping two points in mind. One is that caffeine from coffee takes around 20-30 minutes to start showing its effects so ideally, you should drink your coffee 20-30 minutes before your exam starts. The second point is that excessive caffeine intake can cause impaired concentration and anxiety. So watch your caffeine intake.