PISCATAWAY, N.J. (CBSNewYork/AP) — President Barack Obama on Sunday urged college graduates to shun those who want to confront a rapidly linked world by building walls around the United States or by embracing ignorance, as he delivered a sharp and barely-concealed critique of Donald Trump.

As CBS2’s Steve Langford reported, there were long lines, tight security, and unusual cold this graduation day at Rutgers University. But the arrival of Marine One heralded the special guest for the 250th anniversary commencement.

“Truth is, Rutgers, I came here cause you asked,” Obama said.

The president told Rutgers grads their emails, letters, tweets, YouTube videos and a plea from the grandmother of the student body president convinced him to be here.

“America converges here, and in so many ways the history of Rutgers mirrors the evolution of America,” he said.

But Obama did not come just to flatter. He had, he said, some suggestions.

“America’s progress has never been smooth or steady,” Obama said. “Progress doesn’t travel in a straight line.”

Obama used the speech to illustrate a world view antithetical to the ideas espoused by the presumptive Republican presidential nominee. Looking out at the sea of red and black gowns, Obama told the roughly 12,000 graduating students that the pace of change on the planet is accelerating, not subsiding, and that recent history had proved that the toughest challenges cannot be solved in isolation.

PHOTOS: Obama Gives Commencement Address

“A wall won’t stop that,” Obama said, bringing to mind Trump’s call for building a border wall between the U.S. and Mexico. “The point is, to help ourselves, we’ve got to help others — not pull up the drawbridge and try to keep the world out.”

The president never mentioned Trump by name, but his intended target seemed clear. Repeatedly, Obama referred to disparaging comments about Muslims and immigrants, and opposition to free trade deals. But he appeared most incensed by what he described as a rejection of facts, science and intellectualism that he said was pervading politics.

“In politics and in life, ignorance is not a virtue,” Obama said. “It’s not cool to not know what you’re talking about. That’s not keeping it real or telling it like it is. That’s not challenging political correctness. That’s just not knowing what you’re talking about,” the president said.

“And yet, we’ve become confused about this,” he continued, warning that the rejection of facts and science would lead the U.S. on a path of decline.

Obama’s rebuke came as Trump is gaining momentum, raising the prospect that a Republican victory in November that would mean a reversal of Obama’s policies and approach to governing. In recent days, Trump has started focusing on the general election while working to unite a fractured Republican Party around his candidacy. Democrats are readying for a fight against a reality TV host they never anticipated would make it this far.

1010 WINS’ Roger Stern reported Obama told the graduates that it is young people who have moved this nation forward.

“We didn’t fear the future. We seized the future and made it our own and that’s exactly why it’s always been young people like you that have brought about big change,” Obama said.

Obama has mostly steered clear as Democrats Hillary Clinton and Bernie Sanders compete for the nomination. But he has used speeches such the Rutgers address to lay out themes that the nominee may pick up on as the Democrats work to deny Trump the White House.

New Jersey Gov. Chris Christie, who ran against Trump for the GOP nomination, has since endorsed him and become one of his most vocal surrogates. Christie didn’t attend the president’s speech at Rutgers, instead spending the day at nearby Princeton University for his son’s baseball game in the Ivy League championship.

In his speech, Obama told graduates that when they hear people wax nostalgic about the “good old days” in America, they should “take it with a grain of salt,” and adding that “the good old days weren’t all that good.”

“Guess what? It ain’t so,” the president said, rattling off a list of measures by which life is better in the U.S. than in decades past.

But Obama’s speech also had lighter moments, with the president working for laughs from a crowd full of Jersey pride.

“I come here for a simple reason, to finally settle this pork roll vs Taylor ham question,” Obama said. “I’m just kidding.”

He also said, “As Bruce Springsteen once said, they spend their lives waitin’ for a moment that just don’t come.”

In total, Obama spoke for 43 minutes. He seemed to have received a good reception, Langford reported.

“It was amazing,” one man said. “I was really inspired.”

“It was awesome to have him here,” a woman said. “It’s the 250th. To have the 44th president here has been an honor. It’s something I’ll never forget.”

But some were not so ecstatic.

“It was an honor to have him here, but at the end of the day… it was just an attack on Trump,” a man said.

Some 50,000 students and their families packed High Point Solution Stadium for the ceremony, the first at Rutgers to involve a sitting president. The public university’s leaders lobbied the president for years to come to campus for the school’s 250th anniversary, and Obama praised the school for its diverse student body and research programs.

Sunday’s address was the second of three commencement speeches that Obama will deliver during his final graduation season as president. Earlier in May, Obama told graduates at historically black Howard University that the country is “a better place today” than when he graduated from Columbia University more than 30 years ago. The president will also speak on June 2 at the U.S. Air Force Academy in Colorado Springs, Colorado.

The university also bestowed an honorary law degree on the president, adding to the half-dozen or so other honorary degrees that the Columbia and Harvard Law School graduate has received.

(TM and © Copyright 2016 CBS Radio Inc. and its relevant subsidiaries. CBS RADIO and EYE Logo TM and Copyright 2016 CBS Broadcasting Inc. Used under license. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press contributed to this report.)