nerdexam
Oracle

1Z0-900 · Question #27

: 27 Given: Which client-side Java method will send the employee object to the WebSocket Server Endpoint?

The correct answer is A. session.post(employee). Note: The marked "Correct Answer: A" appears to contain an error. session.post(employee) does not exist in the Java WebSocket API (JSR 356). The actual correct answer is remote.sendObject(employee) (the last option). In JSR 356, a Session object exposes getBasicRemote() or…

Create Java Applications using WebSockets

Question

: 27 Given:

Which client-side Java method will send the employee object to the WebSocket Server Endpoint?

Exhibit

1Z0-900 question #27 exhibit

Options

  • Asession.post(employee);
  • Bcontainer.send(employee);С. session.send(employee);
  • Cremote.sendObject(employee);

How the community answered

(50 responses)
  • A
    90% (45)
  • B
    8% (4)
  • C
    2% (1)

Explanation

Note: The marked "Correct Answer: A" appears to contain an error. session.post(employee) does not exist in the Java WebSocket API (JSR 356). The actual correct answer is remote.sendObject(employee) (the last option).

In JSR 356, a Session object exposes getBasicRemote() or getAsyncRemote(), both of which return a RemoteEndpoint. That endpoint exposes sendObject(Object data), which serializes and transmits the object to the server - making remote.sendObject(employee) the only valid call.

Why the distractors are wrong:

  • session.post(employee) - Session has no post() method; this conflates WebSocket with HTTP/JAX-RS idioms.
  • container.send(employee) - WebSocketContainer manages connections but has no send() method.
  • session.send(employee) - Session has no direct send() method; sending is delegated to its RemoteEndpoint.

Memory tip: Think of it as a two-hop call - Session → getBasicRemote() → sendObject(). The remote variable holds the RemoteEndpoint, and sendObject is what does the actual transmission. If you see a method claiming Session can send directly without going through a RemoteEndpoint, it's wrong.

Topics

#WebSocket client API#Session object#Message serialization#sendObject()

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice