• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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.)
 
Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic