When I was a student, we had to announce ourselves whenever we entered or left the dojo. We had to say, "Good morning Sensei it's David" or "Good night Sensei, thank you. This is David" every time or we got a scolding from Furuya Sensei the next time we came. Sensei used to say, "Only a dorobo (thief) enters without announcing themselves." This stems from the Japanese proverb, "When you see a stranger regard him as a thief!"
This idea of announcing oneself or one's intention can still be seen in Japanese society today. When a person comes home, they say, "tadaima" or I'm home. When we see someone you know in the morning one is supposed to say, "Ohayogozaimasu" or Good morning. When a student visits a dojo, they are supposed to bring a letter of introduction from their teacher that states the student's rank, how long they have been training, something about their character and a request to allow them to train.
This insular idea comes from the "village" mentality that the Japanese had that dates back hundreds of thousands years. If you were from their village then a Japanese person would bend over backwards to help you, but if you were an "outsider" then they would be very suspicious of you.
From a martial arts perspective, this distrust of outsiders came because of the practice of dojo yaburi (道場破り) or dojo challenges, but some call it dojo storming. Dojo yaburi is when a person comes to the dojo to challenge one of the students or the teacher. Supposedly, if one could beat the teacher then they would take over the school and the students. Resources and students were scarce and so this was a frequent occurrence.
This idea of regarding a stranger as a thief is one that still exists today. One of the main differences between Japanese and Western people is that Japanese people don't talk to people they don't know and they especially don't idly chit-chat with strangers. This closed-offness is something that confounded Western businessman in the 1980s as they tried to infiltrate the Japanese economy. Usually, no introduction meant no business. One needed to have an "in" in order to start a business relationship.
There is even a famous Zen story closely associated to this idea of strangers and thieves:
One evening, Zen Master Shichiri Kojun was reciting sutras as a thief with a sharp sword entered, demanding that he give him money.
Shichiri told him: "Do not disturb me. You can find the money in that drawer." Then he resumed his recitation.
The thief found the money and began to leave when Shichiri said, "Don't take it all. I need some to pay taxes with tomorrow."
The intruder gathered up most of the money and started to leave. Shichiri then said, "You should thank a person when you receive a gift." The man thanked him and ran off.
A few days afterwards the thief was caught and confessed to his crimes. When Shichiri was called as a witness he said: "This man is no thief, at least as far as I am concerned. I gave him money and he thanked me for it."
After he had finished his prison term, the thief became Shichiri's disciple.
In Japan, whenever you enter someplace you are supposed to state your intention and one does this by how one announces themselves. Students have to greet their teachers and show they are ready to learn and this is done with the first greeting. Customers always air on the side of politeness so they usually say, "Sumimasen" or excuse me prior to asking for something.