• 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

GregorianCalendar -- Calendar.SECOND

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here all three Calendar.SECOND values are same. how? i am creating three different objects for each.

class sec {

public sec() {
GregorianCalendar cal2 = new GregorianCalendar();
int currentIndex2 = cal2.get(Calendar.SECOND);
System.out.println("constrctor..second2.."+currentIndex2);
}

public static void main(String args[]) {
sec se = new sec();

GregorianCalendar cal = new GregorianCalendar();
int currentIndex = cal.get(Calendar.SECOND);
System.out.println("second.."+currentIndex);

GregorianCalendar cal1 = new GregorianCalendar();
int currentIndex1 = cal1.get(Calendar.SECOND);
System.out.println("second1.."+currentIndex1);
}
}
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's really just turning out that way because your statements are being executed so quickly. Because your command take a matter of milliseconds to complete, it's very likely that all 3 Calendar objects will be created at the same second.

I added this line after the "new sec();" line:



It's just a simple way to ensure that the first Calendar object is created well before the others because the application gets stuck in this loop for quite a while.

When I did that, I found that the first object was created at "34" while the last two were created at "52". (Obviously, your results may vary.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic