BEIJING — Chinese economic reformer Deng Xiaoping traveled to Tokyo exactly 40 years ago this week to mark the signing of the Sino-Japanese Peace and Friendship Treaty, as the two countries attempted to put the memories of wars behind them.

“In the present turbulent situation, China needs friendship with Japan and vice versa,” Deng told the Japanese prime minister at the time, between visits to high-tech factories and marveling at Japan’s bullet trains.

Four decades later, China has overtaken Japan as the world’s second-largest economy and is producing high-speed trains of its own. But the same thoughts may well be running through President Xi Jinping’s mind today.

Now, in the middle of an increasingly bitter trade war with the United States, Xi will on Thursday welcome Japanese Prime Minister Shinzo Abe for their first bilateral meeting in more than seven years.

“For the first time for a very long time, Chinese leaders are looking for a positive relationship with Japan,” said Yun Sun, a China expert at the Stimson Center in Washington, D.C. “With Trump in power, both Japan and China are feeling the heat coming from the U.S. It changes their calculations,” she said. 

Xi will host Abe at a reception, attended by about 500 Japanese business leaders, in Beijing’s opulent Great Hall of the People on Thursday night, for a celebration marking the 40th anniversary of the treaty.

Then they will have a day of meetings Friday during which they will pledge to work together on economic cooperation projects in countries such as Thailand. They expected to reach agreements on more than 30 such infrastructure projects. 

It’s a far cry from 2014, when friction over a group of disputed islands in the East China Sea raised fears the two countries would become involved in a military conflict. Japanese companies pulled out of China in droves, and the two leaders had a famously awkward encounter at an APEC meeting. 

But over the past year, the two countries have started to repair their relationship, at least superficially.

China’s foreign minister and premier have both visited Japan this year, and the number of Chinese tourists following suit is expected to reach a record 8 million this year. Japan was the top destination for Chinese travelers during this month’s Golden Week holiday, according to travel website C-Trip. 

Then there’s the Trump factor.

China is eagerly trying to improve economic relations with a raft of rich countries to try to reduce its exposure to the United States, where President Trump has slapped tariffs on $250 billion worth of Chinese imports and is threatening more. 

Chinese Premier Li Keqiang just came back from a trip touting Chinese market access to European companies, while Beijing is redoubling its efforts to forge a trade deal called the Regional Comprehensive Economic Partnership. There are even murmurs that China might try to join the Trans-Pacific Partnership, the 11-country trade deal that Trump pulled out of in his first week in office.

Japan, a neighbor and China’s second-biggest export market after the United States, is an important part of this diversification effort. 

China has been pressing Japanese companies to announce investment plans and deals in China during Abe’s visit, and has generally been pushing for an improvement in the relationship to offset the sharp deterioration with the United States, according to people familiar with the preparations.

This appears to be a tactical move, analysts in Tokyo say.

“Is it fundamental and long-lasting? It could just be a tactical move to deflect tensions coming from the U.S., and drive a wedge between the U.S. and Japan,” said Narushige Michishita of Japan’s National Graduate Institute for Policy Studies.

But Abe’s government is happy to go along with it for its own economic reasons. “Prime Minister Abe wishes to elevate Japan-China relations to a new level,” a Japanese government official said, speaking on the condition of anonymity to preview the sensitive visit.

China is already Japan’s largest trading partner, and more than 30,000 Japanese companies operate here, pumping more than $3.3 billion in direct investment into the country each year — and the market is only becoming more attractive.

China’s middle class totals about 250 million people, double the entire population of Japan. That represents a tantalizing opportunity for consumer goods companies in particular, like Shiseido, the skin care company.

But Japan has a tricky balancing act. Abe has poured an enormous amount of energy into developing a personal connection with Trump, and the military alliance with the United States is the cornerstone of Japan’s security.

Japan is also concerned about becoming collateral damage in the trade war. “We don’t want to see this U.S.-China trade issue damage the international supply chain,” the Japanese official said. “Japanese companies also have stakes and could be negatively affected. We hope that dialogue between the U.S. and China will lead to a diplomatic resolution of these issues.”

China’s Global Times nationalist tabloid made it clear that Abe should pay attention to how he balances his competing interests.

Japan and China could help stabilize not just Asia but the whole world, columnist Sun Xiaobo wrote. He didn’t mince his words when advising Japan to pick sides. “Japan should have a clear idea of how to deal with U.S. influence in developing its relations with China,” he wrote.

But Beijing knows where Japan’s loyalties lie, said Zhou Yongsheng, a Japan expert at China Foreign Affairs University in Beijing.

“Japan is still an ally of the U.S., and it will avoid adopting any policies that could undermine U.S. policies,” he said. “Therefore, we could expect ties to improve but the steps will not be huge.”

Regardless of the American factor, there is a limit to how much better relations can get. There are still plenty of historical issues causing frictions between the two countries.

Abe is determined to revise the pacifist constitution imposed on Japan after World War II and returning the country to a normal footing with a full-fledged military, not just “self-defense forces.” But Beijing sees this as a sign of aggression and has strongly protested Abe’s efforts to date.

There are also the continued skirmishes over the disputed islands in the East China Sea, which Japan controls but China claims. 

“I think that China understands that there is a ceiling to how good this relationship can get, but right now for both Japan and China, they realize that it’s in their interests to cooperate,” said Sun of Stimson. 

Indeed, all is not forgotten. Abe was initially supposed to arrive in Beijing on Oct. 23, the same day 40 years earlier than Deng had arrived in Tokyo. But then the Chinese government realized that another anniversary fell on Oct. 23, said author Bill Bishop, editor of the Sinocism China newsletter. That is the 150th anniversary of Japan’s Meiji Restoration, the day of the creation of the Japanese government that later rampaged through Asia, including in China.

Some anniversaries, it seems, are better left unmarked.

Denyer reported from Tokyo. Luna Lin in Beijing and Akiko Kashiwagi in Tokyo contributed to this report.