Why and how did Japan succeed in keeping Europeans largely away from its territory in the seventeenth century?

Why and how did Japan succeed in keeping Europeans largely away from its territory in the seventeenth century?