Menu Close

scala interview questions

What is Scala?

  • Scala stands for SCAlable LAnguage.
  • Scala is a Multi-Paradigm Programming Language, which supports both Object-Oriented and Functional Programming concepts.
  • Scala is a Type-Safe Object-Functional Programming JVM Language. Scala runs on JVM.
  • Scala is a Hybrid Functional Programming JVM Language.
  • Scala has a Strong and Statically Type System.
  • In Scala, all types are checked at compile-time.

Is Scala Statically-Typed Language?

  • Yes, Scala is a Statically-Typed Language.

What is Statically-Typed Language?

  • Statically-Typed Language means that Type checking is done at compile-time by compiler.
  • As a Developer, we should care about writing right code to avoid all compile-time errors.
  • Examples: Java, Scala, C, C++, Haskell etc.

What is dynamically typed language?

  • Dynamically-Typed Language means that Type checking is done at run-time, not at compile-time by compiler.
  • It is also called interpreted language.
  • As a compiler won’t check any type checking at compile-time, We can expect more run-time issues or bugs.
  • Example : Groovy, JavaScript, Ruby, Python, Smalltalk etc.

Is Java a Pure OOP Language?

  • Pure Object-Oriented Programming Language means that everything should be an Object.
  • Java is not a Pure Object-Oriented Programming (OOP) Language because it supports the following two Non-OOP concepts:
  • Java supports primitive data types. They are not objects.
  • Java supports Static members. They are not related to objects.

Is Scala a Pure OOP Language?

  • Yes, Scala is a Pure Object-Oriented Programming Language because in Scala, everything is an Object and everything is a value.
  • Functions are values and values are Objects.
  • Scala does not have primitive data types and also does not have static members.

What are the popular JVM Languages available now?

  • Java, Scala, Groovy and Closure are most popular JVM (Java Virtual Machine) languages.
  • Scala, Groovy and Closure JVM languages supports both Object-Oriented Programming Features and Functional Programming Features.

What is default access modifier in Scala?

  • In Scala, if we don’t mention any access modifier to a method, function, trait, object or class, the default access modifier is “public”.
  • Even for Fields also, “public” is the default access modifier.

What is ofDim in Scala?

  • ofDim() is a method in Scala that lets us create multidimensional arrays.
  • Since these let us store data in more than one dimension, we can store data like in a matrix.

What is a vector in Scala?

  • 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.

What is a monad in Scala?

  • A monad is something to which we can pass functions and manipulate the underlying object’s data.
  • We don’t need to manipulate the object directly. Hence, a monad is an object that wraps another.

What is function currying in Scala?

  • With Scala currying, we can take a function that takes multiple arguments and turn it into a series of functions that take single arguments each.
  • These come in handy working with higher-order functions.

What Is Recursion Tail In Scala?

  • ‘Recursion’ is a function that calls itself. A function that calls itself, for example, a function ‘A’ calls function ‘B’, which calls the function ‘C’. 
  • It is a technique used frequently in functional programming. 
  • In order for a tail recursive, the call back to the function must be the last function to be performed.

What Is Case Classes?

  • 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 values.

Differentiate Nil, Null, None, and Nothing in scala.

  • The difference between these four attributes in scala is given below:
  • Nil- it is used to initialize an empty list since it is an object which extends list.
  • Null- null in scala is used to provide compatibility with the java null keyword or to provide a type for the null keyword. It also represents the absence of type information for complex types.
  • None- the “none” pattern in scala is used to remove null values from the scala code.
  • Nothing- it is used for providing the return type for the operations that can affect the normal flow of program.

What is PreDef in Scala?

  • Predef in Scala is used for providing type aliases for the commonly know scala types such as collection types Map, Set, and the List constructors.

Explain what is Unit in Scala?

  • Unit is a type in Scala that is used as a return statement for a function when no value is to be returned. It is a subtype of scala.AnyVal.