As one leaves this city of 7 million for the Javanese heartland, urban scenes quickly give way to vistas of peasants toiling as they have for centuries in multitiered rice terraces that stretch up the sides of mountains and sprout their green shoots in almost every conceivable nook of the land.

But the overwhelming impression is of people. They are everywhere on Java, this principal island of Indonesia, and the countryside looks like nothing so much as one continuous village.

With more than 90 million people crammed into an area the size of New York state, Java is one of the most densely populated places in the world. The island holds about 63 percent of Indonesia's population, although it accounts for only 7 percent of the country's land area. Java is twice as densely populated as Japan, and the population is increasing at the rate of 2.3 percent a year. Meanwhile, farms are getting smaller as more people share the land.

To cope with the problem, the government is stepping up the world's largest rural resettlement program. Called "transmigration," the voluntary scheme is aimed at moving at least 21 million people to underpopulated outer islands in this far-flung, 13,600-island archipelago.

According to Martono, Indonesia's junior minister for transmigration, the figure derives from experts' calculations that Java can fully accommodate no more than 70 million people. The government's current five-year plan calls for 500,000 families, totaling about 2.5 million people, to be resettled at more than 100 sites on other Indonesian islands by April 1984.

Aided by the World Bank and other donors, Indonesia has committed more than $4 billion to the program since 1976. For the 1983-84 fiscal year, Martono said he hopes at least to match the current year's transmigration budget of $725 million.

Besides its goals of correcting the overpopulation on Java, the transmigration program also has political and security ramifications. One of the resettlement sites is Natuna Island, which Martono noted was 600 miles from Jakarta but only 450 miles from Vietnam.

Martono said a community of farmers, fishermen and soldiers was being built up on the island to turn it into a forward line of defense. The island is also important because it lies 130 miles southwest of one of the world's largest offshore natural gas reservoirs, which Indonesia plans to exploit in the future.

Asked if Vietnam has claimed Natuna Island, Martono replied with a laugh, "Not yet."

Transmigration also is being employed to help crush rebellions on outer islands. Another target of the program is Irian Jaya, the Indonesian half of the island formerly called New Guinea. The eastern half is the independent state of Papua New Guinea, where guerrillas of the small Free Papua Movement sometimes take refuge in their sputtering war against Indonesian troops.

Western diplomats estimate that about 300 poorly equipped fighters remain in the jungles near the Papua New Guinea border, many of them tribesmen armed only with bows, arrows and spears. Some of their supporters have criticized the transmigration program as being aimed at diluting the Melanesian character of the province.

Some critics attribute similar motives to an incipient transmigration program for the former Portuguese colony of East Timor, which Indonesia invaded in 1975. About 100 families of rice farmers from Bali have been sent to East Timor to help develop agriculture, and initial plans are to send 400 more when further resettlement areas are built. The Balinese are to be integrated with East Timorese families evacuated from areas where independence-seeking guerrillas are active.

According to Martono, transmigration is a high priority because the government hopes it also will increase food production in this nation where about half the 150 million residents live below the poverty line. He said there are currently 6 million landless farmers on Java and Bali and 7 million farmers who own less than 1 1/4 acres. The average farm on the two islands, he said, consists of less than one acre.

In the transmigration program, Martono said, each family is transported by the government to the resettlement site and given a house, five acres of land, some farm equipment and food assistance for up to 18 months.

The cost of the program, he said, comes to about $5,000 per family, which on average consists of five persons.

"Not all the sites are successful," Martono acknowledged. Some have been abandoned when the farmers could not make a living. Disease reportedly also has claimed a number of lives in remote, jungle areas.

Martono said, however, that fewer than 5 percent of the settlements were failures and that he was "very optimistic" about reaching the target of resettling 500,000 families in the 1979-84 five-year plan.

A major obstacle is a strong Javanese attachment to ancestral lands. This was illustrated when Mount Galunggung volcano began erupting in April, forcing more than 40,000 people to evacuate their homes and covering thousands of acres of farmland with ash. Although their land now is barren in many cases, most of the evacuees have been unwilling to move.

"It's very difficult to leave Java," Martono said