PISCATAWAY - President Barack Obama told Rutgers University graduates that the pace of change in the world is accelerating, not subsiding.

A crowd of more than 50,000 people were at High Point Solutions Stadium as the president delivered the commencement address. It was the second of three commencement speeches Obama will give this year, making it among of the last he's expected to give in office.

The president urged graduates to shun those who want to confront a rapidly changing world by building walls around the United States or by embracing ignorance, as he delivered a sharp and barely concealed critique of Donald Trump.

Looking out at a sea of red and black gowns, Obama told the roughly 12,000 graduating students that recent history had proved that the toughest challenges cannot be solved in isolation.

"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.

In his speech, Obama also 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."

"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.

Obama was the first sitting president to give the commencement address at Rutgers. The school is bestowed an honorary law degree on the president.

The university reportedly put the request for Obama to speak in nearly three years ago, in anticipation of the school's 250th anniversary.

Rutgers officials say heightened security measures were in place for the president’s visit, and they released a list of banned items ahead of time.

Traffic around the campus was expected to heavy and motorists were urged to avoid the area.

AP wire services contributed to this report.