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.
There is a quite easy general way to get an example. Saying $AB=0$ means that the image space of $B$ must be contained in the kernel of $A$, while $BA\neq0$ means the image of $A$ is not contained in the kernel of $B$. Clearly you won't get an example by choosing $A$ or $B$ to be zero or invertible, so their images and kernels have to be proper nonzero subspaces of the whole space $V=K^n$ these matrices act upon.

Now the rank-nullity theorem ties the dimensions of the kernel and image of the same matrix to each other (their sum must be$~n$), but that is *the only* inevitable relation. So you can start with a simple example for which $AB=0$, and if it happens that $BA=0$ too, you can modify say $B$ in such a way that you keep its image space unchanged, but modify its kernel (to not contain the image of $A$). For instance, let $A$ be a projection on some subspace $U$ of $V$ parallel to a complementary subspace $W$. To keep things simple take $U$ the span of an initial $k$ standard basis vectors and $W$ the span of the remaining $n-k$ vectors, so $A$ is diagonal with first $k$ diagonal entries equal to$~1$ and the remaining $n-k$ diagonal entries equal to$~0$. You can assure $AB=0$ by having $B$ be a projection on the subspace $W$ (which is the kernel of $A$). Now the kernel of $B$ has dimension$~k$, and we want this to *not contain*$~U$, image of $A$ which does have dimension$~k$ (so we just need those subspaces to differ). That excludes the most obvious choice of taking for$~B$ the projection$~P$ parallel to the complement $U$ of$~W$ (that's the diagonal matrix with entries $0$ where $A$ has$~1$ and vice versa).

There are at least two ways to fix this. One is to simply choose a different complement $U'$ of$~W$. This is easy to achieve, for instance by just changing one of the spanning (standard basis) vectors of $U$ to have a nonzero coordinate for one of the (final standard basis) vectors spanning $W$. An easier and more concrete approach is to take the (diagonal) matrix of $P$, and perform some column operation(s) on it, which will not change the image (column space), but it will in general change the kernel. For instance just permute some of the zero columns with nonzero columns, which will work fine. Quite likely the result will no longer be a projection matrix at all, so this is a more radical change than obtained by projecting parallel to a different complementary subspace.