Initialize a long in Java Initialize a long in Java java java

Initialize a long in Java


  1. You should add L: long i = 12345678910L;.
  2. Yes.

BTW: it doesn't have to be an upper case L, but lower case is confused with 1 many times :).


  1. You need to add the L character to the end of the number to make Java recognize it as a long.

    long i = 12345678910L;
  2. Yes.

See Primitive Data Types which says "An integer literal is of type long if it ends with the letter L or l; otherwise it is of type int."


You need to add uppercase L at the end like so

long i = 12345678910L;

Same goes true for float with 3.0f

Which should answer both of your questions