DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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, 06:57 AM
  2. Serious problem with a website!
    By Loham in forum Java
    Replies: 1
    Last Post: 06-13-2008, 08:11 AM
  3. Replies: 0
    Last Post: 10-25-2006, 08:58 PM
  4. How to execute a method of the class loaded
    By naveenkumarg1 in forum Java
    Replies: 1
    Last Post: 11-18-2005, 07:13 PM
  5. Multiple Java Financial NYC Job Openings
    By Recruitermd in forum Careers
    Replies: 0
    Last Post: 03-24-2005, 02:53 PM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links