well, I'm unsure how Facebook's/Twitter's protocol works, and honestly it's probably not worth learning much about, other than the security measures they take that seem to work well; however, it seems you're wondering how a concept like this would work at all, which I can answer.
The way that networking works is with sockets, of which there are two types (TCP, and UDP -- for something like social networking, you'd use something like TCP, but online games usually use UDP). You can create a socket using an IP address, and a port number (1-65535); once the socket has been accepted on the server side from the requesting client side, the handshake is made and data can be transferred via packets. Then, it would be something all server-side to read through the database entries of social networking users, and getting their latest tweets, and sending this over that socket to the client on the other end.
In Java, you can simply use the java.net.Socket and related packages/classes for achieving this. I would suggest starting by reading this:
http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html Once you understand those concepts, you could work with networked data transfer pretty easily, and do things similar to what Facebook and Twitter do.