Functions as First Class Citizens in Scala

scala-thumbnail

In Java (Java 7 and before) we can store an object reference in a variable or some primitive value in which case Classes and Primitive types are the first class citizens there, but in Scala we can assign method/function definitions to variables, we can pass around function definitions to other functions and we can even […]

Using Apply and Unapply Methods in Scala

scala-thumbnail

Before we proceed to learn about Apply and Unapply methods, its good to know what a companion object is. A companion object in Scala for some class say Fraction is defined as: One can provide apply(args) and unapply(args) methods in the companion objects which can be used implemented to some special operations in Scala. Suppose […]

Traits in Scala- Advanced concepts

scala-thumbnail

In our previous article we covered very basic concepts on traits. In this article we will expand on our initial work and explore the inherent power of traits. As we said here just like the Interfaces traits can have abstract methods. Also traits can extend other traits just like Interfaces can extend other interfaces. also […]

Traits in Scala

scala-thumbnail

Java doesn’t allow multiple inheritance for the fear of Deadly Diamond of Death. And to circumvent this Java introduced interfaces where in a class can extend only one other class, but implement multiple interfaces. These interfaces don’t contain any implementations. (This is going to change with Defender Methods in Java 8). Lot of other languages […]

Inheritance and Overriding in Scala

scala-thumbnail

Inheritance in Scala is quite similar to the way it is in Java. The overriding aspects are a bit more detailed because in Scala there are not just methods to override but also vals, vars. There are a few restrictions added in Scala like: Overriding classes must use the “override” modifier. In Java one can […]

Developing Concurrent applications using ExecutorService Framework in Java

java-thumbnail

We all have used Thread, Runnable to develop multi-threaded applications in Java. While we used Thread and Runnable we had a lot of work to do in terms of assigning the task to the Thread, starting the thread to waiting for it to complete the execution to get the result from each thread. In Java […]

Book Review: Java Concurrency in Practice

Java-Concurrency-In-Practice-book-review

Lot of us know that writing multi-threaded/concurrent applications in Java is not just about creating Thread objects and passing in Runnable implementations. Few of them mastered the art of concurrent programming and explored alternatives not only provided by Java but other languages like Scala, Groovy, Clojure. But quite a few of us have tried to […]

Primary and Auxiliary Constructors in Scala

scala-thumbnail

Constructors in Scala are a bit different than in Java. Scala has 2 types of constructors: Primary Constructor Auxiliary Constructor also read: Primary and Auxiliary Constructors in Scala Traits in Scala Java HelloWorld vs Scala HelloWorld Primary Constructor In Java we have a no-args default constructor which is provided for every class which doesn’t provide […]

Package Objects in Scala

scala-thumbnail

Package Objects in Scala was introduced as part of Scala 2.8. With this feature a package in scala can contain field declarations, methods along with the classes, objects and traits. The methods and variable declarations are put into the package object and are accessible in the package for which the package object was declared. also […]

Implementing a Producer-Consumer scenario using BlockingQueue in Java

java-thumbnail

Before we start with the actual example, lets have a look at the few concepts we should be aware of. Producer-Consumer Problem Wikipedia here says that: The consumer producer problem (also known as the bounded-buffer problem) is a classical example of a multi-process synchronization problem. The problem describes two processes, the producer and the consumer, […]