nerdexam
Oracle

1Z0-900 · Question #36

Given the code fragment: How can you get all property names of a JMS message in the JMS consumer onMessage operation?

The correct answer is A. String [] props = msg.getPropertyNames(). Note on the stated correct answer: There appears to be an error in this question. In the actual JMS API (javax.jms.Message), getPropertyNames() returns an Enumeration, not a String[]. The real correct answer is B. --- Message.getPropertyNames() is defined in the JMS spec to…

Use Java Message Service API

Question

Given the code fragment:

How can you get all property names of a JMS message in the JMS consumer onMessage operation?

Options

  • AString [] props = msg.getPropertyNames();
  • BEnumeration props = msg.getPropertyNames();С. Iterator props = msg.getPropertyNames();
  • CList<String> props = msg.getProperties();

How the community answered

(62 responses)
  • A
    89% (55)
  • B
    8% (5)
  • C
    3% (2)

Explanation

Note on the stated correct answer: There appears to be an error in this question. In the actual JMS API (javax.jms.Message), getPropertyNames() returns an Enumeration, not a String[]. The real correct answer is B.


Message.getPropertyNames() is defined in the JMS spec to return Enumeration (or Enumeration<String> in JMS 2.0), making B the only type-compatible assignment. A (String[]) is wrong because getPropertyNames() does not return an array - that type never appears in the JMS Message API. C (Iterator) is wrong because the JMS API predates the Java Collections framework and deliberately chose Enumeration over Iterator. D (List<String> via getProperties()) is wrong because no such method getProperties() exists on javax.jms.Message at all.

Memory tip: JMS is a legacy API - think "old school Java." Enumeration is the pre-Collections-framework equivalent of Iterator, so whenever you see JMS returning a set of names, think Enumeration, not List, Iterator, or arrays.

If your exam source marks A as correct, flag it - it conflicts with the javax.jms.Message Javadoc.

Topics

#JMS#Message properties#Message API#Enumeration

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice