How to keep those animals out of my farm?

Solution 1:

In 1.8 mobs can spawn in certain biomes but they do not only spawn on grass. Now they spawn on the highest block (so as to prevent mobs from spawning in houses), so you should put a ceiling on top of your farm. Adding torches should provide enough light for your crops and prevent hostile mobs from spawning.

Solution 2:

Put glass on top of the tilled area, so that only spiders, wolves, chicken, slimes and silverfish can possibly fit in the one meter high ground. To keep everything but chicken (and spiders?), simply lit the area and fence it. To keep the chicken and the pigs out, I simply carved out a room in my base and dedicated it to this purpose:

That leaves wolves, though. I'm afraid that you'll just need to right click them to make them stay put while you move here to harvest.

Now, so long as my base doesn't get run over by mobs, my crops are reasonably safe.

Solution 3:

Two things to help:

The pathway in your garden can not be grass (use stone, or gravel or something). That should stop most of the neutral NPCs from spawning, and aggressive NPCs won't spawn as long as your farm is well lit.

Second, you can make melon seeds out of the melon pieces, just put them in your crafting slot. (You can also rebuild a full melon from them if you wanted for even more carrying capacity)

A single height of fences should be enough to keep things out then.