President Obama took several sharp swipes at Donald J. Trump on Sunday during a commencement address that could be the beginning of a forceful effort to help elect a Democratic successor as president.

Addressing Rutgers University’s class of 2016 at the school’s 250th anniversary commencement, Mr. Obama never mentioned Mr. Trump by name. But his target was clear, and his assessments earned raucous cheers from the graduates.

“The world is more interconnected than ever before, and it’s becoming more connected every day,” Mr. Obama told the graduates. “Building walls won’t change that.”

Mr. Trump, the presumptive Republican presidential nominee, has proposed building a wall between the United States and Mexico and forcing Mexico to pay for its potential multibillion dollar construction costs. Mr. Trump has also denounced much of the modern international trading and economic system, and he has proposed banning Muslim visitors and immigrants from the country, at least temporarily — all ideas Mr. Obama condemned on Sunday.

But Mr. Obama is altering his stump speech in important ways to go after Mr. Trump. As his remaining time in office draws to less than a school year, Mr. Obama has alternated between mild and mock horror, pointed humor and a touch of disbelief in his attacks on the Republican front-runner.

“We live in an age of global supply chains, and a lot of folks have legitimate concerns with the way globalization has progressed,” Mr. Obama said. “But the answer isn’t to stop trading with other countries. In this global economy, that’s not even possible.”

Mr. Obama said that isolating and disparaging Muslims was not only a betrayal of American values but “would alienate the very communities at home and abroad who are our most important partners in combating violent extremism.”

Wearing a crimson robe with black sashes and a purple doctoral hood that a fierce wind kept blowing off his shoulders, Mr. Obama told the graduates that the knowledge they had earned through years of studying was something they should insist political leaders value and possess themselves.

“Facts, evidence, reason, logic, an understanding of science — these are good things. These are qualities you want in people making policy,” Mr. Obama said, adding later, “In politics and in life, ignorance is not a virtue.”

Mr. Obama seemed to especially take pleasure in advocating the use of facts in politics while speaking to an academic audience. His point with such arguments is usually to press for action against climate change, one of the signature policies of his administration and one that nearly all climate scientists support.

But while Mr. Obama mentioned climate change, he also used his points about facts and experience to take yet another swipe at an unnamed Mr. Trump.

He noted that when people get sick, they want an experienced doctor to treat them; when they fly, they want experienced pilots.

Mr. Trump has no experience as a politician, a quality that has been viewed as one of the most important reasons for his success as a presidential candidate.

Mr. Obama came to Rutgers after students, faculty members and even relatives of students spent the past three years lobbying the White House for him to speak on this anniversary for the school.

“The truth is, Rutgers, I came here because you asked. You are the first to launch a three-year campaign,” he said. “Emails, letters, tweets, YouTube videos. I even got three notes from the grandmother of your student body president,” Mr. Obama said, drawing laughter. “And I have to say that really sealed the deal. That was smart because I have a soft spot for grandmas.”

But Mr. Obama made clear that Rutgers was precisely the kind of institution that he wanted to celebrate. Last week, Mr. Obama spoke at the commencement of Howard University, a historically black university, and told the next generation of black leaders that passion must be tempered by strategic thinking and a willingness to compromise.

Rutgers, one of the first nine government-chartered institutions in the American colonies, “could be the most diverse student body in America,” he said. And he likened Rutgers’ long history of success with that of the country as a whole.

aucune période de l'histoire n'est aussi prospère que (la nôtre)

And while he celebrated that history, he made clear to the graduates that no period in history was as prosperous as this one.

“The good old days weren’t all that good,” Mr. Obama said. “In fact, by almost every measure, America is better and the world is better than it was 50 years ago or 30 years ago or even eight years ago.”

One of Mr. Obama’s frustrations during his presidency has been the country’s persistently sour mood despite what he sees as a remarkable turnaround in the nation’s economy, the passage of wide-ranging health care legislation and the nation’s pre-eminent strength militarily.

He cited those accomplishments and many others, including declining rates of crime, teenage pregnancy and poverty, as well as improvements in life expectancy, the status of blacks and Latinos and clean energy.“Marriage equality is the law of the land,” he added, to robust cheers.

As he often does in such speeches, Mr. Obama told the graduates that they needed to participate in the political process and be satisfied with incremental change. Democrats generally fare better than Republicans in high-turnout elections, and while young people overwhelmingly support Democrats, they rarely vote. So Mr. Obama and Michelle Obama, the first lady, always urge student audiences to show up at the polls on Election Day.

“Because apathy has consequences,” the president said.

He said changes, even small ones, were worth fighting for.

Ne gaspillez pas votre temps à attendre

“I always tell my daughters, ‘Better is good,’” Mr. Obama said near the end of his speech, adding, “Don’t waste your time waiting.”