On Feb. 13, 2002, John McCain and I were standing in a crowded room next to the chamber of the U.S. House of Representatives when the senator yelled, “Quiet down!”

A monitor showed the floor debate over “Shays-Meehan,” shorthand for a campaign finance law I had introduced in the House with my Republican colleague Christopher Shays. The Senate version of it would come to be known as “McCain-Feingold.” Rep. John Lewis, the Georgia Democrat who had become a national figure as a civil rights activist in the 1960s, was speaking in strong support of the bill, and Senator McCain wanted to hear him.

When the congressman finished, the senator leaned over to me and said, “Marty, we’re lucky we get to serve with the likes of John Lewis. That’s what makes this institution so great.”

I have since left Congress and now serve as president of the University of Massachusetts. As I reflect on my relationship with Senator McCain, who on Saturday lost his long battle with brain cancer, I realize there are several lessons students can learn from his remarkable life and legacy.

Nonpartisan statements of values l have been largely lost from our national dialogue.

First, you define your own values.

Of course, John McCain is best known for his “maverick” streak of independence, reaffirmed last summer when he broke from his party to vote against a “skinny repeal” of Obamacare, the signature legislative accomplishment of his onetime opponent for the presidency.

During that 2008 presidential campaign, a woman at one of Mr. McCain’s town hall meetings suggested that Barack Obama did not have the country’s interests at heart. “No, ma’am. He’s a decent family man and citizen that I just happen to have disagreements with on fundamental issues,” Mr. McCain bluntly told the woman, one of his likely voters.

Ten years later, direct, nonpartisan statements of values like that have been largely lost from—or drowned out of—our national dialogue. Our next generation of leaders can change that.

Second, challenge the status quo with superior ideas.

John McCain was a famously rambunctious student at the U.S. Naval Academy, where he graduated fifth from the bottom of his class. Later in life, after he was already a war hero and had embarked on his political career, he learned to channel his anti-establishment streak.

Never sacrifice your dignity or integrity for short-term gain.

The senator and I came together because we both saw the corrosive effects of money on our government. He wanted to disrupt our campaign finance system not just for the sake of change but because it was the right thing to do to preserve the integrity of our elections. His powerful advocacy for legislation that many of our colleagues thought ran counter to their interests made all of the difference.

Senator McCain demonstrated that challenging the status quo works best when you are able to articulate why your approach is the better one.

Third, consider now how you want to be remembered.

John McCain’s son and namesake, Navy Lieutenant Jack McCain IV, wrote an eloquent tribute in which he explained how his father survived more than five years as a prisoner of war in Vietnam, “suffering gravely for refusing early release,” because he wanted to return home with honor. As the senator himself would later tell the midshipmen at his alma mater, his embrace of honor came from a powerful force: the dread of dishonor.

Today’s college students belong to what I believe is our brightest and most talented generation but one raised with social media, where nothing is valued more than eliciting a reaction. John McCain’s example is that no matter your age, your life story is already being told. Never sacrifice your dignity or integrity for short-term gain.

As our next generation of leaders, college students will have to tackle our nation’s most pressing issues. I hope they will look to John McCain’s life and six decades of service for inspiration.

Martin Meehan is the President of the University of Massachusetts. He served in the United States House of Representatives from 1993 to 2007 as the Representative for Massachusetts's 5th congressional district.