"What case is the first halacha speaking of (that one must violate the commandments rather than give up his or her life)? In a case of all the commandments except idol worship, illicit relations and bloodshed. However, by transgressing these three sins, if one is given the object to transgress or die one must die rather than transgress.
Idol worship goes counter to the idea that G-D controls the world. Someone who worships idols asks the idols for rain, money and other events. This detracts from the belief that G-D is the ruler and guider of the world. Illicit relations represents the antithesis of G-D's ultimate power over the granting of life. Someone who has illicit relations uses a forbidden path to form life. Bloodshed is a man taking the power of ending life. These three ideas are the antithesis of Torah and Judaism. When someone falters in one of these three areas it is impossible to worship G-D with the same level of fervor. Therefore, the idea of "live by them" does not apply in these situations.
In the other situation, that a non-Jew is forcing a Jew to transgress a commandment just because he is Jewish and the non-Jew wants him or her to violate the laws of the Torah, this is similar, but a little different. The non-Jew's sole purpose is to hear the Jew renounce G-D. In this situation a Jew is given a choice, is G-D the ultimate truth or is man in charge of the world. The non-Jew or idol worshiper is trying to show that he or she is in charge and not G-D. Therefore, one must stand up and say that G-D is the only one that is all powerful and this disgusting person is worthless. However, it is only necessary to give up one's life in public in this case because if it was in private there is no real statement being made. However, in public there is a public act of acknowledgment that is being conveyed. So in private, one may transgress, but in public it is necessary to give up one's life.