not able to execute the method based on OS in JAVA


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: not able to execute the method based on OS in JAVA

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    1

    not able to execute the method based on OS in JAVA

    HI,

    I want to use same methods specific to OS but when I am trying to do so,I am only able to find out the OS name but it is not going inside that.I wrote a simple code as below --

    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 Output is

    OS name=SunOS
    No OS selected!!!
    So how can I use the method based on the OS..

    Thanks in advance....

  2. #2
    Join Date
    Apr 2008
    Location
    Finland
    Posts
    52
    if(OsName == "SunOS") // == doesn't work with string

    try this:
    if(OsName.equals("SunOS"))

Similar Threads

  1. How to call java method in jsp file?
    By erickh in forum Java
    Replies: 1
    Last Post: 12-18-2008, 07:57 AM
  2. Serious problem with a website!
    By Loham in forum Java
    Replies: 1
    Last Post: 06-13-2008, 09:11 AM
  3. Replies: 0
    Last Post: 10-25-2006, 09:58 PM
  4. How to execute a method of the class loaded
    By naveenkumarg1 in forum Java
    Replies: 1
    Last Post: 11-18-2005, 08:13 PM
  5. Multiple Java Financial NYC Job Openings
    By Recruitermd in forum Careers
    Replies: 0
    Last Post: 03-24-2005, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center