6k +/- 1 is not a primality test! If you already know the number Q is prime (and greater
than 7), knowing that it's of the form 6k +/- 1 tells you whether it's "safe" -- that
Q+1 and Q-1 will both have large factors, making Q more difficult to factor (thus "safe" for cryptographic purposes). But most numbers of the form 6k +/- 1 will be composite.
"Safe Prime" page from Wikipedia
If want to write your own routine for testing 1000 digit numbers for primality, you'll want to use the BigInteger class as the other answers have suggested. You could use the Fermat
test first, which will tell you if the number is "definitely composite" or "probably prime".
You could then use a more computationally intensive test like Miller-Rabin or Solovay-Strassen
on the "probably prime" numbers for the final definitive test.
Primality testing algorithms from Wikipedia