File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes int, BigInt, double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "int, BigInt, double" Watch "int, BigInt, double" New topic

int, BigInt, double

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
When should we use int, bigint and double as data types in Java ??
I want to write a java class for Fraction numbers.
I am not sure whether I should declare my private members (numerators and denominators) as int, bigint or double or float ?

<a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a>
marc weber

Joined: Aug 31, 2004
Posts: 11343

If you're writing a Fraction class, then it will really help you to think this question through, because it will be fundamental to how your class works.

First, define your requirements for a "numerator" and a "denominator." Will these be whole numbers only? Or might they be floating point? What range will they require? Then list the basic characteristics for each of the types (int, long, double, BigInteger, BigDecimal...): Whole number or floating point? Range? Object or primitive? How do these correspond with your requirements?

Next, consider how you are going to be manipulating these values -- that is, how your methods will perform operations and what form the results will be in. Depending on your approach and your requirements for "precision," you might take a closer look at the BigDecimal class.
[ October 21, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: int, BigInt, double
It's not a secret anymore!