Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 04:13 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
Rep Power: 0
mew is on a distinguished road
Default Short/Integer
java.lang.Number has following subclasses:
BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short

I am exploring datatypes and I am confused when to use Short and when to use Integer. It appears to me that both can save same values.

Code:
		Short s = 22;
		Integer i = 23;
Thanks in advance.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-01-2007, 01:02 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,389
Rep Power: 3
hardwired is on a distinguished road
Default
Yes, up to the max value for the short data type. Then you have to use int up until you reach its max value. Then you have to use long.
Code:
System.out.printf("max short value = %d%n" +
                          "max int value   = %d%n" +
                          "max long value  = %d%n",
                           Short.MAX_VALUE, Integer.MAX_VALUE,
                           Long.MAX_VALUE);
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 09:41 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
Rep Power: 0
mew is on a distinguished road
Default
Great. That was helpful.
So using Integer for values less than 32767 is waste of memory.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-06-2007, 09:28 PM
Member
 
Join Date: Dec 2007
Location: So Cal
Posts: 4
Rep Power: 0
comando2929 is on a distinguished road
Default
If all your doing is storing and looking up the data, a short or byte is just fine. However, if you do any other processing with a non int type, it must be converted to an int which causes a slow down in calculations. This is further explained at.

Java Primative Speed
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by comando2929; 12-06-2007 at 09:36 PM. Reason: add signiture
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Integer Usage bluegreen7hi New To Java 11 01-24-2008 08:54 AM
why doesn't this short applet work? kim85 New To Java 1 01-20-2008 08:43 PM
VeryLong Integer.. help hey New To Java 4 12-14-2007 09:48 PM
Short key for getting list of opened classes in Eclipse Java Tip Java Tips 0 12-04-2007 11:11 AM
Integer vs int bugger New To Java 1 11-14-2007 09:13 PM


All times are GMT +2. The time now is 12:10 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org