In June 17, 1864, Governor-General Mr. L. A. J. W. Baron Sloet van Beele broke ground for the first railway line in Java, which was then part of Netherlands East Indies. The line belonged to the Nederlandsch-Indische Spoorweg Maatschappij (Netherlands East Indies Railway Company), and the first line in operation was between Semarang and Tanggung, opened in August 10, 1867.
The line was then unprofitable, so the company turned to the government for help in completing the rest of the 166 km long main line to Yogyakarta through the Vorstenlanden. The great cost involved in the building was partly caused by the decision to build the tracks at the standard gauge (1435 mm/4' 8Ĺ"). This also resulted in the selection of a narrower gauge for most of the later construction, after a 1869 report by J. A. Kool and N. H. Henket showed the economy and suitability of 1067 mm (3' 6") gauge.
The first of the narrow gauge line was also built by the NIS, connecting Jakarta and Bogor. It was opened in January 31, 1873 after two years of construction. The line was quite profitable, but as it was isolated from the rest of the NIS lines in Central and East Java, it was later sold to the SS in 1913.
The state then began to get involved directly in the construction of railways. In May 16, 1878 the first line of the Staatsspoor- en Tramwegen in Nederlandsch-IndiŽ (State Railway) was opened between Surabaya and Pasuruan. Three years later, construction was begun on a line from Bogor to Cicurug in West Java, with the intention to reach Cilacap, an important port in the southern coast of Java.
In 1884, the SS lines reached Surakarta, on the NIS main line, and in 1888, Cilacap. A continuous railway line was in place between Jakarta and Surabaya in 1894, with the completion of the last section, between Maos and Cibatu. The journey between the two points took three days, with the actual travel time being 32Ĺ hours, because trains did not run at night, and the presence of different gauges required passengers and goods to be transferred at both Yogyakarta and Surakarta. Yet it was a great improvement over the horse-hauled carriages, which took up to two weeks for the trip.
The Samarang-Joana Stoomtram Maatschappij received the concession to build a light railway ("tramway") between Semarang and Juwana in 1881. It was the first of the 15 tramway companies in Java. The tramways were usually related to agricultural developments, especially sugar plantations and factories, tobacco and rubber plantations, and forestry. The lines also acted as feeder to the main lines.
Nederlandsch-Indische Spoorweg Mij West Java, Eastern Central and East Java 1867-1924 855 km
Samarang-Joana Stoomtram Mij Semarang-Cepu, Northwest Central Java 1882-1923 417 km
Semarang-Cheribon Stoomtram Mij Semarang-Cirebon, Northern Central Java 1897-1914 373 km