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



Java example program to get the operating system name of the system
Posted on: October 24, 2008 at 12:00 AM
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

Related Tags for Java example program to get the operating system name of the system:
javacideormformtimeiopropertymethodformatgetsystemvinameusingoperaidforworktoinformationlaneratingdescanpeimmancurrentinnormpassinfoasmntoutoperatingoscaoperatingosjesworkingemmeprosyswhichssoeeatanykhainfimeproperarrtropevassrenthavstabatimanyinforminformatpropprono


More Tutorials from this section

Ask Questions?    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
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.