First off how much time and effort do you wish to put forth to this. If none then go and find another already done chat program.
Well the others have dirrected you to the right path, but here is what I would reccomend. Use the java.net.* pack. Make a server and client side programs.
You would have two programs, the server and the clients.
Create a ServerSocket for a server process. Have that guy except new users, and stores their IPs and user names when they logg in. Now once someone requests another user, put the username and IP in the same little lookup routines. Basically when someone asks for a user by username, all you have to do is look at tall the logged in usernames, and just reroute the IPs to them so they can establish a connection and chat. Or you handle all of the rerouting on the sever to keep IPs from being sent to other users, your choise!
Now on the client side you should set up a Socket object to connect to the Fixed IP location of the Server for a lookup and checkin. Now also give them a serversocket listener (a method on a specified port that accepts() data then reacts). Once you have decided how to route them, by security reasons, now all that is left is to do simple Java I/O back and forth thru the sockets, then route it to a small GUI or console based system. Lots of work, depends what you want this for, there are no easy solutions to anything in life, but hope that helped