There are two ways we can implement a WebSocket server endpoint via the Java API for WebSocket. We can either develop an endpoint programmatically, in which case we need to extend the javax.websocket.Endpoint class, or by decorating Plain Old Java Objects (POJOs) with WebSocket specific annotations. These two approaches are very similar, therefore, we will only be discussing the annotation approach in detail, and will briefly explain how to develop WebSocket server endpoints programmatically later in the chapter.
In this chapter, we will develop a simple web-based chat application, taking full advantage of the Java API for WebSocket.