Other Indonesian areas gradually adopted Islam , making it the dominant religion in Java and Sumatra by the end of the 16th century .
By the end of the 16th century it was the dominant religion in Java and Sumatra .