About the first fact see this this page (the Krul-Remak-SchmidtKrull–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. direct square.
Update. Update. HirshonHirshon, found two non-isomorphic finitely generated nilpotent (infinite) groups $G,H$ such that $G\times G\cong H\times H$.