Forum Moderators: open
I think it can be done with java but I'm not sure how to do it.
I'm pretty sure you mean javascript, not java (these are two VERY different technologies).
What DrDoc gave is probably the best solution, because it won't make a problem for your visitors who have disabled javascript in their browser. And well-behaved spiders will listen to those instructions -- however, not all spiders are well-behaved.
So, if you want to use javascript to be sure that rogue spiders don't follow the links:
<a href="#" onClick="location='page.html'">link</a>