Japan has again learned by painful experience that memories of its World War II aggression do not die easily in countries that it occupied and they can sour at a moment's notice the friendly relations Japan wants to build with those countries today.

The latest lesson was a series of angry student demonstrations and government statements in China denouncing an official visit that Prime Minister Yasuhiro Nakasone made Aug. 15 to Yasukuni Shrine in Tokyo that honors Japan's 2.5 million war dead.

The dispute continues to simmer, despite Nakasone's cancellation of a second shrine visit and efforts by the Chinese government to rein in the street protests.

Nakasone and his Chinese counterpart Zhao Ziyang conferred in New York Wednesday without directly broaching the Yasukuni subject, a Japanese spokesman said. But they did devote much of their 30-minute session to reaffirming friendship, an apparent attempt to wind things down.

It is in many ways a rerun of a 1982 dispute in which China accused Japan of rewriting history textbooks to whitewash Japan's wartime record.

Both governments seem to want to avoid any larger disruption. But emotions run so deep on both sides that the issue cannot easily be put aside.

China today remains full of bitter recollections of Japan's 1931-45 invasion and occupation of vast expanses of the country. The Chinese say Japanese troops killed 20 million of their people.

These feelings are pitted against strong resentment against China for this affair in parts of Japanese society. Some people say China has exaggerated the war's cost. Other Japanese fault it for refusing to put the past behind it and for blaming today's Japan for things that happened more than 40 years ago.

Many senior leaders of the ruling Liberal Democratic Party, Nakasone included, were in uniform during the war.

On Aug. 15, the 40th anniversary of Japan's World War II surrender, Nakasone went to Yasukuni Shrine and, with television cameras rolling, said prayers for the Japanese war dead, whose souls are said to gather there.

He had visited Yasukuni many times before. But this was the first time he announced that he was there in his official capacity as prime minister, not as a private citizen. It was a gesture fraught with symbolism and defiance of conventions that had evolved after the war.

It was part of a larger campaign by Nakasone to build a new national spirit. The idea, the prime minister told the Diet, or parliament, recently, is to honor the war dead and "renew the desire of Japan for peace."

"It is common sense around the world that a chief of state can visit and pay respects at a place where a country commemorates those who gave their lives for it," said Seisuke Okuno, head of a group of ruling party legislators who favor such official visits.

But there is no consensus favoring the visits in Japan. Many opposition parties charge that they violate constitutional requirements for the separation of church and state and could mark a step toward militarism.

Things appeared to have quieted down somewhat in Japan when news came in September of highly unusual student protests in China. On the campus of Peking University, a cartoon poster appeared showing Nakasone wearing boots and sharpening a sword.

On Sept. 18, the anniversary of the start of Japan's invasion of Manchuria in 1931, several hundred Chinese students paraded in Peking's Tienanmen Square shouting such slogans as "Down with Nakasone!" and "Down with Japanese militarism!"

For many Chinese, Nakasone's visit was particularly insulting because among the enshrined dead at Yasukuni are seven Japanese leaders who were convicted of war crimes after the surrender and hanged in 1948. They include wartime prime minister Hideki Tojo.

The Chinese government criticized the Yasukuni visit during the summer. But after the student actions began, the tone of its statements sharpened, possibly due to fear of being accused of being dupes of the Japanese.

At the start of the row, Japan offered its standard counter to foreign acrimony, an appeal for "understanding" of the Japanese position. But later, as things escalated and it became clear that the Chinese government was trying to calm down the street protests, Nakasone and others in the ruling party appear to have decided that some better gesture was needed.

As read in Tokyo, the Chinese government's message was: "Please don't put us into a more difficult situation," according to one Japanese official.

Nakasone cancelled a plan to visit the shrine officially for a second time during a festival from Oct. 17 to 19. His spokesmen, in private conversations, mentioned the Chinese complaints, but also domestic opposition, Nakasone's tight schedule and the October festival's local and distinctly religious nature. The Aug. 15 rite is said to be more of a national ceremony.

This did not stop large numbers of ruling party leaders from praying at the shrine during the festival, however.

Nakasone told the Diet this week that he will consider future visits to the shrine on a case-by-case basis. His foreign minister, Shintaro Abe, said that in the future, China's feelings would be taken into consideration.

That seems to represent a step back from this summer's suggestion that official visits would become routine. The move was condemned by some members of the ruling party, who saw it as a simple crumbling under Chinese pressure.

"We have to think carefully and do what is right," said Okuno. "We should not constantly be thinking of the views of other countries." A few ruling party politicians have said publicly that Nakasone's political standing will suffer for the decision to cancel the visit.

Relations have also been strained somewhat in recent months by trade. Last year, China ran a $1.3 billion deficit with Japan and seems to be headed toward a $5 billion shortfall this year. China is paring down its purchases from Japan to balance the accounts.