There were no immediate reports of casualties.
Indonesia’s National Disaster Management Agency said the undersea earthquake damaged at least 15 houses, two schools, a health facility and a government office.
Television reports showed local residents in the special province of Yogyakarta and its neighbouring provinces of Central Java and East Java panicking as houses and buildings swayed for several seconds.
Some places ordered evacuations, sending streams of people into the streets.
Indonesia’s Meteorology, Climatology and Geophysical Agency said there was no danger of a tsunami but warned of possible aftershocks.
The agency measured a preliminary magnitude of 6.4.
Read Related Also: Comic Dane Baptiste calls Australia 'still the most racist English speaking country I've been to'
Variations in early measurements of quakes are common.
Yogyakarta is an ancient centre of Javanese culture and the seat of royal dynasties going back centuries.
It is home to the 9th-century Borobudur — nine stone tiers stacked like a wedding cake and adorned with hundreds of Buddha statues and relief panels — and the towering Hindu temple complex of Prambanan, both are UNESCO World Heritage sites and Mount Merapi, the country’s most active volcano.
In 2006, a 6.4 magnitude earthquake in Yogyakarta killed more than 6200 people and injured more than 130,000 others, but caused only minor damage to the two temples.
The country of more than 270 million people is frequently struck by earthquakes, volcanic eruptions and tsunamis because of its location on the arc of volcanoes and fault lines in the Pacific Basin known as the “Ring of Fire.”
In 2004, an extremely powerful Indian Ocean quake set off a tsunami that killed more than 230,000 people in a dozen countries, most of them in Indonesia’s Aceh province.