This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!

Elinor Chang

Ranch Hand
+ Follow
since Jul 30, 2003
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 Elinor Chang

As we all know SingleDateFormat is not thread safe. I have a project where I created a static instance of SimpleDateFormat and multiple MDBs are using the instance to format a String to a Date type. I got the following exception at times:

For input string: ""
- java.lang.NumberFormatException.forInputString(Unknown Source)
- java.lang.Long.parseLong(Unknown Source)
- java.lang.Long.parseLong(Unknown Source)
- java.text.DigitList.getLong(Unknown Source)
- java.text.DecimalFormat.parse(Unknown Source)
- java.text.SimpleDateFormat.subParse(Unknown Source)
- java.text.SimpleDateFormat.parse(Unknown Source)
- java.text.DateFormat.parse(Unknown Source)

EJB is known to be thread safe. I am using the SingleDateFormat in an EJB, why I am getting this exception?

Thanks
[ November 01, 2006: Message edited by: Elinor Chang ]
What happens of I map a 16 long number to a 9 long BigDecimal in Hibernate as the following:

Table definition

RATE_TOT DECIMAL(16,14),

Hiberate config

<property
name="rateTot"
type="java.math.BigDecimal"
column="RATE_TOT"
length="9"
>
<meta attribute="field-description">
@hibernate.property
column="RATE_TOT"
length="9"
</meta>
</property>

The RATE_TOT is a 16 long numeric field but in mapping file it's declared as 9 long. What happens to those additional 7 digits?

Thanks
Thanks everybody's input. Back to some questions you asked.

1. new BigDecimal(""+adouble) vs. new BigDecimal(adouble)

It's not silly to use the first constuctore because it ensure the BigDecimal has the exact number adouble represents. It's actually the best way to create a BigDecimal.

2. Using thread safe object.

We are using HashMap in session bean. Since EJB can garantee thread safe and we don't have the case when two thread modify the HashMap instance at the same time, I don't think the multi-threading is the culprit.

I will try to catch the run time exception and do something....

On the other hand, if anybody has experience in ILOG JRule Engine please let me know if the ILOG exeuction model does something funny when dealing with BigDecimal...

Thanks!
16 years ago
Thanks. I just posted a topic in the forum. Hopefully someone can shine some light on it. On the other hand, I doubt it's hiberate that causes it. Hibernate calls JDBC behind the scene. It might go all the way back to be a glitch on BigDecimal constructor that uses a String.

What do you think about the way of constructing a BigDecimal as the following:

double d = 0.1;
double b = -0.1
double e = d + b;
BigDecimal f = new BigDecimal(""+e);

My further invesitgation narrows the scope down to this line. Since the application does heavy duty scientific calculation, is it possible the ""+e becomes "0.00000000000null"? considering double doesn't keep the precision.

Thanks
16 years ago
Hello,

I am encountering a strange problem in retrieving data from database when the column is declared as decimal(16, 14). The data of the column is then saved as BigDecimal in java for further operation.

However I am getting random exception as the following when converting the BigDecimal to a double using .doubleValue(). Anybody has clause on why it happens? The exception happens randomly but persistantly...

Thanks


java.lang.NumberFormatException: For input string: "0.0000000000null"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1207)
at java.lang.Double.valueOf(Double.java:202)
at java.math.BigDecimal.doubleValue(BigDecimal.java:1033)
at sun.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
Three more line of error log. I don't use reflection when converting a BigDecimal to double using .doubleValue() but it seems the application does that itself. Any problem on that?

at sun.reflect.GeneratedMethodAccessor305.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
16 years ago
The JDK I am using is 1.4.2. App Server WebLogic 8.1 Sp3...
16 years ago
Here is the stack trace I have so far.

java.lang.NumberFormatException: For input string: "0.0000000000null"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1207)
at java.lang.Double.valueOf(Double.java:202)
at java.math.BigDecimal.doubleValue(BigDecimal.java:1033)

It happends when converting BigDecimal to a double not the other way around.

On the other hand, I don't set the BigDecimal which is obtained from Database table. The corresponding column was decleared as decimal(16, 14). I start to suspecting on the data retrival part. I am using Hibernate to get data...

Any idea?
Thanks for all your response so far.
16 years ago
Hello,

I am getting random run time exception when converting BigDecimal to double. The exception is the NumberFormatException. Since we are doing lots of scientific calucaltion, our precision is up to 14 position after the decimal point.

The exception is as the followings:

java.lang.NumberFormatException: For input string: "0.0000000000null"

I am sure the input string isn't "0.0000000000null" when I use it to create the BigDecimal object. It seems the object changes itself after hours application run.

Has anybody encountered similar problem? Again, the exception is random and not repeatable. It could happen anywhere.

Thanks
Elinor
16 years ago
If creating a HashMap with known capacity beforehand and the size of the HashMap will NOT change, is the HashMap object should be initilized with a capcacity as the following:

HashMap hm = new HashMap(100);

instead of

HashMap hm = new HashMap();

Is there performance impact if specifying the initial capcaity or not?

Thanks!
17 years ago
I don't quite understand the following mock exam question from the book:

Given a remote client R, that has valid reference to session beans A and B, and given that A is a local client to B, which statements are true? (Choose all that apply)

1. R cannot pass his reference for A, to B
2. A cannot pass his reference for B, to R
3. A cannot invoke methods on B
4. B cannot invoke methods on R

the answer is 2, 4

What does the question is all about? Why the answers?

Thanks
You are right. JLS does specifies all array types implement the Serializable interfaces. Thanks!
17 years ago
Sorry for the confusion. I didn't mean by Array type but an array of something in general. I'd like to find out if an array of object or primitive type, not just String[], is serializable. e.g. int[], String[], etc..
17 years ago
And what's the difference between using Arrays type and using String[]?

Thanks
17 years ago