Wim Molenberghs

+ Follow
since Jan 31, 2008
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 Wim Molenberghs

An object is eligible for garbage collection when no object refers to it.

To put it in your example:

String s2=new String("java");

String s1 = s2; -> no GC
String s2 = new String("java2"); -> still no GC because s1 still has a reference to new String("java")
String s1 = new String("java3"); -> new String("java") is eligible for GC.

Thanks Reza

Reza Rahman wrote:
The stateless case is "working" accidentally because of the fact that the container only has one bean instance in the pool that is being re-used across look-ups/calls. Try running the clients in parallel and you will see a different result because the container will create more bean instances in the pool.

So a good practice is to never use instance variables which could have a state?

Reza Rahman wrote:
The stateful bean behavior is correct also. State should be maintained between invocations from the same client, not different clients (defined by the bean instance look-up).

Got it! I thought that if you run the client 2 times, it was like the same client.
But if a client is defined by the bean instance look-ups, I understand why my code always returns 1.

Reza Rahman wrote:
Out of curiosity, what EJB 3 reference are you using? Most should have explained why is the case?

I followed a course which was apparantly not good enough
I think I'll order a good book from Amazon tomorrow.
Hi ranchers,

I have some doubts about stateless en stateful session beans and I hope someone can point me to the right direction.

I've written the following code:

the bean:

and the client:

I would expect that, since it is a stateless bean, the output from the client is always 1 but if I run the client multiple times, the output is 1,2,3,4,...
So why keeps my bean his state and looks my stateless bean like a stateful??

Now, if I replace in my ejb the @stateless with @stateful

If I run my client, I expect an output of 1,2,3,4,... but instead, I get always an output of 1
So why doesn't keeps my bean his state and looks my stateful bean like a stateless??

Which book do you prefer to start with?
The one from Manning of the one from Head First?
14 years ago
because the max positive integer is not 2147483648 but 2147483647 because the 0 is also considered a positive int.
so if you have an int of 2147483648, it is out of range.
The couter of int goes:
yes, the main is also a thread.
don't forget this for the exam.
The books doesn't say "the program starts three threads" but "the program starts three threads that are all waiting to receive the finished calculation"

I can be wrong but the way I read this is that there are 3 threads that are waiting + a thread to finish the calculation.

And the program has not a total of 4 threads but 5 :-)
I think line 3 DOESN'T compile because it's not defined inside a method.
Line 1 and 2 are just classvariables.
[ May 10, 2008: Message edited by: Wim Molenberghs ]
Loose coupling refers to minimizing the dependence of an object on other objects. In other words, you can change the implementation of a class without affecting the other classes.These properties make the code extensible and easy to maintain.

For example, consider two classes, A and B. If they do not use each other at all (neither of them instantiates the other, invokes a method on the other, and so on), they are not coupled. If A uses B (for example, instantiates B) but B does not use A, then they are loosely coupled. If both A and B use each other, then they are tightly coupled.

Another criterion of loosely coupled classes is how they access each other�s members. Loose coupling demands that a class keep its members private and that the other class access them
through getters and setters

Originally posted by Mamadou Tour�:
But is one way better than the other ??

The one is not better or worser than the other because they are very different.

try to run the following code with the 2 diffent threads and tell us what you see

[ April 30, 2008: Message edited by: Wim Molenberghs ]
You hava a problem in your system.out

change System.out.println(i= " " + a[0]+ " " +a[1]);
System.out.println(i + "= " + a[0]+ " " +a[1]);
and it should work
I'm studying the 1.5 book but I'm going to take the 1.6 test within a month.

I will let you know if there are some questions on the exam who are not covered in the book.
Hi all,

I have the SCJP 5 book from Sierra and Bates.
If I've studied this book. Should I be able to pass the SCJP 6.0 test or are there so many differences between the fundamentals of java 5 and java 6?