A hammer is a multi-purpose tool in Project zomboid. It can be used as a weapon and/or a base fortification tool. The hammer is required to put up any barricades or to craft many items.
In combat, the hammer does not fare well. It is okay for killing 1 or 2 zombies, but even 3 can kill you, because of the hammer's short range and its poor damage (3-5 hits per zombie). However, in a pinch, a hammer is a much better optino than fighting unarmed.
Acquiring a hammer is somewhat difficult, usually, it is found in zombie and NPC corpses, as well as in some cabinents in some houses (but all three are rare). In the story mode, "Till Death do us Apart", the hammer will appear with 10 planks and 15 nails in the shed, being your first and only weapon for some time.
Fortifiying your base will become your hammers main use once you acquire a better weapon. You need a hammer to put up barricades, to put up walls, crafting, and to take down barricades.