properties

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:

Scala: Reassignable variables and properties (def fields)

Sadly, I had to get away from Scala for a while, but now I can get back to it again. Just as I started getting back into it I happened upon the following code, and thought, “Well, surely title in this anonymous class is a var field. How strange that the Programming in Scala guys would use a var like this.”:

Scala: How to define properties in an abstract base class or trait

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 4.13, “How to define properties in an abstract base class or trait.”

Problem

You want to define abstract or concrete properties in an abstract base class (or trait) that can be referenced in all child classes.

Setting a Scala application's command line parameters in Eclipse

I’ve been developing a new Scala application named Cato that requires some command-line parameters, and I just had to figure out how to configure Eclipse so my application would get those parameters. Doing this with Scala in Eclipse is different than configuring Java command line parameters in Eclipse, so I thought I’d share the recipe.

Fortunately it’s just a two-step process. First, click the drop-down icon next to the “Run” button and choose “Run Configurations”, as shown here:

How to read/access Play Framework application.conf properties

Here’s a quick look at how to read Play Framework application.conf configuration properties.

First, given a Play application.conf file with these properties:

foo=42

bar.baz=10

stations = [ 99.5, 102.3, 104.3, 105.9 ]

streams = [
    { "name": "104.3", "file": "104_3.pls" },
    { "name": "WGN",   "file": "wgn.pls" }
]

You can read the foo property (as a String) from your Play code like this:

The Chrome JavaScript debug console and [Object object]

As I’ve gotten back into client-side web development -- specifically using Sencha Touch 2, a JavaScript framework -- I’ve quickly run into a problem in the Chrome JavaScript debug console. When I try to use console.debug() to debug an object, I get this non-useful output about the JavaScript object I’m printing:

[Object object]

There may be better ways to print the desired object, but I quickly discovered this trick to printing all of the properties of a JavaScript object:

Java file open, read, and write utilities

Java file utilities FAQ: Do you have any Java file utilities you can share?

As I was working on another Java/Swing application this weekend, I ran across my "Java file utilities" class, and I thought I'd share that class here today. It's nothing too major, but it does include Java methods that let you open, read, write, and copy files using Java.

Converting a Java properties file to a Map (example)

At the moment I can't remember why I wrote this method to read a Java properties file and return it as a Map of key/value pairs ... but if for some reason you happen to need a Java method that reads a properties file and returns the contents as a Map, here's some free source code for you:

A Java Properties file method

In an earlier Java Properties file example I showed how to load a Java Properties file and then access the elements in the Properties object, but for today, if you just need a method to read a Java Properties file, I hope the following source code will be helpful to you: