Also, do students studying to become either one of these need to study things like how to program an java and stuff?
I am studying Mechatronic it's a mix of both. You need C for sure as an electrical engineer.
The initial years have a very similar syllabus which becomes more specialised as time moves on. Programming skills may be helpful but will not teach you the basics of either.
electrical engineer deals with electrical equipments(like motor,drive,plc),automation process etc and a mechanical engineer deals with mechanical equipments (like compressor, refregeration,air conditioning engine etc) both of the engineers need to know programming language. but it is not necessary to learn java