File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes simple code verification using long variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple code verification using long variables" Watch "simple code verification using long variables" New topic
Author

simple code verification using long variables

Peter McCarthy
Greenhorn

Joined: Jan 22, 2006
Posts: 4
long now = System.currentTimeMillis();
long startValid = now;
long threeDays = 259200000;
long endValid = now + threeDays;

i have to alter some java code for a school project and i've never used java, only c++. does this code seem like it would work out OK? i'm not completely sure of the syntax in java. thanks.
Robert Hill
Ranch Hand

Joined: Feb 24, 2006
Posts: 94
By itself, the code you posted won't compile, of course.

But did you try to compile and run it?

why have 2 variables that store the same value(now and startValid)?
Peter McCarthy
Greenhorn

Joined: Jan 22, 2006
Posts: 4
Originally posted by Robert Hill:
By itself, the code you posted won't compile, of course.

But did you try to compile and run it?

why have 2 variables that store the same value(now and startValid)?


that's just a snippet from the whole code. everything compiles OK. I just wasn't sure if there was a certain way to initialize long values or add long values together that maybe I wasn't doing correctly, yet it was still able to compile.

as far as 2 variables storing the same value, those 2 lines were in the code given to me so i just didn't change them.

also, like i said, the code compiles and runs, but it's not doing what it should so i'm looking at it piece by piece to make sure i'm doing it all right.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2503
    
    8

also, like i said, the code compiles and runs, but it's not doing what it should so i'm looking at it piece by piece to make sure i'm doing it all right.


Hi Peter,

Actually the code by itself alone compiles as is inside main() of course. Now as long as the threeDays variable value is the amount of milliseconds in 3 days then the endValid variable should be milliseconds 3 days from now. What output are you expecting?


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

This code should be working as long as you don't consider daylight savings time.

If you do, java.util.Calendar would be better:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: simple code verification using long variables