Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int, BigInt, double

 
varun bihani
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic