Q.1 What is a vector in Scala?Ans: A vector is a general-purpose data structure that is immutable. We can use it when we want to hold a huge number of elements and want random access to them. This data structure extends the trait IndexedSeq and the abstract class AbstractSeq. |
Q.2 Write a few Frameworks of Scala?Ans: Some of the Frameworks supported by Scala are as follows:Akka FrameworkSpark FrameworkPlay FrameworkScalding FrameworkNeo4j FrameworkLift FrameworkBowler Framework |
Q.3 What is Case Classes?Ans: Case classes provides a recursive decomposition mechanism via pattern matching, it is a regular classes which export their constructor parameter. The constructor parameters of case classes can be accessed directly and are treated as public value |
Q.4 What is a closure in Scala?Ans: A closure is a function whose return value depends on the value of the variables declared outside the function. |
Q.5 What is Monad in Scala?Ans: Monads is a structure that represents sequential computations, Monad is not a class or a trait; monad is a concept.A monad is an object that wraps another object in Scala, In Monad the output of a calculation at any step is the input to the other calculation which runs as a parent to the current step. |
Q.6 What is Null in Scala? What is null in Scala? What is difference between Null and null in Scala?Ans: Null is a Type (final class) in Scala. Null type is available in “scala” package as “scala.Null”. It has one and only one instance that is null. |
Q.7 What is ofDim() ?Ans: In Scala, ofDim() is a function that allows you to create multidimensional arrays. You can store the data in multiple dimensions – it becomes like a matrix of sorts. |
Q.8 What is the difference between val and var in Scala?Ans: In Scala, both val and var are used to define variables. However, they have some significant differences.var stands for variable.val stands for value.As we know, variable means changeable and value means constant.var is used to define Mutable variables that means we can reassign values once its created.val is used to define Immutable variables that means we cannot reassign values once its created.In simple Java terminology, var means ‘variable’ and val means ‘final variable’ |
Q.9 How can we append to the listAns: In Scala, we can ':+' single value. Check out the below given example to understand better.var myList = List.empty[String] |
Q.10 What is an Object in Scala?Ans: An object in Scala is one particular instance in a class. |
Q.11 What is Recursion in Scala?Ans: Recursion is referred to as the function in Scala that calls itself. |
Q.12 What are the different scopes for variables in ScalaAns: There are three different scopes for variables in Scala, which include Fields, Method Parameters, and Local Variables. |
|
Q.14 Define Map in Scala?Ans: A Map in Scala is the collection of key or value pairs that helps in retrieving a Value-Based on its key. |
Q.15 Which all languages Apache Spark supports?Ans: Apache Spark is written in Scala. Many people use Scala for the purpose of development. But it also has API in Java, Python, and R. |
Q.16 Why do we need App in Scala?Ans: App is a helper class that holds the main method and its Members together. The App trait can be used to quickly turn Objects into Executable programs. We can have our classes extend App to render the executable code.object Edureka extends App{println('Hello World')} |
Q.17Explain the Scala Anonymous Function?Ans: In the Source code, Anonymous functions are called ‘Function literals’ and at run time, function literals are instantiated into objects called Function values. Scala provides a relatively easy Syntax for defining Anonymous functions.(z:Int, y:Int)=> z*yOr(_:Int)*(_Int) |
Q.18 Explain the Syntax for function declaration in Scala?Ans: The syntax is:def functionName(parameters : typeofparameters) : returntypeoffunction = {// function statements}A function is created using the ‘def’ keyword.All the parameters and their return types are mentioned clearly.The equal operator, when added, returns the value, else if no equaloperator is used, the function will not return any value. |
Q.19 How to create Arrays in Scala?Ans: Array we can declare a variable that reference the array .we need to describe data type of array .An array created as :var z:Array[String] = new Array[String](10)orvar z = new Array[Int](5) |
Q.20 Explain set collection in scala.Ans: A Set is a collection that contains no duplicate elements. There are two kinds of Sets,the immutable and the mutable.By default, Scala uses the immutable Set.for details https://docs.scala-lang.org/overviews/collections/sets.htmlBelow is method is use by sethead: returns the head (first element) of the settail: returns entire set except the head elementisEmpty: checks if the set is empty, returns BooleanExample :scala> val fruit = Set('apple', 'orange', 'peach', 'banana')fruit: scala.collection.immutable.Set[java.lang.String] = Set(apple, orange, peach, banana)scala> fruit('peach')res0: Boolean = truescala> fruit('potato')res1: Boolean = false |
Q21. Explain implicit classes with syntax. Ans: Implicit classes allow Implicit conversations with the class’s Primary constructor when the class is in scope. Implicit class is a class marked with the “implicit” keyword. This feature was introduced in with Scala 2.10 version.//Syntax:object {implicit class Data type) {def Unit = xyz}} |