Tokyo — Seventy-four years after Japan's defeat in World War II, the world's third-largest economy is in the midst of a quiet military buildup, at U.S. urging. President Trump's visit to Japan over Memorial Day weekend will culminate with him becoming the first U.S. president in modern history to set foot on a Japanese warship.

Mr. Trump will tour the JS Kaga, one of the two largest warships in Japan's Maritime Self-Defense Force. In a controversial move, Tokyo recently decided to refit the Kaga and a sister ship to carry F-35B Strike Fighters — effectively creating Japan's first aircraft carriers since World War II, the first since the attack on Pearl Harbor.

Now, after almost 75 years of peace, Mr. Trump's visit will be seen as a display of military solidarity that has long been sought by Japan's leaders. Professor Stephen Nagy, international relations scholar at Japan's International Christian University, said he thinks the photo-op is intended as much for the American public as for Japan's neighbors China and North Korea.

Get Breaking News Delivered to Your Inbox

"Over the past two years, three years, President Trump has conveyed a message that alliance partners really are leeching off the United States," Nagy said. "Prime Minister (Shinzo) Abe would like to send a strong signal that no, that's not the case, that the Japanese people and the Japanese Self-Defense Forces are stepping up to the plate and are contributing to security within the region."

An aerial photo shows the JS Kaga of Japan's Maritime Self-Defense Force entering Osaka Port in Osaka on May 19, 2018. The Yomiuri Shimbun via AP Images

This spring, nearly 400 troops were deployed to the tiny island of Miyakojima, about 100 miles from the Senkaku-Diaoyu islands held by Japan but claimed by China. More troops and missile units are set to follow.

All told, Japan is on track to spend a record $47 billion on defense this year amid increasingly aggressive sea and air incursions by China and continuing provocations from North Korea. While Japan spends more than most countries on its defense and has been a major military power since at least the 1980s. Nagy said it's not rearming.

"This idea of a militarized Japan or remilitarizing, it makes no sense considering the demographics in Japan, the reality that its economy is going to decrease in size in the coming years because of demographics, that the kind of defense that it will need will be a defensive military," Nagy said.

As the only target of an atomic bombing, Japan has held firm to its so-called "pacifist constitution" and a policy that diplomacy, not force, must be used to settle disputes with other countries. "Having experienced Hiroshima and the destruction of World War II, we must preserve our peace constitution," said one woman, Ayumi Omura.

The centerpiece of Japan's defense is a string of U.S. bases and about 50,000 American troops. Japan pays more than $5 billion to host U.S. forces, far more than any other American ally.

But with Washington questioning the value of its alliances, Japanese for the first time are voicing anxiety about the U.S. security commitment to their country. "I don't think the U.S. will defend us if we're under attack," said businessman Kenta Okawa. "Trump's policy keeps changing. I don't see any long-term vision from him. He just puts on political performances to get votes."

During the summit, Japan likely will be asked again to spend more on the alliance — and for the sake of unity, it's expected to send Mr. Trump home with a win.