The quake hit at 15:17 pm (0817 GMT) at a depth of 33 kilometres (20 miles), an official from the meteorology office in Jakarta said.
"It was felt in the town of Cilegon in West Java as well as in Jakarta," he told AFP.
"So far there have been no reports of damage or casualties, however a lot of phone calls have come in from people living in Jakarta, Cilegon and other towns in western Java," he said.
Indonesia sits on the Pacific "Ring of Fire", where the meeting of continental plates means seismic activity is common.
A geographical faultline runs parallel to the Indonesian island of Sumatra and tectonic activities along it have repeatedly led to strong earthquakes.