COLORADO SPRINGS — President Obama on Thursday used his final commencement address to a United States military academy to urge Air Force cadets to find the right balance between force and diplomacy as they join the ranks of the country’s armed forces.

Facing 812 cadets in blue-and-white dress uniforms, Mr. Obama told the Air Force Academy’s class of 2016 that they must not allow the United States to turn away from the world, calling the isolationist rhetoric of some politicians a “false comfort” that undermines the country’s leadership in the world.

Instead, he said, the Air Force and other branches of the military must be willing to engage the country’s arsenal in defense of America and on behalf of its allies. Mr. Obama recounted the many terrorists, including Osama bin Laden, who have been killed or captured because of his willingness to deploy force.

“The list goes on because if you target Americans, we will find you and justice will be done and we will defend our nation,” Mr. Obama said, prompting some applause from the cadets and a stadium filled with their friends and family.