Classic cardiac pain is described as a central, crushing chest pain. People usually describe it as “tightness”, and they often feel anxious, sweaty, breathless and nauseated with the pain. Doesn’t sound like the OP’s problem.
A sharp, severe chest pain that is worse on inhalation is also a symptom of a blood clot in the lungs (pulmonary embolism), coughing up blood would be another symptom of a PE. It would be unusual in a fit, healthy young man, unless he’d been confined to bed for a long time or had blood that clotted abnormally quickly, so I think that that would also be unlikely.
Chest pain that is worse on deep breathing is usually described as “pleuritic”. It can be caused by muscular, bone or joint problems (costochondritis, broken ribs etc) or by lung infections such as pneumonia or pleurisy. The OP doesn’t mention a cough, so infection seems unlikely.
As well as the lung/heart/ribs, there is also the oesophagus (yes I can spell it correctly, it’s spelt that way on this side of the Atlantic) and acid reflux (heartburn) could indeed lead to sharp chest pains.
Studying hunched over in a chair could ead to some muscle spasms in the chest wall and upper back, that might explain the pain, and hunching over books could also make acid reflux worse.
Caffeine may give you the sensation that your heart is racing, but shouldn’t cause chest pain. Stress can certainly cause headaches and chest pain, so don’t discount it.
If the pain goes away after some over-the-counter pain meds, like aspirin, paracetamol (acetominophen) or ibuprofen, you can almost certainly rule out your heart as the cause. Cardiac pain will NOT respond to mild pain medication, but will be relieved by special medication like GTN (the one that people with angina spray under their tongues).
If you have no cough, no sensation of acid in your mouth and the pain is gone, your doc is going to have a rough time trying to work out where the pain is coming rom. The best they’ll probably be able to do is to tell you that your heart and lungs sound fine, and give you some muscle relaxants, antacids and pain meds.
On the other hand, if you still have the pain, SEE A DOCTOR NOW. That will give them a good chance of getting to the bottom of it, and hopefuly stop it happening again.