There are three main types of sockets: stream, which uses TCP and is reliable; raw, which provides raw data transfer over IP; and datagram, which is message-oriented. Sockets can be used for unicast, multicast, and broadcast communication as well as loopback. To open a socket in Java for a client, create a Socket object; for a server, create a ServerSocket object and then accept incoming connections. Input and output streams are created using classes like DataInputStream and PrintStream, and sockets should be closed along with their streams to free resources.