The earthquake struck at 12.14 p.m., with its epicentre at 104 km southwest of Java at a depth of 48 km under seabed, an official of the Meteorology and Geophysics Agency told Xinhua.
The quake was also felt at Yogyakarta, driving panic and forcing people to rush out of the houses and buildings, Sutopo Purwo Nugroho, an official and spokesman for national disaster agency said.
Later, two aftershocks measuring 4.9 and 4.3 on the Richter scale followed the main shock, centred at the seabed, he said.
“One house collapsed and several others suffered from damages in Krangdegan village at Purworejo (Central Java),” said Sutopo, adding that the assessment was being conducted in the quake-affected areas.
“In Yogyakarta, Cialacap and Kebumen, people were panic and quickly left their houses and office buildings,” he said.
The officials said there was no risk of a tsunami.
A 6.1-magnitude quake, which struck Aceh province on Sumatra island July 2013 killed at least 35 people and left thousands homeless.
Indonesia is vulnerable to seismic upheaval, as it is located in the Pacific Ring of Fire, where tectonic plates collide, causing frequent seismic and volcanic activity.