Proof (groups of order 4)
By Lagrange's theorem, every non-trivial element in $G$ has order 2 or 4.
If there exists $g\in G$ where $o(g) = 4$, then $\langle g\rangle \leq G$ while $|\langle g\rangle| = 4 = |G|$, so $G=\langle g\rangle \cong C_4$.
Otherwise, we can find distinct $a,b\in G$ with $o(a) = o(b) = 2$. Checking the hypothesis of the direct product theorem,
-
$\gen a \cap\gen b = \{e\}$ since $a\neq b$;
-
$\gen a \gen b \equiv \sb{xy}{x\in\gen a, y\in\gen b} = G$ due to subgroup and same order;
-
$ab = ba$ since all non-trivial elements have order 2.
Therefore $G\cong\gen a\times\gen b\cong C_2 \times C_2$.