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 ?
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.
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.
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.
You can use System.getProperty()
to get the following properties:
os.name
: Operating system nameos.arch
: Operating system architectureos.version
: Operating system versionIn 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With