About the first fact see <a href="http://groupprops.subwiki.org/wiki/Direct_product_is_cancellative_for_finite_groups">this </a> page (the Krul-Remak-Schmidt theorem). For infinite (even finitely generated) groups the situation is different because there exists an infinite f.g. group isomorphic to its <a href="http://groupprops.subwiki.org/wiki/Group_isomorphic_to_its_square">direct square. </a>

<b> Update. </b> <a href="http://springerlink.com/content/k7p548016pvq0163">Hirshon</a>, found two non-isomorphic finitely generated nilpotent (infinite) groups $G,H$ such that $G\times G\cong H\times H$.