Farming is a sustainable way to gain food with no risk to the player. Currently only Wheat, Melons, Pumpkins, Carrots and Potatos can be farmed.
What you need
Before you can start farming you need to craft a Wood Hoe or better. Once you have a Hoe you need to get some seeds. There are three types of seed: Wheat Seeds, Melon Seeds and Pumpkin Seeds. You can obtain Wheat Seeds by destroying Tall Grass.
Location, Location, Location
Now that you have everything you need, you need to find a place to grow your crops. Crops grow best when they have Water near them as the soil is then hydrated making them grow faster but being near Water isn't required. Once you have picked a location its advisable to use Fence to surround your field so that Mobs can't destroy your Crops by trampling on them. Crops are trampled when Players or Mobs jump on them.
Crops can only grow on Dirt that has been hoed (Called Farmland). So you need to use your Hoe (Right Click) on the location you are going to turn into a Farm. Crops need Light to grow, so placing Torches near them will allow them to grow at night or underground. Melon Seeds and Pumpkin Seeds will grow vines which spawn one Melon/Pumpkin beside it on Farmland if there is not already one next to it.
Melon/Pumpkin Farm Layout
It is best to plant Melon Seeds and Pumpkin Seeds in rows of two with 1 row either side of Farmland beside them for the Melons/Pumpkins to grow on. You should make your field 8x8 and surrounded by water so that the crops grow faster (See 1st Image). The design allows you to expand the field either horizontaly or verticaly (See 2nd Image).
You can only harvest Wheat once it has fully grown or you will only get Wheat Seeds from it. Wheat is fully grown when the tips of it are a golden colour. When Wheat is harvested it will drop one Wheat as well as Wheat Seeds when harvested, Melons drop one or more Melon (Slice) when harvested and Pumpkins can be picked up when harvested.