(CNN)For years, Kim Jong Un didn't leave North Korea.
The young dictator, the third generation of his family to rule the country, focused on shoring up his power at home, purging elites not supportive of his succession and winning the public and army over with economic reforms and massive military spending.
Throughout, he defied predictions of his demise, whether by coup or assassination, and imminent economic collapse or popular revolt.
With a dramatic diplomatic trip to China in late March, he has shown himself supremely secure and confident, ready to play on the world stage at the same level as major powers.
"We had long expected Kim to pay a courtesy call to Beijing early in his leadership, he held off for seven years until he felt he was in a position of power to meet with the president of China as an equal," said Jean Lee, a North Korea expert at the Wilson Center.
"Kim feels he has settled the question back home of whether he can defend his people as a military leader, and now he's turning his attention toward showing that he can play the role of international statesman."
The true tests of how well Kim can play on the world stage will come later, when he meets with South Korean leader Moon Jae-in and US President Donald Trump.
Unsteady succession
When Kim sought to succeed his father Kim Jong Il in late 2011, there was no guarantee he would be successful.
North Korea had already seen power handed down one generation, from the country's founder Kim Il Sung to Kim Jong Il, but the current leader's father was a well-known and powerful figure in North Korea, groomed for decades to take over.
By contrast, Kim was a relative unknown, promoted swiftly to the rank of four star general and vice chairman of the party's Central Military Commission as his father's health waned.
Following Kim Jong Il's funeral, some observers predicted his son would be a weak leader, a puppet of the country's ruling class, particularly his powerful uncle, Jang Song Thaek.
There may have been an attempt to control Kim in this way, but he responded with a series of major purges, firing dozens of senior officials and arresting and later executing Jang.
North Korea's propaganda department went into overdrive, playing up the personality cult surrounding the Kims and presenting Kim Jong Un as the natural successor to his grandfather. He was even styled to look like the late Kim Il Sung.
The Kim clan has ruled North Korea with an iron fist for decades, imprisoning and executing thousands and running brutal "re-education" camps for dissidents and their families.
Shoring up power
Kim went beyond simply purging potential challengers, he also set about building a new support base for himself within the country and the army.
This meant far greater economic reforms than his father, relaxing the tight controls on how people make and spend their money and kickstarting a quiet consumer revolution.
At the same time, Kim doubled down on the "Songun" -- military first -- policies of his father, pouring millions of dollars into the Korean People's Army and weapons development.
He also began a series of missile and nuclear tests which outraged North Korea's neighbors and sparked angry rebukes from Washington, Beijing and Seoul, and stringent international sanctions.
The peninsula appeared to be barreling towards conflict, especially after the election of Trump, who took a hard line on North Korea and promised "fire and fury" as Pyongyang's weapons testing threatened Guam, Hawaii and even the US mainland.
In November, North Korea tested its most advanced intercontinental ballistic missile (ICBM) yet, which it said was capable of delivering a nuclear warhead to any US target and appeared to meet a goal set for the country's weapons program.
Kim the diplomat
If 2017 was the year of missile tests, this year has been all diplomacy.
In January, Pyongyang agreed to reopen diplomatic communications with Seoul, and within days it was agreed North Korea would participate in the Winter Olympics.
Kim sent his sister, Kim Yo Jong, to South Korea with an invitation for the country's President Moon to come north and meet with Kim, a dramatic improvement in relations that would have been unthinkable only months earlier.
He also extended an invitation to Trump via South Korean envoys, potentially setting up the first ever meeting of a sitting US President and North Korean leader.
"After North Korea successfully obtained a basic nuclear deterrent capability, now it is ready to move to the next phase," said Tong Zhao, a North Korea expert at the Carnegie Tsinghua Center for Global Policy in Beijing.
"Pyongyang needs to deal with the negative consequences created when it developed its nuclear weapons, and recover its relations with China, and improve relations with the US, South Korea and even Japan."
North Korea may face significant difficulty finding middle ground between its firm commitment to retaining its nuclear weapons, and the equally forthright views of hardliners in Washington, who have called for US troops to immediately confiscate North Korea's nuclear weapons.
In the past, North Korea has said it will never give up its nuclear deterrence if other countries retain theirs, and experts said Pyongyang is unlikely to ever agree to a complete denuclearization, though it may concede to freeze testing and reduce its arsenal.
Seeking advice on Trump
Lee, the Wilson Center analyst, said Kim now feels "emboldened to force the region's leaders to treat him as an equal."
"We're seeing a carefully crafted North Korean strategy on diplomacy unfold on the world stage, starting with Beijing," she said.
So far, Kim's strategy appears to be paying off. But South Korea and China are known entities to Pyongyang; Donald Trump is something quite different.
James Hoare, an associate fellow at Chatham House and former UK diplomat in North Korea, said Kim's sudden trip to China may have been in part an effort to get advice on dealing with the US President.
"They don't know Trump, and they may well have decided by biting the bullet and talking directly to China, they may get some helpful advice on how to handle him and what the real American agenda is," he said.