You are on page 1of 6

JAVAPEDIA.

NET JMS INTERVIEW QUESTIONS

1. What is JMS (Java Messaging Service)?

JMS (Java Messaging Service) is a messaging standard that


allows J2EEapplication components to create, send, receive, and read
messages.

JMS defines an enterprise messaging Java API that makes it easy to write
business applications that can exchange business data and events
asynchronously and reliably in a vendor-agnostic manner.

2. How JMS (Java messaging service) is different from RPC (Remote Procedure
call)?

JMS provides asynchronous messaging while RPC is synchronous.

In RPC the client who invokes the method need to wait for the method to
complete the execution and return the control back to the invoker due to its
synchronous nature. In JMS the message sender just sends the message to the
destination and continues its own processing. The sender does not need to wait
for the receiver to respond as JMS is asynchronous.

3. What type of messaging is provided by JMS?

JMS provides two type of messaging.

 Synchronous
 Asynchronous

4. Explain Synchronous messaging in JMS.


In synchronous messaging, client waits for the server to respond to a message
before it continue its own processing.

5. Explain Asynchronous messaging in JMS.


In asynchronous messaging, client does not wait for a message from the server,
instead it automatically creates an event to trigger when response received
from server. For example, email and text messaging.

6. What are the advantages of JMS?


Asynchronous messaging.

Reliability. Ensures once and only once message delivery.

Loose coupling. JMS can be used in heterogeneous environments with


decoupled systems that can communicate over system boundaries.
7. Different types of Messaging models in JMS.
There are 2 types of messaging models that JMS provides,

 Point to Point,
 and Publish and Subscribe method.

8. Difference between Point to Point and Publish/Subscribe models in JMS.


In point to point communication (one producer and one consumer), the
producers and consumers of the message are defined. The producers push the
messages in the queues and the receivers retrieve them. It is highly reliable.

In publish and subscribe method (one producer and one or more consumer),
the producers publish the message and the subscribers who have subscribed to
that topic receive them. In this way, a message may be received, or processed,
by multiple consumers. It is unreliable however very fast.

9. Difference between topic and queue in JMS.


Queuing is used for one to one messaging and it supports point to point
messaging model while topic is typically used for one to many messaging and it
supports public subscribe model of messaging.

10. Name some of the other major JMS products available in the market.
IBM's MQ Series is one of the most popular product used as Message Oriented
Middleware. Some of the other products include SonicMQ, iBus etc.

All the J2EE compliant application servers come with its own implementation of
JMS.

11. What are the components of JMS?

 JMS provider.
 JMS client.
 Messages.
 Administered objects.
 and Native clients.

12. Explain the role of the JMS provider.


The JMS provider handles data conversion, security of the messages and the
client triggering. It specifies the level of encryption, security level of the
message and the best-data type for the non-JMS client.

13. Give an example of the publish/subscribe model in JMS.


JMS can be used to broadcast shutdown messages to clients connected to the
Weblogic server on module basis. If an application has many modules, each
module behaves like a subscriber to a named topic on the server receive and
process the message.
14. What are the important components of a JMS application?

 Session.
 Connection.
 Message.
 Message Producer and Consumer .
 Connection factory and destination.

15. What is JMS administered object?


JMS administered object refers to the preconfigured JMS object created by an
administrator for the use of JMS clients and placed in JNDI namespace.

16. What is JMS session?


A JMS session is a single-threaded context for sending and receiving JMS
messages, could be locally transacted, non-transacted or distributed transacted.

17. Difference between durable and non-durable subscription in JMS.


Durable subscription enables the subscriber to receive all messages from a
topic, while a non-durable subscription does not make any guarantees about
messages sent by others when a client get disconnected by others.

18. Different types of messages available in JMS API.


The different types of messages available in JMS API are,

 StreamMessage,
 TextMessage,
 BytesMessage,
 ObjectMessage,
 and MapMessage.

19. Can JMS be used to send an email?


JMS has no support for email operations.

20. What is Message object in JMS?


Message is a light weight message having only header and properties and no
payload. If receivers are to be notified about an event, and no data needs to be
exchanged then using Message can be very efficient.

21. What is the use of BytesMessage in JMS?


Byte message is a stream of uninterrupted bytes. It contains an array of
primitive bytes in its payload. For the transfer of data between two applications
in their native format, byte message is used, which may be not possible with
other message types.

22. Describe the use of StreamMessage in JMS.


StreamMessage carries a stream of Java primitive types as it's payload. Unlike
ByteMessage, there are restrictions on the way the data is read to avoid
erroneous output. StreamMessage prevents reading a long value as short,
something that is allowed in case of BytesMessage. SreamMessage enforces a
set of strict conversion rules which actually prevents reading of one primitive
type as another.

23. What is the use of TextMessage in JMS?


TextMessage contains instance of java.lang.String as its payload. Thus it is very
useful for exchanging textual data. It can also be used for exchanging complex
character data such as an XML document.

24. What is the use of ObjectMessage in JMS?


An ObjectMessage object is used to send a message that contains a serializable
object in the Java programming language ("Java object").

25. What is the use of MapMessage in JMS?


A MapMessage holds name-value pair as its payload thus it is similar to the
java.util.Properties object of Java. The values can be Java primitives or its
wrappers.

26. Wat is JMS client?


An application or process/component that produces and/or receives messages.

27. What is JMS producer and Consumer?


JMS producer is a JMS client that creates and sends messages.

JMS consumer is a JMS client that receives messages.

28. What is JMS queue?


A staging area that contains messages that have been sent and are waiting to
be read. Note that, contrary to what the name queue suggests, messages don't
have to be delivered in the order sent. If the message driven bean pool contains
more than one instance then messages can be processed concurrently and thus
it is possible that a later message is processed sooner than an earlier one. A
JMS queue guarantees only that each message is processed only once.

29. What is JMS topic?


A distribution mechanism for publishing messages that are delivered to multiple
subscribers.

30. Describe Messaging.


Messaging is a method of communication between software components or
applications. A messaging system is a peer-to-peer facility: A messaging client
can send messages to, and receive messages from, any other client. Each client
connects to a messaging agent that provides facilities for creating, sending,
receiving, and reading messages.

Messaging enables distributed communication that is loosely coupled.


Messaging is different from electronic mail (e-mail), which is a method of
communication between people or between software applications and people.
Messaging is used for communication between software applications or software
components. Messaging is a mechanism by which data can be passed from one
application to another application.

31. Explain the difference between Java Mail and JMS Queue.
JMS is the ideal high-performance messaging platform for intrabusiness
messaging, with full programmatic control over quality of service and delivery
options.

JavaMail provides lowest common denominator, slow, but human-readable


messaging using infrastructure already available on virtually every computing
platform.

32. How does a typical JMS client perform the communication using JMS.

 Use JNDI to locate administrative objects.


 Locate a single ConnectionFactory object.
 Locate one or more Destination objects.
 Use the ConnectionFactory to create a JMS Connection.
 Use the Connection to create one or more Session(s).
 Use a Session and the Destinations to create the MessageProducers and
MessageConsumers needed.
 Perform your communication.

33. Define a JMS application.


A JMS application can have one or more JMS clients that exchange messages.

34. What is the difference between Byte Message and Stream Message?
Bytes Message stores data in bytes. Thus the message is one contiguous stream
of bytes. While the Stream Message maintains a boundary between the different
data types stored because it also stores the type information along with the
value of the primitive being stored. Bytes Message allows data to be read using
any type. Thus even if your payload contains a long value, you can invoke a
method to read a short and it will return you something. It will not give you a
semantically correct data but the call will succeed in reading the first two bytes
of data. This is strictly prohibited in the Stream Message. It maintains the type
information of the data being stored and enforces strict conversion rules on the
data being read.

35. How does the Application server handle the JMS Connection?

 App server creates the server session and stores them in a pool.
 Connection consumer uses the server session to put messages in the
session of the JMS.
 Server session is the one that spawns the JMS session.
 Applications written by Application programmers creates the message
listener.

You might also like