Blogs

Scala packaging and import examples

This article is a collection of Scala packaging and import examples. I created most of these examples when I was writing the Scala Cookbook. I share them here without much discussion, but for more examples and discussion, please check out the Cookbook.

Packages imported by default

By default, three packages are implicitly imported for you:

Scala object examples

This article is a collection of Scala “object” examples. I put the word object in quotes there because it has at least two meanings in Scala. In the first meaning, just like Java, an object is an instance of a class.

In its second meaning, Scala has an object keyword, and using that keyword lets you do a variety of things, including creating a main method to launch your application, to create the equivalent of Java’s static methods, and also to create something called a companion object.

Comparison of the 2015 Subaru Outback vs Forester

I recently went into a Subaru dealership to buy a 2015 Subaru Forester. I currently live in Colorado, and may move back to Alaska, so it’s important to me to have an all-wheel drive vehicle for either winter experience. Although I went into the dealership to buy a Forester, I ended up buying an Outback. As a result of that experience I thought I’d share what I learned about the two cars.

Scala method and function examples

This page contains a collection of Scala method examples. I created many of these examples while I was writing the Scala Cookbook. Unlike the Cookbook, where I explain these examples in great detail, on this page I’m just sharing many of the examples so you can use this as a method/function reference page. (The Cookbook contains more examples than this page, and explains them in detail.)

Scala trait examples

This page contains a collection of Scala trait examples. I created many of these examples when I was writing the Scala Cookbook. Unlike the Cookbook, where I explain these examples in great detail, on this page I’m just sharing many of the examples so you can use this as a trait reference page. (The Cookbook actually contains more examples than this page.)

Without any more introduction, here are the examples.

Scala control structure examples (if/then, match/case, for, while, try/catch)

This post contains a collection of Scala control structures examples. I initially created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe them much here, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).

if/then control structures:

Here are some examples of the Scala if/then control structure:

Scala number and date examples

This short blog post contains a collection of Scala number and date examples. I created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe the examples here much at all, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).

Scala numeric types

Scala has these numeric types:

Syndicate content