Skip to content
Ameen Abozaid
In reviewJNR-007-L03

Environment variables and system properties

  • Lesson 3 of 6
  • 11 min read
  • Junior
On This Lesson 4 topics

The content for this lesson is written and waiting for review. The outline below shows what it covers. It will be published once it is approved.

In this lesson

override settings from outside.

Planned topics

  • Environment variables are set by the operating system or container: System.getenv("SHOP_TAX_RATE").
  • System properties are set when starting Java: -Dshop.tax-rate=0.07; read with System.getProperty.
  • Names are usually UPPER_SNAKE_CASE for environment variables.
  • Common pattern: file gives defaults, environment overrides.
  • Convert types yourself and fail clearly on bad values.
Draft outline details

Demonstration

java
String rate = System.getenv().getOrDefault("SHOP_TAX_RATE", props.getProperty("shop.tax-rate"));

Check your understanding

How do you pass a system property?

Show answer

With -Dname=value on the java command.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.