Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: integer number too large - don't understand

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default integer number too large - don't understand

    import javax.swing.*;
    public class TestInt
    {
    public static void main (String[] args)
    {

    long tooBig;

    tooBig = 2147483648;


    }
    }

    Jgrasp reports: TestInt.java:9: error: integer number too large: 2147483648
    tooBig = 2147483648

    Why is this?

    Thanks in advance


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: integer number too large - don't understand

    2147483648 is too large to be an int, and is being represented as a "literal int"
    2147483648L is the representation of a "literal long"

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: integer number too large - don't understand

    2147483648 is too large to be an int, and is being represented as a "literal int"
    But in the my code I have "Long TooBig"
    How is it being represented as a "literal int"?

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: integer number too large - don't understand

    When you type a series of digits, it is the literal representation of the number. In this specific case it is a literal int being assigned to a variable of type long.

    String s = 'c';
    Here, c is a character being assigned to a String variable, but it is still the literal representation of a character.

  5. The Following User Says Thank You to jps For This Useful Post:

    ProfAlex (September 24th, 2013)

  6. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: integer number too large - don't understand

    Can you please supply the correct code as I still don't fully understand.
    thanks

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: integer number too large - don't understand

    1234 is an int literal
    1234L is a long literal.

    2147483648 is too large to be an int
    If you want a value that large, define it as a long by adding an L to the end
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    ProfAlex (September 24th, 2013)

Similar Threads

  1. I don't understand what's wrong in my programme
    By si3012 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 16th, 2013, 07:58 AM
  2. [SOLVED] Gotten easy code by proffessor that I don't understand, do you?
    By matitorn in forum Java Theory & Questions
    Replies: 7
    Last Post: October 9th, 2012, 01:30 PM
  3. Don't understand void methods, need help!
    By alex067 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 9th, 2012, 07:02 AM
  4. Simply don't understand minimax...
    By Herah in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 13th, 2011, 12:45 PM
  5. I don't understand what I'm supposed to do
    By dmcettrick in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 11th, 2011, 09:34 AM