In 1436, Prameswara, the ruler of Malacca in the Malayan Peninsula, embraced Islam and was entitled Sultan Megat Iskandar Syah. Later he freed his sultanate from China which was its patron since 1402. Gradually, Malacca starts to take control on the trade route in the archipelago. By 1500, Malacca had become the greatest emporium in Southeast Asia, and all the trading ports of the western archipelago were centralized on Malacca. The most important of these were the ports on northern coast of Java, then still a Hindu island.
The last great Hindu kingdom of Java, Majapahit which capital is in Trowulan, had almost collapsed when Malacca began its supremacy on the region. Known to have subdued almost all of Southeast Asia kingdoms, the great empire waned after the death of its greatest ruler, Hayam Wuruk, in 1389. A civil war erupted from 1402 to 1406 helped further destruction of the kingdom. Though reunited in 1429, Majapahit had lost its control on many trading ports in the archipelago to the emerging Malaccan sultanate.
Taking advantage of the situation, the rulers of the Javanese coastal cities were seeking independence from the inland Hindu kingdoms of Majapahit and Pajajaran. Slowly but sure, intermarriage between Moslem traders and local nobles brought tight relationship with Malacca. Thus, it opened the gates of Java to Islam.
Ibn Batutta, the famous traveler from Moroco, also mentioned a Sufi scholar from Indonesia, Syeikh Abu Mas'ud Abdullah bin Mas'ud Al-Jawi, whom he met at Aden, Yemen, around 1328. It's a proof that Islam and Sufism had established in the island of Java at that time, probably among the merchants and nobles.
It's sad to know that many orientalists claim that the economic and worldly benefit which the rulers had by embracing Islam is the cause of their conversion to the new religion. This opinion should not be accepted and it's a reflection of the orientalists' bad prejudice to Islam. Actually it was Sufism who helped getting Islam into the hearts of the first converts of Indonesian Moslems. The Sufism teachings of love and asceticism had penetrated the mystic-minded royal courts, while their teaching of equality of all human before Allah had absorbed the commoners who were placed low in the caste-system of the Hindu kingdoms.
Further introduction of Sufism through art helped boost the spreading of Islam among the Javanese. This is due to the Javanese people's high appreciation toward art. The Sufi saints of Java at that time, known as The Nine Wali (Walisanga or Walisongo), was very much aware of it and exploits it for the benefit of Islam. These Sufi saints (Wali) creatively manipulated the already popular Hindu epic of Ramayana and Mahabharata to teach Islam through the shadow-puppet play (wayang kulit) and gamelan (set of metal instruments) music.
They also invented songs, poems, sport games, festivals, and even child's play and traditional cakes to propagate Islam and Sufism. These tactics proved to be very effective in making Islam the major religion among the Javanese.