Blog Archives
1 2

01: Coding “Java way in Scala” Vs “Scala way in Scala”

Example #1: Read from a list & write to a list

Java Way in Scala



02: Coding Scala Way – Recursion & Iterator in FP

This extends Coding Scala Way – Part 1 Can you write the following code written in Java the Scala way? Java coding question on recursion and generics Q. Can you write Java code to compute a collection of numbers supplied to it? The computation could be addition, subtraction, etc. Use…



03: Coding Scala Way – Lazy Eval

Example #6: Lazy initialization & evaluation of code Scala support “views”, which are collections that can be lazily evaluated. One use for views is when you need to traverse a collection of values which are expensive to compute and you only need one value at a time.



04: Coding Scala Way – Null checks with Option-Some-None

Example #10: Null checks with “Option-Some-None”

Nulls in Scala is a code smell, and a better way to handle null values is with an “Option“, which has 2 sub classes “Some” that has a value and a “None” that does not have a value. Instead of checking for “myVal != null”, you can use “pattern matching” to deal with null values.



05: Coding Scala Way – FP concepts

Example #13: Explain the concepts

Can you explain the Scala concepts applied in the following code snippets?



06: Coding Scala Way – Reduce & Compose functions

Example #14: Reduce operations Given a list of functions as shown below, how will you go about applying all the functions in the list to each input number and sum the result of each function?



07: Coding Scala Way – Regular Expressions

Example #16: Regular Expression Regular expression (aka regex) to identify numbers in a string. Invoking “findFirstIn” and “findAll” functions of the “Regex” class. “[0-9]+”.r is a short form instead of instantiating it as new Regex(“[0-9]+”).



08: Coding Scala Way – Recursion & Higher Order Function

Example #20: nth Fibonacci number

Q1 What is wrong with the following recursive approach to compute the nth Fibonacci number?
A1 It “hangs” for the larger values of “n” like 50.



09: Coding Scala Way – Fibonacci Series

Example #22: Fibonacci series in Scala This extends determine the nth fibonacci number using Scala. In this let’s print the Fibonacci series of length n.



10: Coding Scala Way – groupBy, mapValues & identity

Java developers need to learn Coding Scala Way. Scala way of coding is quite different & you need to unlearn Java way of coding

Question: Given a list of numbers, how will you group the numbers by how many times they occur? for example output for “List(3, 3, 4, 5, 5, 5)” is List((3,2), (4,1), (5,3)).

Pre Java 8 way – imperative style



11: Coding Scala Way – Actors with Akka – part 1

We already saw in Java: Producer and Consumer Java Multi-threading code. This extends the tutorial “Simple Akka tutorial in Scala step by step” for setting up the environment with right plugins and libraries with Eclipse & Maven.

The Akka Actors sending & receiving messages

Akka Actors conceptually each have their own light-weight thread. Actors are represented to the outside using ActorRefs, which are objects that can be passed around freely and without restriction. The “!” method is in the “akka.actor.ActorRef” trait.



12: Coding Scala Way – Actors with Akka “Ask Pattern” – Part 2

Actors with Akka “Ask Pattern” is for getting a reply or a response to a message that was sent by a sender. Use ? or ask method. We saw earlier how to send or tell a message to an actor. The Akka Actor Asking for a reply or response The…



13: Coding Scala Way – 2 Actors with Akka – part 3

This extends Actors with Akka – part 1. This “Akka with actors” shows how messages passed among actors in the system. This is known as the reactor pattern based on the event-driven architecture. Orderplacement.scala with Actors



14: Coding Scala Way – Scala concurrency with Future

Scala concurrency with Future explains step by step blocking vs unblocking calls and how implicit and apply concepts work under the covers. Scala extends the Java programming language and runtime in many ways, including concurrency where Scala version of Future<T> is more flexible than the Java version as you can create futures directly from blocks of code, and you can attach callbacks to futures for handling completions.

Scala Future – blocking call

Scala’s Future[T], resides in the “scala.concurrent” package, and it is container type, representing a computation that is supposed to eventually result in a value of type T. The …



15: Coding Scala Way – Scala concurrency & closure vs function definition

This post not only covers “onSuccess” method on a “Future”, but also clarifies the difference between executing a closure and a function definition. Is anything wrong with the following Scala concurrency code?



16: Coding Scala Way – Scala concurrency styles

This extends Scala concurrency & closure vs function definition. This post looks at Scala concurrency styles – blocking & non-blocking. onComplete – non-blocking



17: Coding Scala Way – What is wrong with this code?

Q. What is wrong with the below code? How will you fix it?



3 Reasons Why I started Learning Scala

Why learn Scala? and where to use Scala? are very popular questions in forums like LinkedIn, Quora, Stack Overflow, etc. Here is my take on learning Scala with 3 reasons.

#1. I am already proficient in Java

Learning new programming languages (e.g. Scala) and paradigms (e.g. functional programming) will teach you different ways to approach problem solving. Seasoned developers are opinionated, and know the language features they love, and miss. One of the good open-ended job interview questions to ask is — What features do you love in Java? What frustrates you? What features do you like to be added …



FAQs Data: 01: Getting started with Spark Scala on IntelliJ IDEA

Even though you can download required libraries via Maven pom.xml, in this tutorial will directly download so that you understand the key steps. Intellij IDEA is the most popular IDE for Spark development on Scala. Here are the 12 easy steps that will get you started with your Spark with Scala on IntelliJ IDEA IDE.

Step 1: Download Java 8 & set up the JAVA_HOME Environment variable.

Step 2: Install the latest IntelliJ IDEA IDE.

Step 3: Inside IntelliJ IDEA set up Scala Plugin & download Scala SDK.

IntelliJ IDEAPreferencesPlugins

Step 4: Create a new …



FAQs Data: 02: Getting started with Spark Scala on IntelliJ IDEA with Maven

This extends FAQs Data: 01: Getting started with Spark Scala on IntelliJ IDEA to package the Spark & run it via command-line. The dependent libraries configured via Maven pom.xml. Make sure Maven is installed on your machine & set in the path.

Step 1: Extend the previous pom.xml file from



1 2

300+ Java & Big Data FAQs - Quick Prep

Java & Big Data Tutorials

Top