Bali was first settled by Chinese immigrants sometime around 2500 BC and after working on it for 2,000 years the complex irrigation system that is still the focal point of Balinese agriculture and way of life today was established. Things remained pretty much unchanged until the 11th century. Around 1010 AD a Balinese Prince named Airlangha took over East Java intending to unite it with Bali under his rule. Successful, he subsequently appointed his brother, Anak Wungsu, to rule Bali. As such there was a great deal of commerce between Bali and Java bringing with it an exchange of politics and arts. It was at this time the Bali adopted the Javanese language, Kawi that is still used today.
Airlangha's death brought on several wars waged by Javanese Kings to continue the Javanese control of Bali. Finally in 1343 Bali succumbed to Javanese control when it was defeated by a General by the name of Gajah Mada from the Majapahit Empire, the last Hindu Javanese empire.
When Islam began spreading south from Sumatra into Java in the 16th century, the Majapahit empire collapsed and a large number of aristocrats, priests, and artists fled to Bali. From then until the Dutch arrived in 1597 little changed except the culture continued to be refined - which is where we pick up the story.