How do I quickly generate a random prime number, that is for sure 1024 bit long?
Use a library function, such as OpenSSL. There's no need to write this yourself.
To trade memory for speed you could just generate them and store them in a list and then randomly pick one.
Edit: Naturally you can't generate them all so the best you could achieve is pseudo randomness at a high memory cost. Also this isn't good if you want it for security.
1024 is a lot. Are you sure a pseudo-prime won't do? In java pseudo primes are a part of JDK
Generate 1024 random bits. Use a random source that is strong enough for your intended purpose.
Set the highest and lowest bits to 1. This makes sure there are no leading zeros (the prime candidate is big enough) and it is not an even number (definitely not prime).
Test for primality. If it's not a prime, go back to 1.
Alternatively, use a library function that generates primes for you.