An earthquake with a preliminary magnitude of 5.2 hit eastern Japan on Friday, shaking buildings in Tokyo.