But Obama says it is time for a new foreign policy that relies on more carrots and fewer sticks, an approach McCain calls naive. And their disagreement on the key issue of national security begins with the war in Iraq.
Republican presidential candidate McCain supported the invasion of Iraq in 2002 but disagreed with the combat strategy until last year's troop buildup, the so-called surge, reduced violence considerably. And he says it is now time to finish the job with enough troops and no timetable for withdrawal.
"This strategy has succeeded and we are winning in Iraq, and we will come home with victory and with honor," McCain said.
Democrat Obama's been against the war from the beginning, arguing the real enemy is al Qaeda and the Taliban in Afghanistan. He said he wants to pull the troops out over the next 16 months at a rate of one or two brigades a month.
"When the war started, you said it was going to be quick and easy. You said we knew where the weapons of mass destruction were. You were wrong. You said that we were going to be seen as liberators. You were wrong," Obama said.
The candidates agree on the need for additional troops in Afghanistan. But they don't agree on how to handle other nations in the region, like Pakistan, which is now a hotbed or terrorism.
"Our relations with Pakistan are critical because the border areas are being used as safe havens by the Taliban and al-Qaeda and other extremist organizations and we have to get their support," McCain said. "By working and coordinating our efforts together, not threatening to attack them."
"If we have Osama bin Laden in our sights and the Pakistani government is unable or unwilling to take them out, then I think that we have to act, and we will take them out. That has to be our biggest national security priority," said Obama.
The national security fireworks also extend to some other diplomatic issues, like whether to negotiate face-to-face and without pre-conditions with anti-American leaders, like Iran's president Ahmadinejad.
"I reserve the right, as president of the United States, to meet with anybody at a time and place of my choosing if I think it's going to keep America safe," said Obama.
"What Senator Obama doesn't understand is that without preconditions, you sit down across the table from someone who has called Israel a stinking corpse and wants to wipe that country off the map. You legitimize those comments. This is dangerous," McCain said.
McCain's approach to foreign policy is similar to the Bush administration, which means a relatively hard line toward Russia, Iran, Venezuela and North Korea. Obama says you have to talk to the leaders of those countries and provide financial assistance to their neighbors if you ever expect to turn enemies into friends.
Both candidates are promising to protect Israel against aggression from Arab militants. But they support the creation of a Palestinian state after Palestinians renounce terrorism and recognize Israel's right to exist.