It was shortly before midnight when Christina Bota and her 12-year-old son, Alexis, arrived at a New York City shelter for homeless families. She was frightened and in tears - the memory of her ordeal fresh in her mind.

An ex-convict, enraged at his girlfriend for living with another man while he was in prison, had hurled a gasoline bomb at 3 a.m. through a window of the apartment house where the Botas lived. Their fourth floor apartment was one of five rendered uninhabitable by the blaze. When the rent for a replacement proved too steep, the choice soon became stark: A homeless shelter or the streets.That was almost two years ago. Now, as other families in the Catherine Street shelter prepare for Christmas, the Botas are preparing to move into a permanent new home in the Bronx - a three-room white-carpeted apartment with a bright new kitchen.

Once abandoned, the apartment was renovated as part of a massive $5.1 billion program begun by New York City to create 252,000 apartments over the next decade for the homeless and for low-, moderate- and middle-income residents. The program, in its ambition and scope, is unprecedented on the national urban landscape.

"It's a beautiful Christmas present," Bota said as she prepared to pack her few belongings for the move.

Planners believe the housing initiative and a host of smaller programs - some of which are aimed at preventing homelessness before it occurs - will be major steps in reducing New York's huge homeless population.

Already, while the homeless problem continues to grow in many other cities, in New York there is cautious good news. After years of steep increases, the homeless population here appears to be leveling off, and a significant segment - homeless families - appears to be declining.

The number of families in shelters and hotels has dropped since March from 5,245 to 4,719, while the number of single people who are homeless has remained stable, rising only from 10,380 in January to 10,394 in December.

Officials concede it is impossible to count all the homeless, especially those who sleep in subways, streets and doorways. But they express cautious optimism, even though on most nights some 27,000 people receive shelter from the city.

"Our initiatives have, I believe, helped turn the corner on homelessness in our city," Mayor Edward I. Koch said in remarks submitted recently to an ad hoc congressional task force considering homelessness and housing. "In the last year, fortunately, the growth of the number of homeless single adults seems to have slowed, and the pattern that had spiraled steadily upward for many years appears to have stabilized."

Other municipal officials said a number of efforts may be beginning to pay dividends.

"I think there is a combination of several things. We have considerably increased our efforts at prevention of homelessness over the past several years," William J. Grinker, commissioner of the city's Human Resources Administration, said in an interview.

"That includes paying rent arrears to prevent evictions, having people stationed in Housing Court so that if a family is liable to be evicted, it can be dealt with . . . having an early warning system where we identify factors that are likely to cause homelessness through our income-maintenance system."

Case workers have found that when welfare families occupy several residences during a single year, they may be strong candidates to become homeless. By quickly identifying these families, social workers can focus resources on trying to keep them out of shelters.

Case workers also have increased services for people in homeless shelters.

At the Catherine Street shelter in the heart of Manhattan's Chinatown, classes are held in how to find apartments. A physician's assistant or a nurse practitioner always is on duty to treat health problems. Within 48 hours after family members arrive at the shelter, they are seen by a worker, who determines among other things whether they are entitled to food stamps or other benefits or should be referred to a lawyer if eviction occurred erroneously.

Board of Education personnel are stationed at the shelter to be sure children register at nearby schools.

The shelter contains a library for youngsters that is used for homework and after-school tutoring. During summers, the staff operates a day camp. A curator from one of New York's museums runs a photography workshop for the shelter's residents. Once a month, motivational speakers are brought in to try to broaden the horizons of the homeless.

Some shelter residents accept transfers to hotels or to shelters providing families with housing, often in apartment-like settings. Others may return to relatives, previously reluctant to accept them.

When a renovated apartment or a place in a city housing project becomes available, strenuous efforts are made to be sure the family does not become homeless again. Case workers will go with family members to buy furniture and household essentials, which are purchased with public assistance funds.

Once a family is settled, other case workers visit the apartment to be sure youngsters are in schools or no other problems have arisen.

"The concept is that family members will have someone to work with them to resolve any issue that may come up that will have an impact on their ability to stay in their own home," said Lawrence E. Schatt, director of the Human Resources Administration's family emergency assistance program. "The aim is to prevent them from going back onto the streets."

Nevertheless, some residents are reluctant to leave the Catherine Street shelter. As weeks pass, they find it offers a safe environment with a network of services. To prevent vandalism or more serious crimes, the shelter employs 54 guards who are assigned to round-the-clock shifts.

"We are really running a hotel with social services," said Schatt, "without all the problems associated with welfare hotels, where drug trafficking and abuse have been common."

In other shelters where single people are housed, the Human Resources Administration has started a voluntary program with the U.S. Department of Labor to provide Job Corps experience for young homeless men and women. The results are encouraging.

So far, 54 of the homeless, aged 18 to 24, are undergoing skills training at a Job Corps facility near Albany, N.Y. The dropout rate has been extremely low and the homeless are learning crafts ranging from building maintenance and word processing to auto mechanics and culinary arts.

"These people have volunteered for this," Grinker said. "They see this as the last chance, a last hope opportunity and they want to take advantage of it.'

The Human Resources Administration is working to be sure jobs are available for the trainees when they return to New York City.

The agency's research shows that only about 5 percent of homeless families are recent migrants to New York City. Most lived for a time in run-down neighborhoods, and only about one-fifth of families had their own apartments just before becoming homeless. Most were doubled up with friends and relatives and often paid no rent. Housing instability was a way of life. Only 21 percent of families studied lived at the same address for the previous two years; 55 percent had two addresses and 24 percent, three or more. Before entering a family shelter, the vast majority unsuccessfully sought other living arrangements.

Using these statistics, case workers have been able to spot vulnerable families and have concentrated efforts to keep them from becoming homeless. Human Resources Administration workers have formed experimental liaisons with the city's Housing Court judges in an effort to prevent evictions.

Clearly, the new statistics showing that New York City's homeless population may be stabilizing have cheered the administration of Mayor Koch. But social services supervisor Edith Grinker warned that they must be cautiously interpreted.

"Until we have the problem licked, it is too early to call it a Christmas present," he said. "But at least it is a glimmer of hope."