Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!

Campbell Ritchie

+ Follow
since Oct 13, 2005
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 Campbell Ritchie

Arun Singh Raaj wrote:. . . The explanation says if the String object is not found in Pool . . .

No, it doesn't. The method documentation says,

if the pool already contains a string equal to this String object

That is different from what you wrote. It looks to see whether there is a String in the pool equal to the current String.If such a String is found, it is substituted for the operand. Otherwise the current String is added to the pool.
13 hours ago
Yes, that would fit the letter of the law, but it still looks like quibbling to me.

Arun Singh Raaj wrote:Thanks Campbell. . . .

That's a pleasure

Is "s" referencing "Hello" of Pool as well as of main Heap?

Surely you know that already.
14 hours ago
They might be cleaning up by picking up cans littering the street, but not by taking them out of bona fide recycling bins.
14 hours ago
But throwing an exception or calling System.exit will mean the reference on line 5 never gets its non‑null status.
If the HenHouse reference points to a valid non‑null object in that case, where is it?

I feel this thread is beginning to go round and round in little circles while we argue about whether the reference in line 5 is valid or not.
Have you read the documentation for the methods? ScheduledExecutorService#scheduleAtFixedRate(...) ScheduledExecutorService#scheduleWithFixedDelay(...)
In one case, with the arguments myRunnable, 3, 5, TimeUnit.SECONDS, you get a scheduled future which executes after 3″, 8″, 13″, 18″, 23″, etc.
You have a delay, start the task, and immediately start timing the next delay.
In the other case, if the task takes 1.5″, you would start the task at 3″, 9.5″, 16″, 22.5″, 29″, etc.
You have a delay, start and finish the task and later start timing the next delay.
15 hours ago
That video shows the pedestrian clearly visible far enough away maybe not to stop, but to slow down to a speed where the collision wouldn't be fatal. It is fortunate that the film stops before she is hit. It also clearly shows her studiously ignoring the traffic, which is a common habit of pedestrians. I had a case like that well over thirty years ago, coming up to the Welford Rd/Victoria Park Rd lights from Victoria Park Rd towards a green light. I didn't realise the chap walking across the lights wasn't watching the traffic until I thought I was too close to stop. Fortunately, he heard it when I hit the horn, and leapt out of the way. A human driver would have assumed somebody walking has seen them. Maybe unless they have ridden a bicycle round here, where pedestrians step out in front of you about one a mile. So a human driver could just as easily assumed the pedestrian was watching the road and kept going.
But the video shows the car taking no action about Ms Herzberg.
15 hours ago

Arun Singh Raaj wrote:Hello guys,
I'm confused about the information i came through about String;
Some say will create two objects . . . How far is it right?

That is something you don't actually need to know, but . . .
Isn't the String pool part of the heap?
One String object, the literal, is loaded into the String pool part of the heap at class loading time; the other is created when that code is executed.

. . . I have read about the intern() method that it makes sure only distinct objects will remain in the memory.

Where did they say distinct? All objects on the heap are distinct. I think they meant to say, “non‑equal”.

Does it mean that if I create "Hello" objects using new operator 1000 times and I perform intern() on one of them then rest 999 "Hello" will be destroyed from the Heap?

If you use code similar to that above, no. The literal will already exist and intern() will change the reference to point to that particular String object. Then one String object will become eligible for garbage collection (=GC). The rest of the code will determine when the other 999 become eligible for GC.

Thanks in advance.

That's a pleasure
15 hours ago

Niall Kev wrote:Thank you. . . . Thanks to all for your help

That's a pleasure. Interesting question

Try the following variants:-One returns an empty List and the other a two‑element List.
Oracle stopped 1.* names for the downloads with (I think) Java6. The download for Java5 is called jdk-1_5_0_xxx... and that for Java6 is called jdk-6uxxx....
18 hours ago

Dave Tolls wrote:. . . line 6 is only printing out smbToFile, and not smbFile. . . .

It goes to show you . . . . make sure all identifiers look different from one another.
18 hours ago

Alex Lee wrote:. . .  the singleton object is created independently with 2 created, or they are shared. . . .

That isn't a correct implementation of a singleton. If you access the factory method from two threads, it is possible for two distinct instances to be returned. The method in line 11 is dangerous; it might return null. I am not convinced that having both methods is consistent with the concept of a singleton at all. I also think that passing a cconfiguration is also inconsistent with the concept of a singleton.
If you are running two JVMs, as it would appear from the instructions you showed, each JVM will have its own instance because they represent separate worlds from each other.

Find a copy of Effective Java by Joshua Bloch pages 17‑18. You will there find that the easiest way to create a singleton is to create a one‑element enum. Otherwise, try this:-If you do some web searching, you will find that many people believe that singletons are usually a bad idea.
18 hours ago