This week's book giveaway is in the Security forum.
We're giving away four copies of Securing DevOps and have Julien Vehent on-line!
See this thread for details.
Win a copy of Securing DevOps this week in the Security forum!

Campbell Ritchie

Sheriff
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
178
In last 30 days
3
Total given
272
Likes
Total received
4961
Received in last 30 days
59
Total given
134
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

You are getting confused between the way primitive numbers are stored and how they are displayed. Writing 01 doesn't cause the number to be stored with a leading 0. Not at all. Leading 0s may however lead to errors because of the way you have declared it, as you will see from this Java® Language Specification section.
No, if you need to display the number in a particular format, try this Java™ Tutorials section. You will find that it is easy to print 201909 or similar.
8 hours ago
I hope I never have to go into your hospital

I presume the Queue classes do something similar to the Java® classes of the same name. So your priority queue will need some sort of sorting to do with the urgency of the situation, so you will need some way to compare time to live. But with the ordinary queues, what is going to happen? You are going to get people out of it in the same order they went in: remember a queue is usually FIFO. What are you going to do? Go through the whole queue and find the people with the shortest time to live?
Your methods are far too long. One of them is over 120 lines. That suggests either you should rethink the whole logic for that method, or it needs to be divided into lots of smaller methods, (or both).
8 hours ago
If that line is the same as line 4 in the first method you posted, also insert a line 228½:-There is a peculiarity about the %b tag that makes it print true if you have a non‑null and non‑Boolean reference type as the argument. More details about the tags in the Formatter documentation.
13 hours ago
. . . as well as that, why are you using thread local random?
13 hours ago
But that instruction only works for Windows®. Java® wasn't intended for OS‑specific tasks. You will need other instructions for OS/X or Unix (e.g. Solaris) or Android or Linux.
16 hours ago
Why are you using Java® code for that? You are abandoning platform independence.
16 hours ago

Onur Tokat wrote:. . . When I copied the answer, I realized. Sorry! . . .

Nothing to be sorry about. It goes to show you what a tiny change in the code can do.
16 hours ago
Welcome to the Ranch

This is an old thread and the original poster (=OP) will probably not reply. Please explain more about your query.
Welcome to the Ranch and well done finding the mistake for yourself.
16 hours ago
If you compare what you have just posted with what you posted originally, you will see that there is one ) after the 5, but that should read )). The answer given in the book that the code fails to compile is therefore correct.
16 hours ago
You can't get an Exception in two lines. I think what is happening is that the exception is thrown from line 4 and then passes on to the try in line 6 where it causes line 7 to complete abruptly. Then it passes to the catch, which can't catch it, so it passes on eventually to the main method where it causes the current thread to terminate. Please copy and paste the whole stack trace and indicate which line in your posted code corresponds to which line in the stack trace.
I don't think creating a new DB object will help. I also don't think creating a new DB object is a good idea; you probably want one connection to the database at any one time. It is possible to have multiple connections, but you have to take precautions about simultaneous updates to prevent dirty reads.
17 hours ago
Welcome to the Ranch

Which page was that code on? Are you sure you have copied it exactly? The code you posted does indeed print, “Too many,” but you might have corrected a compiler error when you copied it. There is no mention of such an error in the errata link Ron posted.
Duplicating this discussion in our exam forum.
17 hours ago
AH, Welcome to the Ranch

HO: Where are you creating the Connection object? You would appear to have declared it and not initialised it, in which case it will be null. Have a look at the JDBC tutorial; I think it is customary to create a Connection object as a local variable which must be closed when you terminate the application. Try with resources is probably the best way to close it.
17 hours ago
Welcome to the Ranch

Since you have the same responses in your other thread, I shall close this one to avoid duplication of effort.
19 hours ago