People ran out of buildings in panic in many areas and Indonesian television showed heavy traffic on roads as people left coastal areas.
National Disaster Mitigation Agency spokesman Sutopo Purwo Nugroho said a 62-year-old man was confirmed dead in the Ciamis region of western Java and that there were reports of more deaths and of injuries in the same region.
He also said there were reports that buildings had collapsed in the city of Tasikmalaya in western Java and in several western Java districts.
"Houses and other buildings are damaged in many areas," he said in a statement.
"We are still evaluating the impact of the quake and will give an update later," Nugroho said in a statement.
The US Geological Survey said the earthquake had a magnitude of 6.5 and was about 91 kilometers (56 miles) deep and located just inland.
Indonesian authorities reported a quake of similar magnitude offshore of Java.
Nugroho said strong tremors were felt for about 20 seconds in the capital of Jakarta and in cities and villages.
Indonesia's MetroTV said a general hospital in the central Java town of Banyumas was damaged and patients were evacuated.
Jakarta resident Web Warouw was on the 18th floor of a building in the capital when the quake struck.
"Suddenly, we felt dizzy, but constantly... We then realized it was a quake and immediately ran downstairs," the 50-year-old said.
People in the coastal city of Cilacap evacuated as a precaution fearing a tsunami, although no alert had been issued for the area.
Indonesia experiences frequent seismic and volcanic activity due to its position on the Pacific "Ring of Fire", where tectonic plates collide.
An earthquake struck the country's western Aceh province in December 2016, killing more than 100 people, injuring many more and leaving tens of thousands homeless.
- AP