Question: I need to construct square matrices $A$ and $B$ such that $AB=0$ but $BA \neq 0$. 

I know matrix multiplication is not commutative, but I don't know how to construct such matrices. Thanks in advance.

Edit: looking for some simple way

Answer: 
$\newcommand{\im}{\mathrm{im}}$Perhaps it is worth recording a strategy to construct such an example, which may turn useful in other circumstances.

Will start with a $2 \times 2$ example, and then generalize.

First of all, both matrices have to have rank $1$. For, if $A$ has rank $2$, that is, it is invertibile, then $A B = 0$ implies $B = 0$ so that $B A = 0$ as well. If $A$ has rank zero, then $A = 0$, and both products are zero.

Now consider the underlying linear maps $\alpha, \beta$. We will have $\dim(\ker(\beta)) = \dim(\im(\beta)) = 1$. 

Consider first the case when $\ker(\beta) \ne \im(\beta)$, so that if you choose non-zero vectors in $e\_1 \in \ker(\beta)$ and $e\_2 \in \im(\beta)$ you will get a basis of the underlying vector space. With respect to this basis you have
$$ B =
\begin{bmatrix}
0 & 0\\
0 & \lambda\\
\end{bmatrix}
$$
with $\lambda \ne 0$.

If you want $A B = 0$, you need $A$ to be of the form
$$A =
\begin{bmatrix}
x & 0\\
y & 0\\
\end{bmatrix}
$$
or considering $\alpha$, you need $\alpha(e\_2) = 0$, so that $\alpha(\im(\beta)) = 0$. Now compute
$$
B A =
\begin{bmatrix}
0 & 0\\
\lambda y & 0\\
\end{bmatrix},
$$
to see that $B A \ne 0$ iff $y \ne 0$. So you might as well choose $\lambda = y = 1$, $x = 0$.

When $\ker(\beta) = \im(\beta)$, let $e\_1 \in \ker(\beta)$ be non-zero, and choose $e\_2 \notin \ker(\beta)$ to get
$$ B =
\begin{bmatrix}
0 & \lambda\\
0 & 0\\
\end{bmatrix}
$$
for some non-zero $\lambda$. For $A B = 0$ we need
$$A =
\begin{bmatrix}
0 & x\\
0 & y\\
\end{bmatrix}
$$
or $\alpha(e\_1) = 0$. Now
$$
B A =
\begin{bmatrix}
0 & \lambda y\\
0 & 0\\
\end{bmatrix},
$$
so again choose $y \ne 0$.

If you want an $n \times n$ example, with $n \ge 2$, take $n \times n$ block matrices
$$
\begin{bmatrix}
A & 0\\
0 & 0\\
\end{bmatrix},
\begin{bmatrix}
B & 0\\
0 & 0\\
\end{bmatrix}
$$
where $A, B$ are as above, and $0$ are zero matrices of the appropriate size.
Pick $\mathrm u, \mathrm v, \mathrm w \in \mathbb R^n \setminus \{0\_n\}$ such that $\neg (\mathrm u \perp \mathrm v)$ and $\mathrm v \perp \mathrm w$. Define

$$\mathrm A := \mathrm u \mathrm v^{\top} \qquad \qquad \qquad \mathrm B := \mathrm w \mathrm v^{\top}$$

whose traces are

$$\mbox{tr} (\mathrm A) = \mathrm v^{\top} \mathrm u \neq 0 \qquad \qquad \qquad \mbox{tr} (\mathrm B) = \mathrm v^{\top} \mathrm w = 0$$

Hence

$$\mathrm A \mathrm B = \mathrm u \underbrace{\mathrm v^{\top} \mathrm w}\_{= \mbox{tr} (\mathrm B)} \mathrm v^{\top} = \mbox{tr} (\mathrm B) \cdot \mathrm u \mathrm v^{\top} = \mbox{tr} (\mathrm B) \cdot \mathrm A = \mathrm O\_n$$

$$\mathrm B \mathrm A = \mathrm w \underbrace{\mathrm v^{\top}\mathrm u}\_{= \mbox{tr} (\mathrm A)} \mathrm v^{\top} = \mbox{tr} (\mathrm A) \cdot \mathrm w \mathrm v^{\top} = \mbox{tr} (\mathrm A) \cdot \mathrm B \neq \mathrm O\_n$$