0

I created one class :

public class CreateAccount {

    public static Date dNow = new Date();
    public static SimpleDateFormat WebsiteURL = new SimpleDateFormat ("E'-'yyyy'-'MM'-'dd'-'hh'-'mm'-'ss'-'a");
    public static final String DummyTime = WebsiteURL.format(dNow);

    public static void main(String[] args){

        WebDriver driver = new FirefoxDriver();
     .
     .
     .
     .
     .
}

and tried to save the WebsiteURL in a final object (DummyTime) in order to use it from another class :

public class SendMessage extends CreateAccount{

    public static void main(String[] args) {

        System.out.println(DummyTime);

}

The problem i have its that every time i call sendMessage , the value dummyTime prints changes. How can i store the WebsiteURL in a const variable that will exept one date and wont change it in the future?

Al.s
  • 300
  • 4
  • 20
  • every thing is ok with your example. if you are calling main of `SendMessage` every time, then it means a new jvm instance each time and therefore a new date value. Whats wrong in it ? – Shailesh Aswal Aug 19 '14 at 09:54

1 Answers1

1

"Call sendMessage" - is starting new jvm with invoking main methiod run SendMessage, you create new jvm, new class loader, new classes, new static variables. And all this new 'things' don't know about your previous run.

If you want to use some values between invoking jvm, you should store them in some files (db).

Natalia
  • 4,362
  • 24
  • 25