system

How to get Java/Scala system environment variables and properties

Want to get the system environment variables and/or properties from your Scala or Java application? This quick post shows what environment variables and properties are available.

Here’s a little Scala application that prints all the environment variables and properties. You’ll see that you can convert it to Java very easily:

Akka/Scala: How to monitor the death of an Actor with “watch”

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.8, “Monitoring the death of an Akka Actor with ‘watch’”.

Back to top

Problem

You want an actor to be notified when another actor dies.

Back to top

Solution

Use the watch method of an actor’s context object to declare that the actor should be notified when an actor it’s monitoring is stopped.

Table of Contents

  1. Problem
  2. Solution
Back to top

How to shut down the Akka Actor system

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a very short recipe, Recipe 13.7, “How to shut down the Akka Actor system.”

Problem

You want to shut down the Akka actor system, typically because your application is finished, and you want to shut it down gracefully.

Solution

Call the shutdown method on your ActorSystem instance:

How to build a pipeline of external commands in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.14, “How to build a pipeline of external commands in Scala.”

Problem

You want to execute a series of external commands, redirecting the output from one command to the input of another command, i.e., you want to pipe the commands together.

How to execute external commands and use their STDOUT in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.12, “How to execute external commands and use their STDOUT in Scala.”

Back to top

Problem

You want to run an external command and then use the standard output (STDOUT) from that process in your Scala program.

Back to top

Solution

Use the !! method to execute the command and get the standard output from the resulting process as a String.

Table of Contents

  1. Problem
  2. Solution
Back to top

How to execute external system commands in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 12.11, “How to execute external system commands in Scala.”

Back to top

Problem

You want to execute an external (system) command from within a Scala application. You’re not concerned about the output from the command, but you are interested in its exit code.

Back to top

Solution

To execute external commands, use the methods of the scala.sys.process package. There are three primary ways to execute external commands:

Table of Contents

  1. Problem
  2. Solution
Back to top

What is the difference between Nil and List() in Scala?

Scala FAQ: What is the difference between Nil and List() in Scala?

Short answer: There isn’t any difference, as shown in the Scala REPL:

scala> Nil == List()
res0: Boolean = true

It’s more “idiomatic Scala” Scala to use Nil rather than List(). For instance, I wrote code like this last night using Nil in a Scala match/case expression:

What the Bleep is my Mac doing?

In my new office setup my network router is now within eyesight of my desk, and even when I just have my iMac running, I can see the lights on the router constantly flickering, including the incoming and outgoing traffic lights. When I see this, I wonder, "What the Bleep is my Mac doing?" What is it downloading, or uploading?

A Java “ping” program/class

Java ping FAQ: How do I ping a computer from a Java program (or Java class, or Java method)?

I've been working on a new Java networking application, and as part of network debugging, I wanted to be able to ping a server from my Java program. I thought writing a "Java ping" class/program would be straightforward, but in short, it wasn't, so I wrote a little helper class to let me call the system ping command, and use the output from it.