An earthquake with a magnitude of 6.5 struck the island of Java in Indonesia, the US Geological Survey (USGS) said, with authorities reporting at least two deaths and damage to buildings.

Indonesia's national disaster management agency said the quake activated early tsunami warning systems in the south of Java, but the Pacific Tsunami Warning Centre said no tsunami had been detected.

The quake struck at 11:47pm (local time) and was felt across the island, including about 200 kilometres away in the capital Jakarta, where office towers and apartment buildings swayed. Powerful tremors lasted around 30 seconds in places.

Panicking people ran out of buildings in many areas and Indonesian television showed heavy traffic on roads as people fled coastal areas.

A 62-year-old man and an 80-year-old woman were killed in building collapses, National Disaster Mitigation Agency spokesman Sutopo Purwo Nugroho said.

Damage was heaviest in the Tasikmalaya, Pangandaran and Ciamis regions of West Java Province near the epicentre.

Motorists were stuck in traffic as they tried to reach higher ground amid fears of a tsunami. ( AP: Wagino )

More than 40 houses collapsed and about 65 suffered severe damage, Mr Nugroho said.

The earthquake triggered a tsunami warning for parts of Java's coastline that was lifted about two hours later.

Several hospitals were damaged by the shaking and patients evacuated.

Java is Indonesia's most densely populated island and is home to more than half of its 250 million people.

AP/Reuters