It is as true today as it has been throughout history: China and Japan have as many reasons to be friends as to be enemies. And that is why, in the decades since they established diplomatic ties in 1972, their relationship has seen as many highs as it has lows.

The enactment of the Treaty of Peace and Friendship between Japan and China on October 23, 1978, was one such high. Ending almost a century of enmity, it heralded a new era of relations, and was the culmination of a historic meeting in Tokyo between China’s then-paramount leader, Deng Xiaoping, and Japan’s then-prime minister, Takeo Fukuda.

As Beijing squeezes Taiwan, Trump gives Tsai warm embrace

The goodwill progressed further when, in November 1983, Chinese Communist Party Secretary Hu Yaobang and Japanese Prime Minister Yasuhiro Nakasone agreed to establish the New Japan-China Friendship Committee for the 21st Century.

Underpinning these accords were ancient bonds and similarities – geographical proximity, shared customs, culture and religion as well as a history of bilateral exchanges stretching back to the Tang dynasty. They were also based on shared geopolitical interests: both nations saw the Soviet Union as their chief threat during the cold war era.

The friendship gained new momentum when Deng began opening up China in the early 1980s, a time when China was sorely in need of Japanese funding and technology. Tokyo’s generosity during this period was partly due to the chasm in economic development that had opened between the two neighbours. Japan was an industrial power, while China was still crawling out from its third-world cave.

But its generosity had another, darker, aspect. It was driven at least in part by a desire to make amends for the immense suffering of the Chinese during the Japanese invasion in the second world war.

While the two countries have had mostly cordial relations since the third century BC, they were at war for half a century from 1894 to 1945.

Trump, China and Europe: one enemy at a time please

And since the dawn of this millennium, their differences have again begun to simmer. They have been at odds over historic perceptions (including of the war), territorial disputes and national-security policies. These spats have come as both seek to redefine their roles amid a rapidly changing geopolitical environment. In recent years, relations plunged following a string of hostile encounters regarding the disputed Diaoyu Islands – known as the Senkakus in Japan – in the East China Sea.

Still, there is room for optimism. Beijing and Tokyo have seen an apparent entente following Chinese Premier Li Keqiang’s visit to Tokyo in May, the first in seven years by a top Chinese leader. Japanese Prime Minister Shinzo Abe and Chinese President Xi Jinping are now preparing for official visits to each other’s countries to celebrate the 40th anniversary of the friendship treaty amid rising global uncertainties.

Beijing has become eager to improve ties with Tokyo in the face of US President Donald Trump’s desire to contain China. But much has changed in the past 40 years. Not only has China overtaken Japan to become the world’s second-largest economy, but Beijing has shifted away from its long-held “low key” strategy towards an increasingly assertive diplomacy. The two Asian giants are now chief rivals, competing for everything from regional domination to global influence. And the tensions are unlikely to ease because of increasingly striking differences over ideology, values, political systems, and geopolitical considerations.

By snubbing China in Rimpac, US plays a dangerous war game

Beijing may be eager to woo Tokyo to drive a wedge between Japan and the United States. But the truth is Tokyo is even more passionate than Washington about containing China.

Abe influenced Washington’s stance on a “free and open Indo-Pacific” – a vision that is as much about counterbalancing China’s growing assertiveness as it is about anything else. As the saying goes: keep your friends close, your enemies even closer.

Cary Huang, a senior writer with the South China Morning Post, has been a China affairs columnist since the 1990s