Chapter 4. Where Am I? Execution Context

Java claims—and rightly so—to be a “compile once, run anywhere” language. But when a program starts, that “anywhere” is now a specific somewhere. When running a Java application on Linux, or any environment for that matter, the question arises, “Where am I?” (context, environment, familiar landmarks). What can a Java program find out about its environment? In particular, on the Linux platform, (how) can we get at:

  • Command-line parameters?

  • The current shell’s environment variables?

  • The current working directory?

  • The location of data files?

The answers to these questions will depend on what kind of Java application you are creating, and just how portable you want your application to be.

What You Will Learn

We’ll ...

Get Java™ Application Development on Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.