As others have said, no, you don't have introduce anything before a dialogue. Infact, you can have dialogues with totally unknown characters:
A low, menacing voice whispered behind his ear.
"I'd put that weapon down, kid."
She heard someone screaming in the distance.
In both cases the character speaking is unknown to the PoV, is not being introduced, and could either be male or female.
Regarding the John example, I'd say it's lacking a bit of context. In a scene of a novel, if two characters are going to meet, I don't expect any of them to pop out of thin air and start talking.
The man was tall and wiry. The hair on the top of his head were receding, but he looked handsome. His squared jaw gave him a look of quiet confidence. As always, Matthew's attention was drawn in to the little details - the clean, recently ironed shirt, and the polished look of his belt. The stranger knew how to dress.
"My name's John," he said, ad he put his right hand forward.
"Happy to meet you" Matthew replied, shaking it.
Of course this is not always true. You can start a dialogue in medias res, with both character already in the middle of the action.
"My name's John" the new intern said.
"Happy to meet you" Matthew answered.
Most names are usually gender specific, so most of the times you don't need to specify if the talker is male or female. If you haven't described a character before, the audience will take the underlying information to assume the gender.
"My name's John"
Since John is typically used for males, you don't really need to say anything else. Unless, of course, the PoV tells us otherwise:
"My name's John"
Matthew looked at the new intern, trying to wash away the dumbfounded expression on his face. He was probably failing at that.
"Yeah, I know." The girl chuckled at him. "You're not the first who gives me that look".
"I didn't mean to" He walked up to her and they shook hands. "It's just unusual."
The same can happen if you're using codenames, surnames, or names in a foreign language. But I'd call those exceptions, not the general case.