• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

stupid question

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[source]
java.util.Calendar calendar = java.util.Calendar.getInstance();
calendar.set(2003,9,5,13,0,0);
System.out.println(calendar.getTime());
System.out.println(Boolean.getBoolean("true"));
[console]
Sun Oct 05 13:00:00 CST 2003
false
[question]
why not:
Fri Sep 05 13:00:00 CST 2003
true
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello wang,
use calendar.set(2003,8,5,13,0,0);
The month starts from 0 (for jan). So for september use 8.

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
And for the code

This will print true if the System property named by the argument (which is "true" in the example) exists and is equal to the string "true".
And this type of key does not exists,hence it prints false.

Code can be modified as shown below to achieve the required ouput:

Regards,
Cody
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent explanations Pradeep and Cody!
Stub-
If you're ever in doubt regarding the behavior of a particular method call -- just check the API documentation, it will always explain what the expected behavior is:


java.lang.Boolean.getBoolean(...)
- Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.) A system property is accessible through getProperty, a method defined by the System class.
If there is no property with the specified name, or if the specified name is empty or null, then false is returned.



java.util.Calendar.set(...)
Sets the values for the fields year, month, date, hour, minute, and second. Previous values of other fields are retained. If this is not desired, call clear first.

Parameters:
year - the value used to set the YEAR time field.
month - the value used to set the MONTH time field. Month value is 0-based. e.g., 0 for January.
date - the value used to set the DATE time field.
hour - the value used to set the HOUR_OF_DAY time field.
minute - the value used to set the MINUTE time field.
second - the value used to set the SECOND time field.


** Note all the months are stored as Constants, so you can use those to define the date without worrying about the base 0 stuff:
calendar.set(2003,Calendar.SEPTEMBER,5,13,0,0)
BTW -- there are no stupid questions
[ September 05, 2003: Message edited by: Jessica Sant ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic