BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

System.getProperty() in java

Last Updated: June 1, 2024 by Chaitanya Singh | Filed Under: java

In this guide, we will discuss System.getProperty() method in Java. The getProperty() method of System class is frequently used to retrieve various system properties such as java version, os version, java home directory details etc.

Program to get system properties using System.getProperty()

Let’s write a java program to get system properties using System.getProperty() method and print them.

public class SystemPropertiesExample {
public static void main(String[] args) {
// Getting various system properties
String javaVersion = System.getProperty("java.version");
String javaVendor = System.getProperty("java.vendor");
String javaVendorURL = System.getProperty("java.vendor.url");
String javaHome = System.getProperty("java.home");
String javaClassPath = System.getProperty("java.class.path");
String osName = System.getProperty("os.name");
String osVersion = System.getProperty("os.version");
String osArch = System.getProperty("os.arch");
String userName = System.getProperty("user.name");
String userHome = System.getProperty("user.home");
String userDir = System.getProperty("user.dir");

// Printing the system properties
System.out.println("Java Version: " + javaVersion);
System.out.println("Java Vendor: " + javaVendor);
System.out.println("Java Vendor URL: " + javaVendorURL);
System.out.println("Java Home: " + javaHome);
System.out.println("Java Class Path: " + javaClassPath);
System.out.println("OS Name: " + osName);
System.out.println("OS Version: " + osVersion);
System.out.println("OS Architecture: " + osArch);
System.out.println("User Name: " + userName);
System.out.println("User Home: " + userHome);
System.out.println("User Working Directory: " + userDir);
}
}

Output:

Java Version: 1.8.0_291
Java Vendor: Oracle Corporation
Java Vendor URL: http://java.oracle.com/
Java Home: C:\Program Files\Java\jdk1.8.0_291\jre
Java Class Path: .;C:\path\to\your\classes;C:\path\to\your\libraries\lib.jar
OS Name: Windows 10
OS Version: 10.0
OS Architecture: amd64
User Name: chaitanya.singh
User Home: C:\Users\chaitanya.singh
User Working Directory: C:\Users\chaitanya.singh\workspace\MyProject

Notes

  • The output will vary depending on the operating system and java version you are running.
  • If any of the mentioned property is not available, the corresponding output line might be empty or null.

Explanation of Each Property

  • java.version: The Java version.
  • java.vendor: The vendor information from where you got the java installed.
  • java.vendor.url: The url to the vendor’s website.
  • java.home: complete path to the directory where JRE is installed.
  • java.class.path: The class path used by the system.
  • os.name: OS name.
  • os.version: The version of the running OS.
  • os.arch: The architecture of the operating system (e.g., x86, amd64).
  • user.name: The user’s account name.
  • user.home: The user’s home directory path.
  • user.dir: The user’s current working folder/directory.

Top Related Articles:

  1. How to check Java Version using Java Program
  2. Java – How null works with StringBuffer
  3. Java Virtual Machine (JVM)
  4. Constructor Overloading in Java with examples
  5. Multithreading in java with examples

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Java Tutorial

Java Introduction

  • Java Index
  • Java Introduction
  • History of Java
  • Features of Java
  • C++ vs Java
  • JDK vs JRE vs JVM
  • JVM - Java Virtual Machine
  • First Java Program
  • Variables
  • Data Types
  • Operators

Java Flow Control

  • Java If-else
  • Java Switch-Case
  • Java For loop
  • Java while loop
  • Java do-while loop
  • Continue statement
  • break statement

Java Arrays

  • Java Arrays

OOPs Concepts

  • OOPs Concepts
  • Constructor
  • Java String
  • Static keyword
  • Inheritance
  • Types of inheritance
  • Aggregation
  • Association
  • Super Keyword
  • Method overloading
  • Method overriding
  • Overloading vs Overriding
  • Polymorphism
  • Types of polymorphism
  • Static and dynamic binding
  • Abstract class and methods
  • Interface
  • Abstract class vs interface
  • Encapsulation
  • Packages
  • Access modifiers
  • Garbage Collection
  • Inner classes
  • Static import
  • Static constructor

Java Exception Handling

  • Exception handling
  • Java try-catch
  • Java throw
  • Java throws
  • Checked and Unchecked Exceptions
  • Jav try catch finally
  • Exception Examples
  • Exception Propagation

Collections Framework

  • Collections in Java
  • Java ArrayList
  • Java LinkedList
  • Java Vector
  • Java HashSet
  • Java LinkedHashSet
  • Java TreeSet
  • Java HashMap
  • Java TreeMap
  • Java LinkedHashMap
  • Java Queue
  • Java PriorityQueue
  • Java Deque
  • Comparable interface
  • Comparator interface
  • Collections Interview Questions

MORE ...

  • Java Scanner Class
  • Java 8 Features
  • Java 9 Features
  • Java Conversion
  • Java Date
  • Java Multithreading
  • Java I/O
  • Java Serialization
  • Java Regex
  • Java AWT
  • Java Swing
  • Java Enum
  • Java Annotations
  • Java main method
  • Java Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap