About the first fact see this page (the Krull–Remak–Schmidt theorem). For infinite (even finitely generated) groups the situation is different because there exists an infinite f.g. group isomorphic to its direct square.
Update. Hirshon, found two non-isomorphic finitely generated nilpotent (infinite) groups $G,H$ such that $G\times G\cong H\times H$.