The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-18-2009
smartgupta smartgupta is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 109
Not able to execute the method based on OS in JAVA

Hi,

In my application,I want to find out the OS name and based on OS I want to do some specific operations.So I write some code based on it in JAVA but I am able to get the OS name but Not able to use the method specific to OS.I write a simple code to check it and found that it is not going to the if statement.code is as follow--

Quote:

public class OSnane {

public static void main(String[] args) {

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

System.out.println("OS name="+OsName);
if(OsName == "SunOS")
System.out.println("hello Sun");
else if(OsName == "Windows XP")
System.out.println("Hello Windows");
else if(OsName == "Linux")
System.out.println("Hello Linux");
else
System.out.println("No OS selected!!!");


}

}
and the Output is:

Quote:
OS name=SunOS
No OS selected!!!

So please tell me how can I Use methods based on OS.
Thanks in Advance ...