Strong tremors were felt in the Indonesian capital Jakarta city on Monday.
The quake was so strong that people rushed out of apartments, and offices.
The epicenter was on land in Cianjur in West Java, at a depth of 10 km (6.21 miles), the weather and geophysics agency BMKG said, adding there was no potential for a tsunami.
BMKG chief Dwikorita Karnawati told reporters at the parliamentary building to stay outdoors in case of aftershocks.
Another official at the BMKG, Suko Prayitno Adi, said the authorities were checking the extent of the damage caused by the quake.
The United States Geological Survey (USGS) recorded the earthquake at a magnitude of 5.4 on the Richter scale.