A bar joke is a very common and basic type of joke. The basic syntax of this type of joke is "A man walks into a bar and <something happens here>". The initial perception of the joke is that a man is walking into a bar to have a drink, but this only lasts a few seconds as the punchline is quickly uttered. This joke has gained an incredible amount of variants over the years. It is often used by comedians, and people telling jokes to friends.
The bar joke has a large number of variations. The types of variations include puns or word plays (the man walks into a bar and pulls out a tiny piano and a 12-inch pianist, followed by any number of different punchlines; or man with dyslexia walked into a bra), or replace the man with woman, a famous person, people of various occupations, animals (a duck walks into a bar, orders a drink, and tells the bartender, put it on my bill) or inanimate objects (a sandwich walks into a bar, orders a beer, and is told by the bartender, we don't serve food here). Sometimes the unexpected happens: "A man walks into a bar. Ouch!"
Another major variant involves several men walking into the bar together, often with related professions, such as "a priest, a minister and a rabbi." In effect, this is a merger between the "bar joke" and jokes involving priests, ministers and rabbis (or Buddhist monks, etc.) in other settings. This form has become so well known that it is the subject of at least one joke about the popularity of the joke itself: "A priest, a minister, and a rabbi walk into a bar. The bartender looks at them and says, 'What is this, a joke?'"
According to Scott McNeely in the Ultimate Book of Jokes, the first bar joke was published in 1952.