In Java, we can use the os.name
system property to find the OS name and version. We can also use the os.version
system property to get the version.
To access the system properties, we can call System.getProperty
with the property name that we need to access.
class GetOSDetails { public static void main( String args[] ) { //Operating system name System.out.println("Your OS name -> " + System.getProperty("os.name")); //Operating system version System.out.println("Your OS version -> " + System.getProperty("os.version")); //Operating system architecture System.out.println("Your OS Architecture -> " + System.getProperty("os.arch")); } }
In the code above, we:
accessed the OS name
. We used the System.getProperty
method to pass the os.name
string as the argument.
also accessed OS version
and OS architecture
through the os.version
and os.arch
system properties respectively.
In addition, we can:
use java.version
to access Java version.
use java.home
to access Java installation.
use user.name
to access user account name.
class GetSystemProperties { public static void main( String args[] ) { //JRE version number System.out.println(System.getProperty("java.version")); //Installation directory for Java Runtime Environment (JRE) System.out.println(System.getProperty("java.home")); //User account name System.out.println(System.getProperty("user.name")); } }
RELATED TAGS
CONTRIBUTOR
View all Courses