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: 
The problem reduces to solving a system of linear equations.

Let

$$x=\left(
\begin{array}{cc}
 a & b \\
 c & d \\
\end{array}
\right)$$

$$y=\left(
\begin{array}{cc}
 e & f \\
 g & h \\
\end{array}
\right)$$

Now solve the 4 linear equations resulting from $x.y=0$

The solution with the maximum number of free parameters (which is the one with $a\neq 0,b\neq 0$) is

$$xs=\left(
\begin{array}{cc}
 a & b \\
 c & \frac{b c}{a} \\
\end{array}
\right)$$

$$ys=\left(
\begin{array}{cc}
 e & f \\
 -\frac{a e}{b} & -\frac{a f}{b} \\
\end{array}
\right)$$

it contains 5 free parameters and the products are

$$xs.ys = \left(
\begin{array}{cc}
 0 & 0 \\
 0 & 0 \\
\end{array}
\right)$$

$$ys.xs = \left(
\begin{array}{cc}
 a e+c f & b e+\frac{b c f}{a} \\
 -\frac{e a^2}{b}-\frac{c f a}{b} & -a e-c f \\
\end{array}
\right)$$

The choice 

$$\{a\to 1,b\to 1,c\to 0,e\to 1,f\to 0\}$$

gives

$$xx = \left(
\begin{array}{cc}
 1 & 1 \\
 0 & 0 \\
\end{array}
\right)$$

$$yy = \left(
\begin{array}{cc}
 1 & 0 \\
 -1 & 0 \\
\end{array}
\right)$$

EDIT

As to the number of free parameters: to begin with we have 8 parameters, the elemnts of the two matrices. The 4 euqations would reduce them to 8-4 = 4, but as at most three equations are independent, the number is 5.
Yet another more powerful (and maybe more "advanced"):

Let A be a given matrix, now $AB-BA$ can be rewritten with help of matrix multiplication and vectorization as: $M\_{AR}\text{vec}(B) - M\_{AL}\text{vec}(B)$, where $M\_{AR}$ is a matrix performing multiplication from the Right by $A$ and $M\_{AL}$ from Left by $A$.

We can now first pick a vectorization $\text{vec}$ and an objective matrix $C$ and try to solve $$\min\_B\{\|(M\_{AR}-M\_{AL})\text{vec}(B)-\text{vec}(C)\|\}$$

Where $C = AB-BA$ is something we can choose.