The algorithm is given as follows:
Begin by guessing that the square root is x / 2. Call that guess g.
The actual square root must lie between g and x/g. At each step in the successive approximation, generate a new guess by averaging g and x/g.
Repeat step 2 until the values of g and x/g are as close together as the precision of the hardware allows. In Java, the best way to check for this condition is to test whether the average is equal to either of the values used to generate it.
My question is in relation to steps 2 and 3. Why do we make the new guess (g + x/g) / 2 and why do we compare this result to g and x/g to determine whether or not to terminate our loop ?
Newton's method approximates a zero of the function $f$ by iterating $$ x \mapsto x - \frac{f(x)}{f'(x)} $$ which has the geometric interpretation of finding the intersection between the $x$-axis and the tangent through the point $(x,f(x))$.
In the particular case of the square root, we use $f(x)=x^2-a$ whose zeroes are exactly at $x=\pm\sqrt a$. Then it so happens that the the iteration formula simplifies: $$ x - \frac{f(x)}{f'(x)} = x - \frac{x^2-a}{2x} = \frac{x + a/x}2 $$ so finding "the point where the tangent intersects the $x$-axis" and "the average of $x$ and $a/x$" turns out to produce the same result.
But it's only the former description that's Newton's method. The latter is specific to square roots, and should only be called "Newton's method" if we have actually derived it in the above way.
If, on the other hand, we arrive at $x\mapsto\frac{x+a/x}2$ by some other kind of heuristic or geometric reasoning, then what we get is just some approximation, which strictly speaking has nothing to do with Newton -- though observing that it is numerically equal to Newton's method can help explain why it works as well as it does.