aspose file tools*
The moose likes Beginning Java and the fly likes What is System.setProperty? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is System.setProperty?" Watch "What is System.setProperty?" New topic
Author

What is System.setProperty?

Phillipe Rodrigues
Ranch Hand

Joined: Oct 30, 2007
Posts: 165
with the execution of the below command where is the value set in the system?

System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");


Thanks,
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Memory only. Next time you start your application, this property will be gone.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Saurabh Deshpande
Ranch Hand

Joined: Aug 09, 2007
Posts: 33
Hi Rob,

Can you tell me if this System.setProperty will get set for the entire application or only for the method or class that it is invoked in?

My concern is I have System.setProperty done for Connection timeout.
And i want to have it for 1 specific url only and not for all the urls.

So, if I set this property in one method or class will it apply for all the URL connections?

Saurabh.


Saurabh Deshpande.
SCJP, SCWCD, SCEA Part 1
Doing Part 2 now....
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
From my research here, these properties can be persisted but how it happens is dependent on your operating system.

First there are system and user properties and they can be managed separately.

On Linux/Unix they are written to XML files in a hierarchical file that matches the package path. On a Windows platform they are actually stored in the registry and the user properties are separate for each user.

It allows a way for you to add the notion of user and system preferences to an application and have those preferences persist across logins.


------------------------
Bob
SCJP - 86% - June 11, 2009
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18662
    
    8

Originally posted by Saurabh Deshpande:
Can you tell me if this System.setProperty will get set for the entire application or only for the method or class that it is invoked in?
You could easily test this for yourself. In one method, call System.setProperty("test", "answer") and in another method, call System.getProperty("test") and see what you get.

Alternatively, ask yourself how something could be maintained just for the execution of one method without assigning a value to a local variable within that method.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Originally posted by Bob Ruth:
From my research here, these properties can be persisted but how it happens is dependent on your operating system.

First there are system and user properties and they can be managed separately.

On Linux/Unix they are written to XML files in a hierarchical file that matches the package path. On a Windows platform they are actually stored in the registry and the user properties are separate for each user.

It allows a way for you to add the notion of user and system preferences to an application and have those preferences persist across logins.

Aren't you mixing the System properties with java.util.Preferences? That's the one that is using the registry in Windows. I never heard of the System properties being written to the registry. I also just checked the Java 6 code for System and it's just a regular java.util.Properties object.
Bob Ruth
Ranch Hand

Joined: Jun 04, 2007
Posts: 320
Whoops, I do indeed stand corrected. My bad.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is System.setProperty?