Explain the concept of message passing in java with an example

Can someone please explain me the concept of message passing in java with an example?What does object invoking methods on other object means?

Replies

  • Whats In Name
    Whats In Name
    -bump
  • Kaustubh Katdare
    Kaustubh Katdare
    Whats In Name
    -bump
    Tagging #-Link-Snipped-# , #-Link-Snipped-# to look into this. I miss #-Link-Snipped-# as well.
  • avii
    avii
    Whats In Name
    Can someone please explain me the concept of message passing in java with an example?
    Tried Message Passing ?
  • Anoop Kumar
    Anoop Kumar
    I guess you are asking how two thread communicates each other. that is via message passing.
    This is generally done with shared memory (class variable, static variable).
    If not going inside complexity of multhithreading (It's not complex until you get what it is), use of Getter and Setter can be seen as message passing.
    Suppose you have a class of Dog, with two method setBark and getBark, what you do is you create a object of Dog--> set the value in setBark(String how) and then send the object as parameter to recieverObject where you can fetch using getBark()
    .
    If you go to Multithreading example, you can take producer-consumer problem, Unless producer doen't set the value consumer can't get it. For more you can see this#-Link-Snipped-#
    Hope you got what you are asking foršŸ˜€
  • avii
    avii
    Hey wait, shared memory is one of IPC, but in message passing how shared memory is used ? #-Link-Snipped-#

    In fact, in distributed systems, due to complexities of sharing memory we go with message passing for IPC. Please correct me if I am wrong.
  • Anoop Kumar
    Anoop Kumar
    avii
    Hey wait, shared memory is one of IPC, but in message passing how shared memory is used ? #-Link-Snipped-#
    In fact, in distributed systems, due to complexities of sharing memory we go with message passing for IPC. Please correct me if I am wrong.
    My bad for creating confusion with concept of shared memory.
    Yes, you are right. What I meant to say is solving problems related to message-passing to object.

    For example I took of Producer-consumer problem, By algorithm concept both producer and consumer share a common memory and first procedure get lock of shared memory to write things and then consumer checks for lock and when it find unlock then read that memory (Correct me, for this also been a while).
    Now, can we implement this in java,
    Yes by threading and using setter and getter.(I given the link in previous post)
    We can implement message passing in java in following ways...
    • In a class, class variable and/or static variable can be used for all object.
    • In a program we use object passing through parameters.
    • In same/across jvm we can use serialized object for message passing
    • In one jvm, between two application system/server properties can be used. like in Tomcat sever we use Application Context to pass object from one application to other.
  • sulochana anand
    sulochana anand
    Class dog {

    String br;

    Void Setbarking(String B)

    {

    B=br;

    }

    Void Getbarking()

    {

    s.o.p(B);

    }}



    Class dogbark

    {

    Pulic static void main(String args[])

    dog d=new dog()

    d.B=ā€barkā€;

    }}
  • Whats In Name
    Whats In Name
    sulochana anand
    Class dog {

    String br;

    Void Setbarking(String B)

    {

    B=br;

    }

    Void Getbarking()

    {

    s.o.p(B);

    }}



    Class dogbark

    {

    Pulic static void main(String args[])

    dog d=new dog()

    d.B=ā€barkā€;

    }}
    Is this an example of message passing?
  • sulochana anand
    sulochana anand
    yes as ianoop explained

You are reading an archived discussion.

Related Posts

Google Smartwatch is coming and if the recent leaks are to be believed, it'll be unveiled before Apple talks about their iWatch. After a lot of nonsense in the tech...
You sure have heard about the Li-Ion batteries (your smartphone might just have one) but have you heard about the Lithium-Air battery? The Li-Air battery stores 4x as much energy...
Okay, I have re-written THIS BOOK in LibreOffice & exported to PDF File. But again I am not satisfied with the quality of how this book looks.So, I am not...
It's been said that Linux Kernel 3.10 has received massive changes in the last several years.This changes is rated according to commit counts & potential actual lines. Here are some...
Hi. I am new to CrazyEngineers.