How do I get user's login name in Java without using any JNI stuff?

I found one example here:

http://javaalmanac.com/egs/javax.sec.../GetLogin.html

but the code won't compile because it choked up on this line:
Code:
	    Principal principals[] = (Principal[])subject.getPrincipals().toArray(new Principal[0]);
and I have no idea how to fix it. Can someone offer me some help?

below is what I imported for the little program:
Code:
import javax.security.auth.login.LoginContext;
import javax.security.auth.Subject;
thanks!!