Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 05:13 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
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
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 02:02 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
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, 10:41 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
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, 10:28 PM
Member
 
Join Date: Dec 2007
Location: So Cal
Posts: 4
comando2929 is on a distinguished road
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 10:36 PM. Reason: add signiture
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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 09:54 AM
why doesn't this short applet work? kim85 New To Java 1 01-20-2008 09:43 PM
VeryLong Integer.. help hey New To Java 4 12-14-2007 10:48 PM
Short key for getting list of opened classes in Eclipse Java Tip Java Tips 0 12-04-2007 12:11 PM
Integer vs int bugger New To Java 1 11-14-2007 10:13 PM


All times are GMT +3. The time now is 02:00 AM.


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