Dhar Desai

+ Follow
since Nov 01, 2004
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dhar Desai

Here's recursive version:

public static void genNumber(int i ,int j)
int k = (i*10) + 1;
if(i == 1111) return;
genNumber(k, ++j); //NOT j++

call genNumber(0,1) to start the whole thing.
15 years ago
This is fun:

String s ="1";
for(int i = 1; i <= 5; i++){
System.out.println(s.replace('1', ("" + i).charAt(0)));
s +="1";
15 years ago
From you description it seems like Machines depends on Stores. That is Machines calls methods on Stores. If that's the case, then Stores should be a remote object. The Machines object then would have to look up the RemoteStub from the rmi registry and use the stub to invoke remote methods.

If Stores also calls methods on Machines, then Machines has to be a remote object as well.
15 years ago
I used the Allen/Bambara book for the first part. Many of the questions are like the ones you find on the actual test.

The key to doing well is by doing as many sample tests as you can find.
"When using RMI-IIOP and using primary types as arguments they are passed-by-value but when using an object (e.g. DTO or VO) this is passed-by-reference - so long as it is serialised."

Not sure I understand this quote. A DTO is passed by reference? If it's serialzable shouldn't that be "pass-by-value"?
I did some more research on the topic.

Here's a reference. See esp. section 2.6.5

http://java.sun.com/j2se/1.4.2/docs/guide/rmi/spec/rmi-objmodel7.html. This refers to RMI-JRMP.

I assume the question refers to IIOP since this is what the EJB containers use.

But as I recall, JRMP is pass-by-value and pass-by-reference. RMI-IIOP also supports both.

Stubs must be passed over the network. What happens when you use JNDI to look up a home interface? You, the client, are getting a stub. Also, the client can have a reference to a stub. You can pass this stub around just like anyother object.

Now that I think about it there are several cases to consider. Assume you have a remote method "void doSomething(Object z) throws RemoteException"

You, the client, calls doSomething and pass in an object z. I'll take an educated guess at the result: I haven't actually tried out all these scenarios. Let me know if something is inaccurate.

1) The class of z does not implement Serializable or Remote. Result: runtime exception.

2) The class of z does implement Serializable but not Remote. Result: z is packaged into a stream of bytes and sent over the wire to the remote object.

3) The class of z implements Remote, but is not Serializable. Futhermore, z has been exported as a remote object in this JVM. Result: a stub is created by the rmi runtime and sent over the wire.

4) The class of z implements Remote, but is not Serializable. Futhermore, z has NOT been exported as a remote object in this JVM. Result: a runtime error?

5) The class of z implements RemoteStub. Result: z is Serialzed and sent over the wire. If it implements RemoteStub then it is a stub object, which is Serializable.

The following scenario is why the original question is misleading:

6) The class of z implements both Serializable and Remote.
6a) z has been exported by to the rmi runtime. Result:
Send stub over wire.
6b) z has NOT been exported to the rmi runtime. Result: z is
itself serialized and sent over the wire.
Actually, I don't think the Saroda's linked list is bounded. The node is a multi-dimensional array with one row and two columns. The first cell contains the data and the second cell contains a reference to the next node.

Instead of using Object[1][2] as a node, it would be simpler to use Object[2], which is essentially the same thing.

It would be even simpler to use a class with two instance variables, one for the data and the other for the next node, as suggested by another poster.
15 years ago
Well, from the point of view of the client, the stub is the remote object.

If I am a client a have a remote stub for remote object A and a remote stub for remote object B, I can pass B to one of A's methods.

B b = getB(); //returns a stub with remote interface B
A a = getA(); //returns a stub with remote interface A.
a.someMethod(b); //see, here the class of object referenced
// by b is a stub implementation: the stub is what
//is passed and the stub is what is sent.

On the other hand we could do this:

B b = new SomeClassThatImpelentsRemoteInterfaceB();
export(b); //somehow exports b. This instantiates the stub and makes
//it available to the rmi runtime. Note, b is not a reference
//to the stub; it is a reference to the actual remote object.

a.someMethod(b); //the object referenced by b (the actual remote object)
//is replaced by a stub for the remote object and then sent
//over the wire after serialization.

BUT, if b is not exported and SomeClassThatImpelentsRemoteInterfaceB also implements Serializable, the the object referenced by b not be replaced by a stub: it itself will be serialized and sent. At least, that's how I think it works.
I took the exam and passed but there's some confusion regarding one of the questions.

If an object implements the Remote and Serializable interfaces and it's passed as an argument to a remote object, does the object itself get passed or does the stub?

The self-test question answers say the stub is passed.

Is this right?

I think it depends. If the object is exported (is this assumed by the question?) then yes, obviously, the ObjectOutputStream (or a subclass of it) replaces the object with its stub.

But if the object is NOT exported, then it's passed by value.
Actually, the fix turned out to be trivial. I switched to the java perspective from the navigation perspective. There was a red marker by the project name indicating there was a problem with some of the classes in the project. I fixed the problem and that allowed me to execute the class.

However, the class was just a test class and not dependent on any other classes in the project. But still, eclipse didn't allow me to execute it.

I am getting an error when I try to execute the main method of a class.

A diaglog pops up and says:
"Errors exist in required project. Continue launch?"

If I choose to continue (by hitting ok) the class is not executed.

So I save time, any tips?