nerdexam
Oracle

1Z0-900 · Question #1

You need to develop a chat application, which allows the display of emoticons and images together with text messages. How should you configure a WebSocket endpoints to receive both text and binary…

The correct answer is D. Create two @onMessage methods, each with appropriate decoder attribute in the same. Option D is correct because the Java WebSocket API (JSR 356) allows a single endpoint to have at most one @OnMessage for text and one for binary messages, and using the decoder attribute on each method enables the endpoint to properly deserialize incoming data into meaningful…

Create Java Applications using WebSockets

Question

You need to develop a chat application, which allows the display of emoticons and images together with text messages. How should you configure a WebSocket endpoints to receive both text and binary messages?

Options

  • ACreate two @onMessage methods in the same endpoint with appropriate parameter types.
  • BDefine the @onMessage methods in your endpoint with Object as parameter and check the actual
  • CYou can achieve this only by creating separate WebSocket endpoints for each message type.
  • DCreate two @onMessage methods, each with appropriate decoder attribute in the same

How the community answered

(43 responses)
  • A
    5% (2)
  • B
    7% (3)
  • C
    16% (7)
  • D
    72% (31)

Explanation

Option D is correct because the Java WebSocket API (JSR 356) allows a single endpoint to have at most one @OnMessage for text and one for binary messages, and using the decoder attribute on each method enables the endpoint to properly deserialize incoming data into meaningful domain objects - for example, converting raw text into an Emoticon object and raw bytes into an Image object.

Why the distractors are wrong:

  • A is close but incomplete - two @OnMessage methods with basic parameter types (e.g., String and ByteBuffer) can distinguish text from binary, but without decoders the endpoint cannot convert those raw payloads into the rich objects (emoticons, images) the application needs.
  • B is invalid - the WebSocket API does not support Object as a catch-all parameter type for @OnMessage; you must declare specific types or use a decoder.
  • C is unnecessary and architecturally wasteful - a single endpoint with proper decoders is the intended design pattern; splitting into two endpoints adds complexity for no benefit.

Memory tip: Think of decoders as the WebSocket equivalent of JSON deserializers - one @OnMessage + one decoder per message type, all within the same endpoint. "Two methods, two decoders, one endpoint" = D.

Topics

#WebSocket endpoints#@onMessage decoder#binary/text messages#message type handling

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice