Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static Boolean getBoolean();  RSS feed

 
Daniel .J.Hyslop
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem understanding in which context boolean getBoolean()should be used.The manual I am learning from and the API states that the method returns true if the system property named by the argument exists and is equal to the string "true";I have written a very simple program trying to get the method to return true , but cannot get it to this state.Obviously I am missing the point in the explanation in the APIie what is meant by "system property",,would someone be kind enough to explain , please.
here`s the simple BoolGetBool class:-


thankyou.
 
Abdulla Mamuwala
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try and run the program below for 'true' value,

Also try and understand the API below,
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html
and get back if you have doubts.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "system property" is a variable that is given a value by the Operating System or the Java Virtual Machine. Just like variables in your program, system poperties have a name as well as the assigned value. I don't know any boolean properties that I could use for an example.

However, it looks like what you really want to use is the Boolean.parseBoolean() method instead. This method will take the String argument and return true if its argument is equal to the String "true", ignoring case.

Notice how the arguments to these two methods are interpreted. The argument to getBoolean() is the NAME of a system property. This name is similar to a variable name in your Java program. Also, this name probably isn't the word "true". On the other hand, the argument to the parseBoolean() method is checked for equality with the word "true".

I hope this clears up the confusion here. Please let us know if you need more help.

Layne
 
Daniel .J.Hyslop
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi layne;
At the moment I am practising and experimenting using methods within the wrapper classes and the more system defined common classes within the API. I am accessing each of these classes and just trying to understand the mechanics of their methods by constucting my own classes and using their methods one class at a time,(the one thing that still puzzles me a bit is the use of static) I used the valueOf(String s) method as my first example in the Boolean class and measured that against the outcome of using getBoolean(String name),I did try quite a few variations of passing arguments to the later method but to no avail,obviously as you explained those arguments were not system orientated.Do command line arguments hold system property elements that would work,I`ll give it a go anyway and see,it won`t hurt to see what happens.
thanks for your reply ,if you would like to add to anything I`ve just said then please explain away.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!