
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine the OS Running on a Computer Using Java
The System class of java.lang package provides a method named getProperty() this method accepts one of the following string parameters an returns the respective property.
java.class.path − If you pass this value as a parameter, the getProperty() method returns the current classpath.
java.home − If you pass this value as a parameter, the getProperty() method returns the current Installation directory of the JRE.
java.vendor − If you pass this value as a parameter, the getProperty() method returns the current vendor name of the JRE.
java.vendor.url − If you pass this value as a parameter, the getProperty() method returns the current vendor URL of the JRE.
java.version − If you pass this value as a parameter, the getProperty() method returns the current version number of the JRE.
line.separator − If you pass this value as a parameter, the getProperty() method returns the value/sequence used by the current os to separate the lines in text files.
file.separator − If you pass this value as a parameter, the getProperty() method returns the character used to separate the directories in a file path (/ Or \).
path.separator − If you pass this value as a parameter, the getProperty() method returns the path separator of the classpath environmental variable.
user.dir − If you pass this value as parameter the getProperty() method returns the working directory of the user.
user.home − If you pass this value as parameter the getProperty() method returns the home directory of the user.
user.name − If you pass this value as parameter the getProperty() method returns the account name of the user.
os.arch − If you pass this value as parameter the getProperty() method returns the architecture of the current operating system.
os.name − If you pass this value as parameter the getProperty() method returns the name of the current operating system.
os.version − If you pass this value as parameter the getProperty() method returns the version of the current operating system.
To get the name of the current operating system invoke the getProperty() method by passing the value "os.name" to it as shown in the following sample code.
Example
public class Sample { public static void main(String args[]) { String os = System.getProperty("os.name"); System.out.println("Current Os is: "+os); } }
Output
Current Os is: Windows 10