the UK and Japan signed the Anglo-Japanese Alliance in 1902, that was when Japan was pulled into great power status - the world's hyperpower thought you were someone worthy to ally with, to the exclusion of everyone else - the UK was then in a what was called "a splendid isolation" - she needed no alliance to maintain her supremacy.
As to how they got to this power, they had a brilliant leader in Ito Hirobumi, who personally directed the first Sino-Japanese War and ended it in Japan's complete favor. The war demolished Qing China's prestige (they didn't have much left back then), stripped her of the territory of Taiwan and dominance over Korea, as well as an enormous sum of money - enough for Japan to renovate her battle fleet according to the 6-6 doctrine (6 battleships, 6 battlecruisers). It was with this fleet, the Anglo-Japanese alliance, and the abilities of men such as Akashi Motojiro, Yamamoto Gonnohyoue, Akiyama Saneyuki and Kodama Gentaro that the Japanese was once again able to conclude the Russo-Japanese War on their terms in 1905, and this represented a major turning point of world history - a European great power had been decisively defeated by an East Asian Power, and thus Japan was without a doubt a great power, with a navy that was far more powerful than most of Europe had to offer.