Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how to detect OS in java

Reply
Thread Tools

how to detect OS in java

 
 
S!mb@
Guest
Posts: n/a
 
      07-14-2004
Hi,

I'm looking for a way to detect on which OS my program is running.
Is there a variable or someting ?

thanks in advance,

jerem.
 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      07-14-2004
S!mb@ wrote:

> Hi,
>
> I'm looking for a way to detect on which OS my program is running.
> Is there a variable or someting ?
>
> thanks in advance,
>
> jerem.


Hi Jerem,

String os = System.getProperty("os.name");

See also the complete list of system properties at
http://java.sun.com/j2se/1.4.2/docs/...getProperties()

--
Thomas<dot>Fritsch<squiggle>ops<dot>de

 
Reply With Quote
 
 
 
 
S!mb@
Guest
Posts: n/a
 
      07-14-2004
Thomas Fritsch wrote:
> Hi Jerem,
>
> String os = System.getProperty("os.name");
>
> See also the complete list of system properties at
> http://java.sun.com/j2se/1.4.2/docs/...getProperties()
>
>


thx a lot

jerem
 
Reply With Quote
 
Alan Meyer
Guest
Posts: n/a
 
      07-14-2004

"S!mb@" <S!mb@nop> wrote in message
news:40f52b6e$0$29377$(E-Mail Removed)...
> Hi,
>
> I'm looking for a way to detect on which OS my program is running.
> Is there a variable or someting ?
>
> thanks in advance,
>
> jerem.


As a followup to Thomas' correct answer, here's a little
program to show all properties. I haven't done any
real exception handling. If you get the message
"Completed=false", you'll have to check for actual
exceptions like SecurityException.

Alan

import java.util.*;

class GetProp {

public static void main (String[] args) {

boolean completed = false;

try {
Properties py = System.getProperties();
Enumeration e = py.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = System.getProperty (key);
System.out.println (key + " = " + value);
}
completed = true;
}
finally {
System.out.println ("Completed=" + completed);
}
}
}


 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      07-14-2004
Hi Alan,

Alan Meyer wrote:

>"S!mb@" <S!mb@nop> wrote in message
>
>
>>I'm looking for a way to detect on which OS my program is running.
>>Is there a variable or someting ?
>>
>>

>...
>
>import java.util.*;
>
>class GetProp {
>
> public static void main (String[] args) {
>
> boolean completed = false;
>
> try {
> Properties py = System.getProperties();
> Enumeration e = py.propertyNames();
> while (e.hasMoreElements()) {
> String key = (String) e.nextElement();
> String value = System.getProperty (key);
> System.out.println (key + " = " + value);
> }
>
>

// BTW: you can replace the 7 lines above by:
System.getProperties().store(System.out, null);

> completed = true;
> }
> finally {
> System.out.println ("Completed=" + completed);
> }
> }
>}
>
>
>

--
Thomas<dot>Fritsch<squiggle>ops<dot>de

 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      07-14-2004
In article <(E-Mail Removed)>,
Thomas Fritsch <(E-Mail Removed)> wrote:

> Hi Alan,
>
> Alan Meyer wrote:
>
> >"S!mb@" <S!mb@nop> wrote in message
> >
> >>I'm looking for a way to detect on which OS my program is running.
> >>Is there a variable or someting ?
> >>

> >...
> >
> >import java.util.*;
> >
> >class GetProp {
> >
> > public static void main (String[] args) {
> >
> > boolean completed = false;
> >
> > try {
> > Properties py = System.getProperties();
> > Enumeration e = py.propertyNames();
> > while (e.hasMoreElements()) {
> > String key = (String) e.nextElement();
> > String value = System.getProperty (key);
> > System.out.println (key + " = " + value);
> > }
> >

> // BTW: you can replace the 7 lines above by:
> System.getProperties().store(System.out, null);
>
> > completed = true;
> > }
> > finally {
> > System.out.println ("Completed=" + completed);
> > }
> > }
> >}


Using the store() method is canonical and more economical, but a
security manager may preclude using getProperties(). In
particular, "...if the security manager does not permit the
getProperties operation, it may choose to permit the
getProperty(String) operation."

John
----
jmatthews at wright dot edu
www dot wright dot edu/~john.matthews/
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      07-14-2004
On Wed, 14 Jul 2004 19:12:48 GMT, John B. Matthews wrote:

> In
> particular, "...if the security manager does not permit the
> getProperties operation, it may choose to permit the
> getProperty(String) operation."


'Unsigned Applets' is one distinct case in point.

I had to call the properties by name in my unsigned,
java 1.1 compatible properties applet here..
<http://www.physci.org/pc/property.jsp>

In contrast, the Java Glossay's 'WassUp' applet is
signed, and can delve deeply into the system guts..
<http://mindprod.com/wassup.html>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java on Pocket PC - detect file changes - activesync Frank Wedekind Java 2 04-28-2007 09:04 AM
how to detect a hard link in Java? jojo Java 29 09-06-2005 05:56 PM
use serialver to detect serialization problems between java 1.5 and earlier versions? robert_dodier@yahoo.com Java 0 01-26-2005 10:37 PM
Detect Java enabled browser Ryan Stewart Java 4 12-25-2004 04:29 AM
Is there a way to detect from a java class (outside the server) if JBoss is currently running? Peter Blatt Java 0 10-09-2004 02:56 PM



Advertisments