In Thailand it was common for temples to require that you wear pants or scarves to cover your shoulders.
Japan has many ancient places; if you wear shorts to a temple or a palace, are you risking the scorn of the gods, and your fellow temple goers?
No, there are no dress codes at temples or shrines. The Japanese attitude to religion is very relaxed... and simultaneously strict, as entry to anything even vaguely holy is generally entirely prohibited.
That said, the prevailing Japanese opinion is that men's shorts above the knee are for elementary school students and the beach, although nobody will find you wearing them offensive, just vaguely ridiculous.
One nice although by no means obligatory gesture on entering a shrine is quickly purify yourself at the water basin (chōzuya). The standard ritual is as follows: