Here is a handy Java class that use System.getProperty("") to detect which type of operating system (OS) you are using now.

This code can detect “Windows”, “Mac”, “Unix” and “Solaris”.

package com.mkyong.core;
public class OSValidator {
	private static String OS = System.getProperty("").toLowerCase();
	public static void main(String[] args) {
		if (isWindows()) {
			System.out.println("This is Windows");
		} else if (isMac()) {
			System.out.println("This is Mac");
		} else if (isUnix()) {
			System.out.println("This is Unix or Linux");
		} else if (isSolaris()) {
			System.out.println("This is Solaris");
		} else {
			System.out.println("Your OS is not support!!");
	public static boolean isWindows() {
		return (OS.indexOf("win") >= 0);
	public static boolean isMac() {
		return (OS.indexOf("mac") >= 0);
	public static boolean isUnix() {
		return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0 );
	public static boolean isSolaris() {
		return (OS.indexOf("sunos") >= 0);


  1. value –
  2. System.getProperty() –
Tags :
Founder of, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.
My website is hosted by Liquid Web, I really like their fast and helpful support, it saved me a lot of time. Furthermore, their servers are extremely reliable, fast and stable, I don't remember when was the last time my server is down. Btw, they're offering $100 Coupon now, if you are sourcing for great hosting provider, go grab it.

Related Posts

Popular Posts