File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to get non-null from Integer.getInteger(String propertyName) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to get non-null from Integer.getInteger(String propertyName)" Watch "how to get non-null from Integer.getInteger(String propertyName)" New topic
Author

how to get non-null from Integer.getInteger(String propertyName)

lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Hi,

I have tried various combinations to get integer value corresponding to a system property by executing the public sttatic methods
Integer.getInteger(String propertyName) and Long.getLong(String propertyName) but i was not succesfull in getting non-null value.



Please correct me if i am commitiing some mistake in my efforts.Pleaes guide me how can i get this method working ?


SCJP1.4, SCWCD1.4, SCBCD5.0(working on...)
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Originally posted by lalit upadheyay:




I don't think it is related to SCJP. Anyway I've got one question for you:
"Do you realy think that name of your OS can be an integer? And what about java home path?" Think about it.


SCJP 1.4 (100%) Done.<br />SCJD (URLyBird 1.2.3 Started)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Moving to Java In General (Intermediate?)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Hi George,

Pls. checkout documentation for method public static Integer getInteger(String nm) and tell me the answer. Please also checkout the SCJP1.4 exam objectives. Section 8 ( regarding Fundamental Classes in the java.lang Package ) contains reference to method getXxx(). Please tell me what is that.

Please do answer to my question.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It says in that documentation,


If there is no property with the specified name, if the specified name is empty or null, or if the property does not have the correct numeric format, then null is returned.


So what's your question? If you have an integer property, this method would return non-null; for example

System.setProperty("foo", "1");
Integer ii = Integer.getProperty("foo");

ii would be non-null, an Integer with value 1.


[Jess in Action][AskingGoodQuestions]
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Originally posted by lalit upadheyay:
Hi George,
Pls. checkout documentation for method public static Integer getInteger(String nm) and tell me the answer.


I know that Javaranch is "a friendly place for Java greenhorns" but I believe it's about industrious greenhorns. Think about it.

Originally posted by lalit upadheyay:

Please also checkout the SCJP1.4 exam objectives. Section 8 ( regarding Fundamental Classes in the java.lang Package ) contains reference to method getXxx(). Please tell me what is that.


Well. Since you already know that there is a documentation you can check it fo method getInteger(String) and see that there is Since 1.5 mark. As you can guess it is out of scope of SCJP 1.4

By getXxx () in objectives they mean method getInteger() without parameters.
[ August 08, 2005: Message edited by: George Bolyuba ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[George]: Well. Since you already know that there is a documentation you can check it fo method getInteger(String) and see that there is Since 1.5 mark. As you can guess it is out of scope of SCJP 1.4

Ummmm... no. There is no "since 1.5" on this method. Integer.getInteger() methods have been in the Integer class since the beginning. They are part of the SCJP 1.4 objectives - though not the objectives for 1.2 or 5.0.

By getXxx () in objectives they mean method getInteger() without parameters.

No, they don't. There is no getInteger() with no parameters. There are three overloaded versions of this method, but none with no parameters. Actually the 1.4 objectives don't use parentheses at all here. However many of us will include empty parens when discussing a method (even if there's not really a no-argument version of the method) because it seems useful to provide a visual indicator that we're talking about a method, but we don't want to get bogged down in naming all the parameters, especially if there are several overloads. Perhaps in these cases it would be more useful to say something like getInteger(*) rather than just getInteger(). Regardless, the practice of omitting method arguments in casual conversation is fairly widespread, and something to beware of.

Lalit, when they refer to getXxx, the Xxx is intended to represent a general pattern, which may be replaced with many different things. When the 1.4 objectives refer to the getXxx methods of wrapper classes, they mean any methods beginning with "get" found in the wrapper classes. These include:

Boolean.getBoolean(String)
Integer.getInteger(String)
Integer.getInteger(String, int)
Integer.getInteger(String, Integer)
Long.getLong(String)
Long.getLong(String, long)
Long.getLong(String, Long)

I think that's all, but if I've omitted (or added) any the API will have the correct info.


"I'm not back." - Bill Harding, Twister
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[B][EFH]:
[/B]
That should be getInteger, not getProperty.

Incidentally I think that the names of these methods are extremely poor - it would have made a lot more sense if they'd put them in System and given them names like

System.getPropertyAsBoolean(String)
System.getPropertyAsInt(String)
System.getPropertyAsLong(String)

I also think the behavior of the methods is rather poor. Returning null for either a missing property or a parsing error makes these methods unnecessarily difficult to debug.

Not that this is EFH's fault of course, I just wanted to complain to someone.
[ August 08, 2005: Message edited by: Jim Yingst ]
Georgy Bolyuba
Ranch Hand

Joined: Feb 18, 2005
Posts: 162
Duh... Some kind of eclipse was on me Now I look in javadocs and cannot get why I was thinking so...
lalit upadheyay
Ranch Hand

Joined: Jun 20, 2005
Posts: 110
Thanks to everyone involved in relieving some of my tension specially Bert Bates(post dated 4-Aug-2003), Jim Yingst , Ernest Friedman-Hill , and George. I was trying to visualise output of every method specified by SCJp1.4 Exam objective that was difficult to grasp theortically. I will find out its working after i clear my SCJP1.4 exam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get non-null from Integer.getInteger(String propertyName)