Tom Johnson

Ranch Hand
+ Follow
since May 11, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Johnson

The longevity of the t reference to the Tyre depends on where its declared. For example if its delcared locally within a method of the Test class then it will be eligible for garbage collection once the method ends, since there is no way to access the reference then.

Also Sahil, after 316 posts surely you know that
13 years ago
Why would a random number correspond to a capital letter?


The code above casts the int value 65 to a char, which converts it to an 'A', since 65 is the ASCII value for the 'A'. currentTimeMillis returns a large number (of milliseconds since the epoch) which is not going to correspond to any capital letter

See here for info on the ASCII to character mapping.
13 years ago
As an aside, you should create a new SimpleDateFomat an not parse date "one" inside the for loop. The value will remain the same each time so you should move it to the start of the method and reuse the result i.e.

14 years ago
my eyes

Please format the code so its readable!!
15 years ago

Joanne Neal wrote:

Michael McGrath wrote:Trinity College Dublin, Ireland's top university, ... with the acknowledged toughest Computer Science degree in the world - outside of a couple of top USA universities.



And I'm the greatest Java programmer in the world (as long as you exclude all those programmers that are better than me)



Good spot Joanne, I missed that....we have a little joke over here in Ireland about Trinity College students and how big-headed they are:

Q: "If you are on a bus and a stranger sits beside you; how will you know that they went to Trinity?"
A: "They'll tell you"

15 years ago
Any search to google will tell you that its called implicitly by the GC when it determines that the object cannot be reached. I believe putting anything much in it is discouraged, even to the point of never using it.
15 years ago
D'oh just in before me Henry
15 years ago
Because the compiler can see that FileNotFoundException cannot be thrown from the method as its a checked exception. The second snippet catches the parent class Exception, which will catch both checked and unchecked exceptions. So there is a chance (as far as the compile is concerned) that a runtime (unchecked) exception could occur in the try block, even though its empty. Hence the second one is allowed.
15 years ago
As far as I know it cant be done declaratively. You could use an aspect to advise the entry to the method and inspect the object passed in the aspect instead of the actual method, but in either case you have to write some code to do it....as far as I know anyway.

Actually just off the top of my head (may be way off) but could write some form of custom annotation?
15 years ago
Yep I tried that....the code that seems to be going wrong is in a utility jar that we use, which I cannot change. So to do what you suggest, I copied the methods from the utility jar into my class and called them instead....should be the same thing. Unfortunately not! I couldn't get the error to happen calling the copied code, even though its identical! I can only think the utility jar is compiled "differently" than my copied version....or does this even even make sense?
15 years ago
That is nothing to do with generics. You need to write some code to check your preconditions and throw an exception if they are not met
15 years ago
Thanks for the pointer....although I see that Math.pow simply delegates to StrictMath.pow while Math.round and StrictMath.round are the implemented exactly the same:


where floor is Math class simply delegates to StrictMath.floor.

So shouldn't calls to Math/StrictMath pow and round always return the same result, cross platform as well?
15 years ago
Hi,
We have a legacy Math utility class containing the following methods:


I realise it should be using BigDecimal everywhere but for the moment I can't change the code. What we are currently seeing is that in production on Websphere, the call


is returning 100.36999999, rather than 100.37. This does not happen in windows or in Tomcat. I have created a simple script and just called that exact line above (outside the application) and it works fine!

Following through the code, the result of the primitive subtraction is 100.36999999999989, which is seen in windows as well. When this passed to the roundDouble method, the factor is 10^8 = 100000000. This is multiplied by the input so its 100.36999999999989 * 100000000 = 10036999999. This is then rounded to the nearest int which is 10037000000. Finally we divide by the factor so its 10037000000 / 100000000 = 100.37.

I am getting 100.36999999 as the final result...so either the Math.round is truncating 10036999999, rather than rounding it or final divide 10037000000 / 100000000 is going wrong and returning 100.36999999.

Can anyone throw any ideas out why there would be a difference, especially between a running application calling a method and a simple script just calling the same method in the same jar on the same environment but outside the application, or any ideas on what could be going wrong?

Thanks

[ UD: added linebreak to preserve layout ]
15 years ago
I had a look at the JSTL sql tags and couldnt see anything how to do this. Possibly the reason is you shouldnt! Better not to have this sort of thing in JSP. I would recommend putting the database access in a business logic code i.e. a java class....