Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-get-example Java example program to get the operating system name of the system

Related Tutorials


 
 

Share on Google+Share on Google+

Java example program to get the operating system name of the system

Advertisement
Many times we need to know the current operating system name on which we are working. So in java we have "os.name" property which provides us the information about the current operating system name.

Java example program to get the operating system name of the system

     

java get Operating System name

Many times we need to know the current operating system name on which we are working. So in java we have "os.name" property which provides us the information about the current operating system name. We can get the current operating system's name by using the getProperty() method of java.lang.System in which we have to pass the property name as "os.name".

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

Above line of java code gets the OS name and assign it to a string variable. Now by printing this we can show the current operating system's name. Here is the full code of GetOSName.java as follows:

GetOSName.java 

import java.util.*;
import java.lang.*;
import java.net.*;

public class GetOSName
{
  public static void main(String args[]) {
  try{
  String osName= System.getProperty("os.name");
  System.out.println("Operating system name =>"+ osName);
  }catch (Exception e){
  System.out.println("Exception caught ="+e.getMessage());
  }
  }
}

Output:

C:\javaexamples>javac GetOSName.java

C:\javaexamples>java GetOSName
Operating system name =>Windows 2000

Download Source Code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Discuss: Java example program to get the operating system name of the system   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com