• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

long's L

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When will I need to explicitly add 'L' or 'l' to a number ?
I got from one mock exam that "
long l = 100; is illegal ?!
It works when I tired compiling .
In relation to that ..
char c = 100 -- works too ?! I thought that char only accept 'x' or '\uxxxx' as value ?
What exactly is happening here ?
 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The mock exam is wrong.
long myLong = 100; is valid.
char c = 100; is also valid. 100 is an int, but since it is a constant, the compiler knows that it will fit into the char. Char is just an int type that takes values of 0 to 16535.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, you meant 65535, right?
System.out.println( (int)Character.MAX_VALUE );
 
reply
    Bookmark Topic Watch Topic
  • New Topic