Obama, delivering the commencement address at the Navy-Marine Corps Memorial Stadium in Annapolis, Md., reminded the new officers "the misconduct of some can have effects that ripple far and wide."
He urged the graduates to do four things: "Live with integrity, and speak with honesty, and take responsibility and demand accountability. We need your honor and we need your courage."
Americans' trust in public institutions has been falling recently because of actions by a few individuals and work must be done by "everybody" to restore that trust, he said.
"As you go forward in your careers, we need you to carry forth the values that you've learned at this institution. ... We need your honor, that inner compass that guides you, not when the path is easy and obvious, but it's hard and uncertain, that tells you the difference between that which is right and that which is wrong," Obama said. "Perhaps it will be the moment when you think nobody's watching. But never forget that honor, like character, is what you do when nobody's looking."
The Pentagon released a report in May estimating the number of military personnel sexually assaulted or victimized by related crimes surged about 35 percent in two years despite intensive efforts to confront the problem, with as many as 26,000 military members having been sexually assaulted last year.
"Those who commit sexual assault are not only committing a crime, they threaten the trust and discipline that makes our military strong," Obama said. "That's why we have to be determined to stop these crimes. Because they've got no place in the greatest military on Earth."
While saying he couldn't promise a "life of comfort and ease" for the class of 2013, Obama said, "But I do know this ... you're becoming the newest link in a storied chain.
"And I'm absolutely confident that you will uphold the highest of standards and that your courage and honor and your commitment will see us through," Obama concluded, "and that you will always prove yourselves worthy of the trust our nation is placing in you today."