According to this Wikipedia article, pre-industrial Japan - a mostly mountainous country around 70% the size of France (a country occupying one of the most fertile regions of Europe) - had about 25% more people than France. Even today, Japan still has almost twice the population of France. Why is this? Is there something special about Japan (or France) that explains this?
In general Japan has the benefit of being an island nation that, whilst mountainous, also has fertile plain regions that historically have been able to support large populations (e.g. the Kanto plain, Nobi plain and Osaka plain). Being separated from the continent of Asia has benefitted the country by insulating it from large scale wars. In the past two thousand years, the only two external invasions of Japan were by the Mongols (1274 and 1281 AD) and the USA in WWII (1944-45). Civil strife and famine did, like everywhere else on the planet, occur, but its geography is a benefit that is a historical constant that I would highlight.
But your question is specifically for the population of Japan c. 1700, so let me address that in more detail. The victory of Tokugawa Ieyasu at the battle of Sekigahara in 1600 and the Siege of Osaka Castle in 1615 ended what is commonly refered to as the 'Sengoku Jidai' (the 'Warring States period'), a period lasting from the mid 15th century (i.e. c. 150 years) that saw a weakening (and ultimate abolishment) of Japan's previous central authority (the Ashikaga Shogunate, think of it as a military dictatorship). This period saw the splintering of Japan into dozens of regional leaders each vying for various levels of independence, or greater authority.
As you can imagine, the constant warfare lead to disruption to Japan's population growth, with peasant mobilisation, destruction and interuption of farming, and direct violent deaths caused by the conflict all putting a downward trend of the country's demographics. Eventual unification in the late 16th century did not fully end this either, with the internal strife instead being exported abroad via the Toyotomi invasion of Korea between 1592-98, which led to over 100,000 Japanese deaths (not even speaking about the cost to Korea), a significant number for that period in time.
When Tokugawa therefore came to power, the country had suffered significantly due to internal strife, and stability was a prized governing virtue. Resultantly, the Tokugawa Shogunate, which was established just after Sekigahara in 1603 and abolished in 1868 with the Meiji Restoration, largely closed itself off to the outside world, heralding in 250 years without war, or major rebellions.
The peace saw a major expansion in crop rotation, particularly of rice. Previously only a staple of the elite (e.g. an ordnance as late as 1649 by the Tokugawa Shogunate forced peasants not to give rice to their families at harvest time as a way of reducing consumption rates), rice became significantly more accessible amongst all societal classes and by the end of the 18th century most classes will have had rice as a significant part of their dietary staple. By 1670 it became accepted (although not quite universal, that would happen over a century later) practice for farmers to be able to pay their taxes not in rice (as had been common for centuries - much of Japan's wealth valuation had been based on the idea of the koku, a unit of measurement based on rice), but in cash, due to the fast commodification of the product.
So significant was this increase that a new disease became common in urban centers, Kakke, or Edo Wazurai (literally the affliction of Edo, due to its common occurence in Edo/Tokyo). Kakke is a result of a vitamin B deficiency that occurs due to the removal of the hull of the rice necessary in this period for the creation of polished, or white, rice, speaking to the vast quantities of rice now consumed in the fast growing urban centers of the country.
Rice was however not the only crop that benefitted Japan's demographic expansion. The sweet potato, introduced in Japan in 1605 along with the white potato, became a common crop in particularly the west of the country, and improved the crop diversity beyond grains, nuts and rice. This diversity, which meant a lower death toll in the face of major crop failures, is credited for why many Tokugawa era famines, such as the one in Kyushu in 1732, were relatively mild. Sweet potatoes had the other benefit that they could be grown in more hilly or mountainous areas, meaning they largely did not compete with rice for land irrigation.
The prosperity is evident from the heavy urbanisation that occured from the late 17th century onwards, with 3 of the 10 largest cities in the world (Edo, Osaka and Kyoto) being located in Japan. Urbanisation can only occur when there is a surplus in food, and the ability to transport said foodstuffs, evidence of the prosperity of the era.
These surpluses also meant that when famines did occur, there were surpluses stored that could alleviate the worst of a famine. The three major famines that occured in Japan in the 17th and 18th centuries, the Kan'ei famine of 1640-1643 (50k-100k deaths), the previously mentioned Kyoho famine of 1732-1733 (12k-169k deaths) and the Great Tenmei Famine of 1782-1788, the largest famine in the Tokugawa period (100k-920k deaths), saw somewhere between 160k and 1.2 million total deaths. This sounds like a lot, but was actually quite mild considering the amount of time passed, and other famines of this era such as various French (1693-1694, 1.3m-1.5m deaths / 1709-1710, c. 600k deaths), Irish (1741-1742, c.300k-480k deaths) or Russian (1601-1603, c.2m deaths) famines.
In short, Japan's demographic boom in this period is largely thanks to a mix of the peace and prosperity that allowed for a vast expansion in arable land and crop diversity. Whilst headwinds did occur in the 19th century, it's part of the reason why Japan continues to be a relatively densely populated country.
I'm largely basing this off of Volume 4 (Early Modern Japan) of the Cambridge History of Japan, 2006 edition.