One way to explain the connection is via the Hodge decomposition of the (singular) cohomology groups of an algebraic variety.
On one hand, viewing $X$ as a two-dimensional real manifold, and using say Mayer--Vietoris, one proves that $H_1(X,\mathbf{Z}) \cong \mathbf{Z}^{2g}$, and hence by duality, $H^1(X,\mathbf{C}) \cong \mathbf{C}^{2g}$.
On the other hand, let's upgrade Riemann's theorem to the Riemann--Roch theorem, which says that if $K$ is the canonical bundle (i.e. the bundle of holomorphic 1-forms) on $X$, then
$$l(D)-l(K-D) = \mathrm{ deg}\, D + 1 -\gamma.$$
(I changed $g$ to $\gamma$ because a priori this isn't the same as the previous $g$; indeed, that's what we want to prove.) Applying this with $D=0$ we get
$$1-l(K) = 1-\gamma$$
hence $l(K)=\gamma$. Now $l(K)$ by definition means the dimension of the space of global sections of the bundle $K$ of holomorphic 1-forms on $X$. Another notation for the same space is $H^0(X,\Omega^1)$, so we have $\mathrm{dim} \, H^0(X,\Omega^1)=\gamma$.
The statement of Hodge decomposition for curves is the following:
\begin{align}
H^1(X,\mathbf{C}) = H^0(X,\Omega^1) \oplus H^1(X,\mathcal{O}_X) \end{align}
and moreover the two direct summands on the right-hand side are conjugate, hence have the same dimension $\gamma$. (Don't worry about what $H^1(\mathcal{O}_X)$ actually is if you don't know the definition of sheaf cohomology; all that matters is that it has dimension $\gamma$.)
Now we know the dimensions of both sides of the displayed formula from 1. and 2. above, and plugging them in we get
$$2g=\gamma+\gamma;$$
that is, $g=\gamma$!
Edit: Maybe it's worthwhile mentioning a simpler proof for plane curves of the equality of these two numbers.
First of all, it's easy to deduce from the Riemann–Roch theorem that the degree of the canonical line bundle $K$ is
$$\text{deg} \, K = 2\gamma - 2.$$
On the other hand, if $X$ is a smooth curve of degree $d$ in $\mathbf{P}^2$, one can write down an explicit nonzero regular differential $\omega$ on $X$, and observe that it has $d(d-3)$ zeroes. Since $\omega$ is a section of $K$, this shows that
$$\text{deg} \, K = d(d-3).$$
Comparing these two expressions for the degree, we find that $\gamma=\frac12 (d-1)(d-2)$.
So our goal is now to show that the topological genus $g(X)$ is also equal to $\frac12 (d-1)(d-2)$. To do this, we use the fact that $X$ is a degree-$d$ branched cover of $\mathbf P^1$ with $d(d-1)$ ramification points (to see this, project from a general point in $\mathbf P^2$). This gives the formula
$$\chi(X) = 2d -d(d-1);$$
since $\chi(X)=2-2g$, this simplifies to give $g=\frac12 (d-1)(d-2)$, as required.
When constructing an $n$-manifold, a $j$-handle is an $B^{j} \times B^{n-j}$, where $B^{k}$ is a $k$-ball and is attached to the rest of the manifold along $S^{j-1} \times B^{n-j}$, where $S^k$ is a $k$-sphere.
Since you are making a $2$-manifold,
- A $0$-handle is a $B^0 \times B^2$ (a disk) glued along $S^{-1} \times B^2 = \varnothing$. (Since we start with a $0$-handle, there is nothing to glue it to.)
- A $1$-handle is a $B^1 \times B^1$ (a rectangular strip) glued along $S^0 \times B^1$ (two opposite ends of the strip).
- A $2$-handle is a $B^2 \times B^0$ (homeomorphic to a disk) glued along $S^1 \times B^0$ (homeomorphic to a circle).
This image (from "Efficient Edgebreaker for surfaces of arbitrary topology" by Lewiner, Lopes, Rossignac, Vieira) starts with a $0$-handle in the upper-left, attaches a $1$-handle, then another, and finally fills in the "gap" between the unglued sides of the $1$-handles with a $2$-handle. (Montesinos, Classical Tesselations and Three-Manifolds, discusses this, with diagrams, in section 1.2.)
An equivalent way to specify a $2$-manifold is by identifications of a disk. Examples. The equivalence of these two descriptions is fairly straightforward.
- The edges of the polygon are given orientations and labels, each label appearing on two edges. The polygon is the $0$-handle.
- Each pair of edges having the same label are attached by a $1$-handle, respecting the orientation of the edges.
- Finally a $2$-handle is glued along the (long) circle that is the union of the unglued boundaries of the $1$-handles. (When thinking about the polygon with identifications, this $2$-handle is the identification of all the vertices of the polygon to one point.)
Let $M$ be the oriented, closed, genus $g$ $2$-manifold. It has a specification by a polygon with $2g$ edges. To specify the labels and orientations, we pick an orientation for the $2$-cell filling the polygon, which induces an orientation on the boundary (either clockwise or anticlockwise). Then we indicate by a superscript on the label whether the edge is oriented in the same direction ("$1$") or in the opposite direction ("$-1$"). Then a labelling of the polygon with identifications producing $M$ is $a_1 b_1 a_1^{-1} b_1^{-1} a_2 b_2 a_2^{-1} b_2^{-1} \dots a_g b_g a_g^{-1} b_g^{-1}$. As a handle decomposition:
- Start with the polygon (the $0$-handle) and pick an edge and a direction to proceed. WLOG, I pick clockwise to simplify the following description.
- Attach a $1$-handle to the edge and to the edge two edges clockwise, without any twists on the $1$-handle. Advance clockwise to the next edge.
- Attach a $1$-handle to the edge and to the edge two edges clockwise, without any twists on the $1$-handle. Advance clockwise by three edges (since the next two already hanve handles attached).
- Continue attaching pairs of handles as described above until all $2g$ edges have a handle attached. Then attach a $2$-handle to the circle formed by the unglued edges of all the $1$-handles.
Best Answer
This is probably best done with a sequence of examples.
On a sphere, any closed curve (read: loop) we cut along will disconnect the sphere:
I've shown this for one particular loop, but it's not hard to convince yourself it's true of any loop. So we can cut along $0$ loops without disconnected the sphere, making it genus $0$.
Next consider a torus. It's easy to find a loop which we can cut along so that the resulting surface is still connected, see here:
Of course, if we try to cut along any second loop, we will necessarily be left with a shape in two pieces.
Since we can cut along $1$ loop without disconnecting the shape, we say it has genus $1$.
Finally, let's consider a genus $2$ surface:
Again, you should convince yourself that any three cuts will result in multiple pieces, while here we were able to make $2$ cuts without disconnecting the surface. So this surface has genus $2$.
The case of higher genera (the plural of "genus") is similar.
Edit: Oh, and what does this have to do with handles? It turns out every (connected, oriented, compact) surface can be deformed into a sphere with handles. See this photo of a genus $3$ surface from wikipedia:
Notice we can make a cut in the middle of every handle while leaving the figure connected, but we can't cut anywhere else. This is some informal proof that the genus is equal to the number of handles your surface has.
I hope this helps ^_^