So as a preface, my area of study is the middle east. I have a pretty good grasp on how regional modernization projects, especially in Egypt were carried out. Generally speaking they sought out European technical support in modernizing their military, economy, education, government administration, and infrastructure, building everything from rail roads to the Suez Canal. For a time it was hugely successful, during, say, the reign of Mohammed Ali Pasha. Then his successors started contracting loans, leading to bankruptcy. Bankruptcy lead to foreign interference, sparking proto-nationalist revolts (Urabi) which in turn led to occupation (to simplify just a bit.) The same story played out across the Middle East and North Africa. The Ottomans even tried Constitutional reform, which was basically a disaster.
Now from my understanding, the Meijii period saw an almost identical program of reforms, with similar conflicts over developing a modern social structure, but obviously with radically different results.
What did Japan do differently? Did they not take out foreign loans? Did they have particularly good leadership? Was it simply their isolation? If they didn't take loans how did they afford these projects?
It's not a fair statement to say that modernization rendered the Ottomans/Tunisians/Europeans open to European imperialism. Correllation doesn't imply causation. You can write books on how European imperialism influenced the Ottoman Empire. You could write more books on how the Ottoman Empire collapsed into itself and that Europe had little to do with the destructuralization of the Near East empire.
The Ottoman Empire fell victim to several different crises that arose throughout the 17th and 18th centuries and solidified during the 19th century, eventually leading to its collapse in the 20th. From economic instability, to the decentralization of power via the regicide of Osman II in 1622, to the rise of the Janissary corps from the reduction of power suffered by the sultanate. Yes the Europeans managed to take advantage of the weaknesses suffered by the Ottoman Empire through methods such as the forcing of capitulations to be resigned even during the economic downturn of their maritime trade. The constitutional reforms you speak of in the Ottoman Empire only happen twice, and each of those are short lived. The constitution is put into place in 1876 and lasts a grand total of two years before the sultan attempts to recentralize power and dissolves the Ottoman parliament. The second Constitutional Era in the Ottoman Empire lasts from 1908 until its dissolution in 1920 at the Treaty of Sevres. This is more or less the empire on its deathbed, although many believed that the empire would still pull out of the tailspin, historically the empire was doomed to failure.
You say that Egypt asked for European help in their modernization attempts in the 19th and 20th centuries. Wouldn't you think it kind of difficult to say that Egypt wanted this or that when Egypt had no formal sovereignty from 332B.C to 1952 A.D? Starting in 1517 the Ottoman Empire controlled Egypt and utilized them in a colonial economic fashion which removed wealth and sent it back to the metropole. If you're speaking about Nasserist Egypt then you're missing a vital component of Egyptian modernization within the context of Third Worldism and the Pan-Arabic view of the West. In 1955, the Bandung conference specifically criticized both Western and Eastern colonial and Neo-colonial efforts in South Asia, Mainland Africa, and the Middle East. Although Nasser continued to receive economic aid from the West up until 1967, he most assuredly did not fall victim to the West's imperialist ventures and is still today considered a pioneer and the father of Pan-Arabism.
Japan had several things going for it. Firstly, it was almost 6000 miles removed from Europe by land, and thousands more by sea. Secondly, Japan was a military power to be reckoned with. By winning two major wars, The Russo-Japanese and First Sino-Japanese, it reclaimed much of its economic and political sovereignty. From there modernization became easy without the influence of foreign parties effecting their state building policies.
Sources:
The Ottoman Empire and Early Modern Europe: Daniel Goffman
Sources in the History of the Modern Middle East: Akram Fouad
The British In Egypt Community, Crime and Crises, 1882-1922: Lanver Mak
I only have a layman's knowledge of Ottoman history myself, but it seems to me (judging from you question) that you believe foreign loans / indebtedness to European imperial powers was a major debilitating factor in Ottoman reform. Interestingly enough, the Meiji Oligarchs (called the genro in Japanese) were extremely fearful of accruing foreign debt. They knew that they needed to modernize and that they could not achieve this without help from the West. However, they were incredibly wary of "giving a mouse a cookie" so to speak. They feared that every inch they surrendered to the West would have repercussions down the road.
Moreover, they had witnessed first hand out British financial domination of China could eventually lead to de facto political control (informal imperialism) over large swaths of territory (the British eventually even wrenched control over import taxation [a major source of revenue for Qing Dynasty China] from the Chinese). The genro did not want this same fate to befall Japan. As such they developed a policy of 'import substitution' whereby they developed their own textile industry over a relatively short period of time (eventually overtaking the British as the world's leading textile producer) self funding these projects through the widespread export of silk and to a lesser degree tea (products in demand in the Western world). Rather than taking out loans they were able to ensure a favorable balance of trade while they slowly grew their industrial base and became a major economic world power.
So to return to your initial guesses:
Yes they avoided foreign loans wherever possible, seeing them as a means of implementing indirect imperialism.
Yes they had especially strong, charismatic, intelligent, and forward thinking leaders. In spite of the policy of "sakoku" (closed country) whereby the Tokugawa Shogunate attempted to keep out foreign influence, continued trade with the Dutch throughout the Tokugawa period led to the creation of a class within Japan known as "Dutch Scholars" who were aware of all the West's latest advancements very shortly after they were developed in the West. This openness meant Japan did not have as much catching up to do in terms of knowledge as implementation. Japan's leader's already knew what they had to do, they simply had to wait until the reactionary Tokugawa Shogunate was overthrown to implement their policies. Moreover, once the Meiji Oligarchs were in power the brought in Western advisers for anything they could not do themselves, and rewarded them handsomely. However, as soon as they felt they had mined these advisers for all they could, the genro immediately sent these advisers home and replaced them with Japanese.
Japan's geographic isolation did help them preserve their independence in the past (perhaps most notably in repelling the 2 attempted Mongol invasions), but as previously stated they were never truly isolated from the outside world in terms of knowledge. The number of Dutch Scholars was very small, but Japan was never truly cut off from the West and contact with other Asian nations remained strong throughout the Tokugawa period (particularly with China and Korea via the Choshu Domain).
So, the Meiji leaders were constantly wary of any area where they felt the Westerners could extend informal control over their country, and always nativized any aspect of the development process that they could (whether that be financial capital or technical training).
Sources:
Kenneth Pyle - The Making of Modern Japan 2nd edition
The Autobiography of Fukuzawa Yukichi - Translated by Eiichi Kiyouka
Kenneth Pyle - Japan Rising
As for Japanese modernization efforts I can't really say, but a factor that is considered by historians as a contributor to Japanese largely avoiding the imperialist domination by European powers is the fact that under Toyotomi Hideyoshi several edicts were issued to expel Christian missionaries from Japan. Following their expulsion, the Tokugawa further contributed by rooting out followers of Christianity and either killing them or forcing them to renounce the religion. By about 1640 Christianity was all but extinct in Japan. The significance of extinguishing Christianity in Japan is that it affected Tokugawa policy towards all foreigners and foreign involvement to the point that Japan has been labeled a closed country under the Tokugawa Shogunate. In reality, Tokugawa Japan after forcing Christian missionaries out had limited trade with continental Asia, the Dutch, and several island countries. Because of this limited exposure and aggressive disposition to foreigners, especially Europeans, Japan was able to largely escape European Imperialism. In addition, during the rise of Imperialism, Japan was the most heavily armed country on earth since it was just leaving the Warring States Period. Long story short, Japan kicked Christian missionaries out which resulted in an unfriendly disposition to European powers and they had the military ability to back it up.
Sources: Sources of Japanese History, WM Theodore
The Conquest of Ainu Lands, Brett L. Walker
Edit: Fixed Typos
This is going to be long but let's try to think of some things:
Distance was not a key factor. China right next door was semi-colonized just like Egypt was.
Japan however had breathing room because the West did not bother Japan too much.
Japan was not in a key strategic location like Egypt was (Suez) so it avoided scrutiny. Japan did not have strategic natural resources (spices, rubber, etc) like in SE Asia or Africa that the West could not produce, so it also avoided scrutiny.
Also Japan's population was not huge (like China) so it was not the main target of colonialism as a potential market for Western industrial products.
You combine this relative neglect with Japan's intense efforts to modernize without borrowing Western money or taking on undue Western help.
For example, Saigo Takamori refused British help in overthrowing the Tokugawa Shogunate in 1868. Ito Hirobumi and others refused to borrow Western money in the 1880s after seeing what happened to Egypt (the Meiji government set up in 1868 had borrowed some money earlier from British banks). This happened despite the fact that Japan had signed unequal treaties that left them without the ability to raise tariffs to raise money or protect infant industries. [This meant direct taxes inside Japan was really high, leading to many protests and one of the highest incarceration rates in the world at the time.]
So that gives Japan the possibility of succeeding.
Considering the fact that only a handful of countries remained independent by the early 20th century, all those who survived should receive honorable mention for not being taken over by Western powers: Thailand, Ethiopia, Liberia, Iran, Ottoman Turkey (if I am missing a country I'm sorry). Either they were lucky like Japan and were neglected or managed to defend themselves.
So why did Japan out of the all the possible countries succeed in industrialization? Well it takes time, so they needed to be doing it since the 19th century. (Also it's practically impossible to industrialize as a colony.)
Out of the above list, I think Ottoman Turkey and Japan are the only 2 countries that seriously tried to industrialize starting in the 19th century. (As you noted, Egypt also tried, but got taken over because of debt.)
So to sum up again. Only a few countries outside of the West remained independent by the early 20th century. Force, money, etc was used to colonize the world. Only these independent countries had the chance to industrialize and modernize.
Only 2 out of the above list tried to industrialize starting in the 19th century: Ottoman Turkey and Japan. So what's the difference:
Timur Kuran's answer is Islamic Law was too good so people did not switch to Western law in time to reap the benefits quickly. The Long Divergence: How Islamic Law Held Back the Middle East http://www.amazon.com/The-Long-Divergence-Islamic-Middle/dp/0691156417
In contrast Japan adopted Western law for commerce very quickly.
How were they able to run businesses effectively? That's the going to require a book but suffice it to say that Japan had enough commercial know-how built up since the 16th century that they could transition reasonably well. So that would be my answer.
David Howell's Capitalism From Within: Economy, Society, and the State in a Japanese Fishery talks about one industry that had the know-how.