All of us know that an instance of File doesn’t indicate a file in the file system, unless some one invokes a create or related methods. But its a kind of confusion- you talk about instance of File and then you also talk about file at the disk level. A new class was introduced in …
Using Apply and Unapply Methods in Scala
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
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 …
Book Review: Java Concurrency in Practice
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
Introduction to Scala Constructor 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 …
Package Objects in Scala
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 …
Fields which satisfy JavaBean specification – BeanProperties in Scala
We have seen previously about declaring fields in classes in Scala and also saw the kind of bytecode created for each of the cases. But lot of Java tools out there expect the fields in classes to follow the JavaBeans specification and in order to support that Scala provides @BeanProperty annotation. also read: Primary and …
Understanding Classes and its Fields in Scala
For those moving from Java to Scala would find it a bit different to see how the classes and their fields are treated in Scala. Most of you in the Java world always complain about the verbosity of adding fields and then to add their getters and setters. Lets look at how the Classes and …