Mostly through active investigation via shadowing, interest groups, etc. Fields like derm, rad onc, and ophtho (just to name a few) aren't generally something that medical students routinely experience without actively seeking this out. Some schools will allow an elective in any of these during third year, but if you're interested in dermatology I recommend you save an actual elective rotation for fourth year. Introducing yourself to the department early on (and getting involved with shadowing/research) can help you find out if any of these fields seem right for you.