There were no immediate reports of damage or casualties.
The quake struck 96 kilometres (59 miles) southwest of Sukabumi in western Java after 6:00 pm (1100 GMT) at a depth of 67 kilometres, the US Geological Survey said.
”The quake was quite strong but we have no reports yet of casualties or damage. We will monitor the affected area,” National Disaster Mitigation Agency spokesman Sutopo Purwo Nugroho said.
Nugroho said the quake struck around 50 kilometres offshore and that activities in Sukabumi had “gone back to normal”.