MIDDLETOWN, Conn. -- Hundreds of diplomas were handed out Sunday at Wesleyan University, and one baton was passed.

Barack Obama agreed last week to fill in for Edward M. Kennedy as Wesleyan's commencement speaker after his fellow Democratic senator was found to have a cancerous brain tumor.

Obama, whose legions of young supporters have already recalled memories of John F. Kennedy's idealistic followers in the early 1960s, explicitly invoked JFK's New Frontier, as well as the rest of the Kennedy family, as he exhorted the Wesleyan graduates to dedicate themselves to public service.

"I was born the year that . . . John called a generation of Americans to ask their country what they could do. And I came of age at a time when they did it," Obama said. He concluded that today's students should likewise consider giving themselves to a broader cause because "you have an obligation to yourself."

"Because our individual salvation depends on collective salvation," he added. "Because thinking only about yourself, fulfilling your immediate wants and needs, betrays a poverty of ambition. Because it's only when you hitch your wagon to something larger than yourself that you realize your true potential and discover the role you'll play in writing the next great chapter in America's story."

The speech bore strong echoes of Obama's campaign message, though his call for voluntarism and service differed in one key regard. On the stump, Obama gets big applause by saying he would as president offer all college students a $4,000 tax credit to help pay for school -- but only if they commit to public service, such as the Peace Corps or teaching in an inner-city school or working in a homeless shelter.

But he argued Sunday that public service should be unbidden. "Each of you will have the chance to make your own discovery in the years to come. And I say 'chance' because you won't have to take it," he said. "There's no community-service requirement in the real world, no one forcing you to care. You can take your diploma, walk off this stage, and chase only after the big house and the nice suits and all the other things that our money culture says you should buy. You can choose to narrow your concerns and live your life in a way that tries to keep your story separate from America's. But I hope you don't."

Near the close of the speech, he made the link between himself and John Kennedy most explicit -- and in the process voiced some of the increased confidence he has been showing about his chances as the likely Democratic presidential nominee.

"You know, Ted Kennedy often tells a story about the fifth-anniversary celebration of the Peace Corps. He was there, and he asked one of the young Americans why he had chosen to volunteer. And the man replied, 'Because it was the first time someone asked me to do something for my country,' " Obama said. "I don't know how many of you have been asked that question, but after today, you have no excuses. I am asking you, and if I should have the honor of serving this nation as president, I will be asking again in the coming years."