A unanimous Supreme Court sang "Happy Birthday" yesterday at a surprise party for Justice William J. Brennan Jr., the court's oldest, longest-sitting justice and leading liberal.

The justices and some 200 court employes followed with a rendition of "For He's a Jolly Good Fellow" and lengthy applause before cutting a giant cake in the court's ornate East Conference Room.

Brennan, who turns 80 today, was at a momentary loss for words.

"I guess I'm supposed to say something," he said. "And I thought turning 80 wouldn't be any fun." The affable Brennan worked the room for nearly an hour, shaking hands with his male colleagues and kissing the court's only female justice, Sandra Day O'Connor.

President Dwight D. Eisenhower once said that appointing Brennan to the court was the second biggest mistake he ever made. (The late Chief Justice Earl Warren was the first on that list.) Thirty years later, Brennan, the son of Irish immigrants, becomes only the seventh sitting octogenarian in the court's history, according to the court's news officer.

Brennan, who rides an exercise bicycle for 30 minutes every morning and has the handshake of a dockworker, says he has no intention of quitting as long as his health holds out. He had a medical checkup last week and says his health is "first-rate."

For six years observers have predicted that President Reagan would be able to fill several vacancies on the aging court. Five of the justices are over 76: Chief Justice Warren E. Burger and Justice Lewis F. Powell are 78; Justices Thurgood Marshall and Harry A. Blackmun are 77.

Conservatives, who often single out Brennan as the archetypal liberal "activist," were hopeful that either he or fellow liberal Marshall would be among those to retire.

So far, however, there has been only one vacancy -- O'Connor in 1981 replaced Justice Potter Stewart -- and none of the older justices is giving any indication of a voluntary retirement in the near future.

In the late 70s Brennan spoke of retiring. Friends said he seemed tired. He was treated in 1978 for a cancerous tumor in his throat and suffered a mild stroke in 1979.

But he has been healthy since then, and he says he hasn't slowed. Alone among his colleagues, he still personally reviews all of the thousands of petitions that come to the court. Other justices have their clerks screen the petitions.

"I always give at least half a day on Saturday" to reviewing petitions, Brennan said in a recent interview, and "sometimes a good deal more than that. But it's never been any different for me. When you have been here as long as I have and you've had so many of these damn things to look at, it's not too hard a job."

And Brennan's memory remains formidable. He illustrated by rattling off a string of cases from the 1950s to demonstrate a point.

Brennan's views have been consistently liberal throughout his three decades on the court, but his role has changed dramatically.

Brennan's task for 13 years under Chief Justice Earl Warren was to create a consensus on the court to extend the basic protections of the Bill of Rights to the states. He built an impressive record, authoring some of the most important decisions of the Warren court and rarely finding a need to dissent.

During the last 17 years under Burger, however, his role has been to preserve the legacy of the Warren court. There, too, he feels that effort has been largely successful, though he now dissents from a third of the court's approximately 150 opinions each year.

"The only one [amendment] that [the Burger court] has gone drastically far" in limiting is the Fourth Amendment, Brennan said. The high court has consistently cut back in recent years on the "exclusionary rule" which prohibits the use of illegally obtained evidence in court. Brennan feels that rule is the "warp and woof of the Fourth Amendment," which protects individuals from unreasonable searches.

Those protections have begun to "unravel" Brennan said. "When I got here it was unraveled and then with [several key rulings] we put it back on its feet and now its being unraveled again, I'm afraid."

One area in which Brennan's efforts have been to no avail has been the death penalty. Brennan and Marshall stand a lonely vigil on the court against capital punishment.

Brennan, always the optimist, says "someday that may fall. After all, 'separate but equal' went down the drain with Brown v. Board of Education. I can give you any number of instances," he said, "when better knowledge and wisdom" dictate overturning prior rulings.

Winning or losing, Brennan seems able to maintain cordial relations with all the justices. "In 30 years I've sat with 20 justices," Brennan recalled, "the original eight, all of whom are dead," four others who have come and gone, and the current court. "I have never had a cross word with any of the 20, not one. My personal relations with everyone have been most cordial and amiable, however different our views."