$$ \begin{cases} \partial_t^2 u - c^2 \partial_x^2 u , x \in [0,l] \\ u(0, t) = 0 = u_t (l,t) \\ u(x,0) = f(x), u_t (0,x) = g(x). \end{cases} $$
Look for solutions in the form $$ u(t,x) = X(x) T(t). $$
$\rightarrow$ wave equation yields
$$ X(x) T^{''}(t) = c^2 X^{''}(x) T(t). $$
Divide by $-c^2 XT$ to see
$$
- \frac{T^{''}(t)}{c^2 T (t)} = - \frac{X^{''}(x)}{X(x)}.
$$
The left side depends only on $t$. The right side depends only on $x$. Differentiating with $t$ reveals left side is constant. Differentiating with $x$ reveals right side is constant. Name the constant $\lambda$.
Assume (why?) that $\lambda >0$. Write $\lambda = \beta^2.$
$$ X^{''} + \beta^2 X =0, ~ T^{''} + \beta^2 c^2 T = 0. $$
For separated form solutions, PDE $\rightarrow$ 2 ODE!
$$ X(x) = C \cos \beta x + D \sin \beta x$$ $$ T(t) = A \cos \beta c t + B \sin \beta c t$$
We demand that $ X(0) = 0 $ so $C = 0.$
We demand that $X(l) = D \sin \beta l = 0.$ We don't want $D=0$! We want $\beta l$ to be a zero of the sine function.
This quantizes $beta$: $$ \beta l = n \pi \implies \beta_n = \frac{n \pi}{l}. $$ We find infintely many solutions in separated form: $$ u_n (t,x) = [A_n \cos \frac{n \pi ct }{l} + B_n \sin \frac{n \pi ct}{l} ] \sin \frac{n \pi x}{l}. $$
We can form linear combinations.
$$ u(t,x) = \sum_{n} [A_n \cos \frac{n \pi ct }{l} + B_n \sin \frac{n \pi ct}{l} ] \sin \frac{n \pi x}{l} $$
This expression solves the wave equation and satisfies the Dirichlet boundary conditions.
The expression is flexible; we can choose the coefficients $A_n, B_n$.
Can we choose the coefficients to match the initial conditions?
We want $u(0,x) = f(x)$ and $u_t (0,x) = g(x)$. Therefore we want to choose the coefficients so that
$$ f(x) = \sum_{n} [A_n ] \sin \frac{n \pi x}{l},$$
$$ g(x) = \sum_{n} [ \frac{n \pi c}{l} B_n ] \sin \frac{n \pi x}{l}. $$
How can we choose the coefficients? Let's postpone this question for a while....
$$ \begin{cases} \partial_t u = k \partial_x^2 u ~, x \in [0,l] \\ u(t, 0) = 0 = u(t, l) \\ u(x,0) = f(x). \end{cases} $$
Look for solutions in the form $$ u(t,x) = X(x) T(t). $$
$\rightarrow$ heat equation yields
$$ X(x) T^{'}(t) = k X^{''}(x) T(t). $$
Divide by $X(x) T(t)$ to find
$$ \frac{T^{'}(t)}{T(t)} = k \frac{X^{''}(x)}{X(x)}. $$
Since the left side depends only upon $t$ and the right side depends only upon $x$, both sides must be constant. We choose to write the constant as $-\lambda$.
The equation splits into to ODE:
$$ - X^{''} = \lambda X, ~ x \in [0,l], ~ X(0) = X(l) = 0,$$
$$ T^{'} = - \lambda k T. $$
$\implies$
$$ u(t,x) = \sum_{n} A_n e^{-(n \pi /l)^2 t } \sin \frac{n \pi x}{l}. $$
We need to choose the coefficients $A_n$ to satisfy the initial condition.