As I mentioned before, some samurai had a lot of time to sit around and think. To a small degree, the government encouraged it - as long as you were thinking of ways to buttress Tokugawa power. Early on, Ieyasu made use of Shinto, Buddhism, and Confucianism to legitimize his rule, but as time went by, he made greater use of Confucianism. We dont need to get into all the various schools of Confucianist thought but we do know that there was not just one school and that several of these different ones were influential during the Tokugawa period. The governments official favorite was the Chu Hsi school, which placed great emphasis on duty and acting according to your station in life. Not too hard to see why the Tokugawa family liked it; Chu Hsi Confucianism was very conservative.
A rival school was the Wang Yang-ming (cool name!) school. This school stressed intuitive knowledge of right and wrong and personal responsibility. A famous, though possibly bogus, Wang Yang-ming saying is "to know and not to act is not to know." Since morality is subjective, if you think something is wrong, it is and you must act on that knowledge. Subversive thinking this. This school greatly influenced the men who destroyed the Tokugawa regime in the 1860s.
One last important school was the Ancient Learning school. These Confucianists believed that to understand ConfuciusEtrue message you had to go back and critically examine the old books. If you can separate the garbage from the original then you know what Confucius really meant. Aside from developing powerful tools of linguistic analysis, this school is important for Japan because it caused some Japanese guys look at their old books and try to separate the "pure" Japanese elements from the "corrupting" Chinese elements. Combine this regard for old Japanese books (primarily the Kojiki and the Manyusho) with Shinto (the Way of the Gods) and you get the School of National Learning. Of course no self respecting National Learning scholar would be caught dead concluding that China (or anywhere else) was better (in any way) than Japan. On the contrary, as the myths in the Kojiki were increasingly taken as facts, it became obvious that Japan was the Land of the Gods. This nationalistic version of Shinto was "taught in schools right up to 1945." Draw your own conclusions.
There is another branch of Tokugawa scholarship which we need to look at, namely Western Learning. After the ban on western books was partially lifted, some men began learning as much as they could about what was happening in the West. Unfortunately, the only Westerners around were the Dutch and they were not always entirely honest. Several generations of Western Learning scholars spent a lot of time learning Dutch because the Dutch told them that it was the major international language of learning. Not having any evidence to the contrary, the Japanese went ahead and learned Dutch and then studied and translated Dutch books on medicine, math, and the hard sciences. Medicine was the first to really gain acceptance, since it could easily be proved more effective then Chinese medicine. Math ran afoul of the native mathematical tradition. You occasionally hear about how some Japanese mathematicians invented a calculus independently of Europe and this is true. However, it was never much more than an sophisticated toy. Unlike in Europe, math was never a tool of the hard sciences in Japan because the hard sciences did not exist. Thus, western math was viewed as just another foreign intellectual pursuit and not as a useful tool. It was not until Britain and others flexed their military muscles that the government understood the power of Western Learning and began to actively encourage it. Until then (the mid-nineteenth century) Western Learning was viewed with suspicion.