• 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

Octal Literal Max Number

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am ready the OCA 7 certification study book and read that you can have up to 21 digits in an octal number, not including the leading zero but when I tried to compile this line:



I got the following error:

Octal.java:8: error: integer number too large: 0111111111111

Please advise how I would write a 21 digit octal number or if this is incorrect, I will need to report that for the books errata notes.  Thanks for anyone's guidance!
 
Marshal
Posts: 4525
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't suffix the value with a L or l (lower case ell) character, it is understood to be and integer, not a long, and you will be limited to the maximum value of an int.
 
Charissa Thomas
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Completely forgot about that.  Thanks a bunch for your quick response!
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Charissa Thomas,

First of all, a warm welcome to CodeRanch!

Charissa Thomas wrote:Please advise how I would write a 21 digit octal number or if this is incorrect, I will need to report that for the books errata notes.


It is definitely not an errata item. Each integer literal in Java is by default an int. If you have a literal which is outside the range of an int, you need an indicator to tell the compiler it should be handled as a long and not an int; otherwise you'll end up with a compiler error (as you have experienced). Adding the L (or l) suffix will fix this compiler error. You'll find more detailed info in this post.

And here you'll find another topic about literals with a bunch of code snippets. And if you like to know what happens if you use suffix D (or d) and F (or f) in hexadecimal literals, you should definitely read this topic and this one.

Hope it helps!
Kind regards,
Roel
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic