Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to find os name using java?

Tags:

java

Is there any way to find os name using java ?

I have tried below code, but it will returns looks like (Linux , windows..)

System.getProperty("os.name")

I need to detecting below format

Linux - "ubuntu, mandriva .. " , windows - "xp,vista ..."

sorry for my English :-( !!!

Any idea ?

like image 736
sprabhakaran Avatar asked Apr 30 '12 12:04

sprabhakaran


People also ask

How do I find my operating system in Java programmatically?

One way is to make use of the System. getProperty(os.name) to obtain the name of the operating system. The second way is to make use of SystemUtils from the Apache Commons Lang API.

Is there any OS written in Java?

Originally Answered: Can I write an operating system in Java? You mean like Android, the phone OS written in Java? Originally Answered: Is Java (programming language) capable of developing an operating system? No, it can't directly access hardware memory addresses.

Which OS is based on Java?

JavaOS is an operating system based on a Java virtual machine and predominantly used on SIM cards to run applications on behalf of operators and security services. It was originally developed by Sun Microsystems.


1 Answers

You can use System.getProperty() to get the following properties:

  • os.name: Operating system name
  • os.arch: Operating system architecture
  • os.version: Operating system version

In your case, I believe you're looking for the os.version property. The javadocs for System.getProperties() contain a full list of properties that you can retrieve.

Edit

I just tested this in Linux Mint and it appears that the getting the os.version property actually returns the kernel version, and not the distro version:

Linux
amd64
2.6.38-8-generic

After finding this post, it seems as though there's no reliable way to find which Linux distribution you're running through the Java API.

If you know you're running in Linux, you can instead run one of the following system commands from Java, but you'll have to grep/parse out the distribution:

  • cat /etc/*-release
like image 76
Mansoor Siddiqui Avatar answered Oct 10 '22 09:10

Mansoor Siddiqui