How do Minecraft mobs behave in water?

Solution 1:

  1. Most mobs swim to the surface, even if you're submerged beneath them. The exceptions are:

    • Squids
    • Dolphins
    • Turtles
    • Fish
    • Guardians/Elder Guardians, which swim after and attack the player underwater
    • Zombies, which sink and become Drowned
    • Husks turn into Zombies which turn into Drowned
    • Drowned mobs, which swim and attack the player underwater
    • Other undead mobs, which sink and move along the bottom, but cannot swim
    • Phantoms, which will sometimes dive into water and then quickly die
    • Also note that Skeleton arrows can and will pierce water
  2. Most mobs will not spawn in or on water. Again, this comes with the exceptions:

    • Squids can spawn in any body of water, as far as 18 blocks below sea level
    • Dolphins spawn in non-frozen ocean biomes
    • Fish spawn in various places underwater
    • Guardians/Elder Guardians spawn in and near Ocean Monuments
    • Drowned mobs spawn at the bottom of oceans, rivers or swamps
  3. Since most mobs swim to the surface of standing water, they can get to the top of a sheer edge and exit from there. No mobs can swim up waterfalls though, so you can keep them all down using running water. Non-Drowned undead mobs will stay at the bottom of water and will be unable to escape.

  4. A long Soul Sand gate can be built along the shoreline, which will prevent mobs from crossing it. These gates can be traversed by players using minecarts on tracks placed over the Soul Sand. From the wiki:

When placed on the ground in front of a two-block high doorway, soul sand prevents players from going through it from that direction, making it useful for building one-way passages or invisible barriers. This affects mobs too as they have to jump to get out of the slowing effects of the block, thus are unable to get through the door.

Because minecart tracks can be laid on Soul Sand like most other block materials, this quirk can be exploited to create minecart-only gates (by placing soul sand on both sides of the doorway). This is one of the few ways to allow minecart tracks to go directly inside a secure area without risking wandering mobs getting in.

Here's a snapshot of a small one I built beside my house, with a crossing point for players.

A Soul Sand gate along a small shoreline

Solution 2:

To answer the first question:

When mobs enter water they swim to the surface. My son has built a mob "generator" which relies on this principle to draw the mobs to the surface where they die and deposit their goodies for him to collect.