Actually, the answer is a bit more subtle than just density. The principle that is behind floating objects is Archimedes' principle:
A fluid (liquid or gas) exerts a buoyant force, opposite apparent gravity (i.e. gravity + acceleration of fluid) on an immersed object that is equal to the weight of the displaced fluid.
Thus, if you have an object fully immersed in a fluid, the total force it feels is given by (positive sign means down):
$F = gravity + buoyancy = \rho_{object} V g - \rho_{fluid} V g = (\rho_{object} - \rho_{fluid}) V g$
Thus, if the average density of the object is lower than that of the water, it floats. If the object is partially immersed, to calculate the buoyant force you have to consider just the immersed volume and its average density:
$F = \rho_{object} V g - \rho_{fluid} V_{immersed} g$
Note that when I was talking about density, I was talking about the average density of the object. That is its total mass divided by its volume. Thus, a ship, even if it is made out of high-density iron it is full of air. That air will lower the average density, as it will increase the volume considerably while keeping the weight almost constant.
If you want to understand this better you can give the following problem a try :)
What is the height an ice cube of side L floats in water?