The easiest method to generate the DH modulus and base (collectively called the "DH parameters") is to use values which have already been generated. This does not imply security issues -- several people can share the same DH parameters without trusting each other.
Technically, you need three values: the modulus p, the base g, and the sub-group order q. Ideally, q should be a prime integer, and gq = 1 mod p.
There are nice pre-generated values in RFC 3526 and RFC 5114.
If you want to make your own, then the basic algorithm is "try random values until you hit a prime", but there are details. You have basically two choices:
Generate random q values and compute p = 2q+1; do that until both q and p are prime. When you have found a q and p with these characteristics, then you can use g = 4 as base; it is guaranteed that g will have order exactly q.
Generate random q values of the "right size" for a sub-group order (say, 256 bits) until you find a prime q. Then generate random values r and compute p = qr+1 for each r; do that until you find a prime p. At that point, generate a random value h and compute g = hr mod p. That value g will have order q (it is theoretically possible but in practice highly improbable that you get g = 1; in that case, generate a new random h).
The first method allows the use of a very small g, which gives a slight performance advantage when using Diffie-Hellman (not a big advantage in practice, something like a +15% speed at most when proper optimizations have been applied). However, generating the modulus p with that method is quite expensive, because you have to try about a few millions of q values until you find one such that both p and q are prime.
With the second method, parameter generation is a lot faster, since it goes in two stages: first finding a prime q (a few hundred tries), then a prime p (a few thousand tries). It also gives you a relatively small sub-group order, which can be nice too. However, you end up with a "huge" base g. This method is really what is done in DSS, as specified in FIPS 186-4, so if you want a formal specification with all the details laid out, go read appendix A of that standard ("Generation and Validation of FFC Domain Parameters").
In any case, you will need computations on big integers, including modular exponentiations and primality tests. Java provides both in