This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how is 1 second represent as a 'long' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how is 1 second represent as a Watch "how is 1 second represent as a New topic

how is 1 second represent as a 'long'

Harold Barnes

Joined: May 04, 2005
Posts: 6
how is 1 second represent as a 'long'? Is is 000000001000?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24190

Several methods in classes in Java deal in millisecond times. One second is 1000 milliseconds, yes. To write 1000 as a long literal, you could write 1000L; but in most cases just 1000 would do, as the int will be converted to a long as needed.

[Jess in Action][AskingGoodQuestions]
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1041
Originally posted by Harold Barnes:
how is 1 second represent as a 'long'? Is is 000000001000?

Another issue:
An integer or long literal that starts with a '0' is interpreted to be in octal. So 1000 = 1000(base 10) but 01000 = 1000(base 8) = 512(base 10).

IF I UNDERSTAND CORRECTLY, including that many zeros doesn't make the compiler use a long. It would look at 000000001000, recognize it as 512(base 10) and use a regular int.

If you want a long, use Ernest's suggestion of a trailing 'L'. (You could use a trailing lowercase 'l', but that looks too much like a one for my comfort. )

Have you checked out Aspose?
subject: how is 1 second represent as a 'long'
jQuery in Action, 3rd edition