What is the super class of all classes in Scala?. In the same wayin Scala, the super class of all classes or traits is “Any” class.Any class is defined in scala package like “scala.Any”.
Trang 1GUIDE TOINTERVIEWS FORSCALA FOR BIG DATA
ZEP ANALYTICS
Trang 2We've curated this series of interview which guides toaccelerate your learning and your mastery of datascience skills and tools
From job-specific technical questions to trickybehavioral inquires and unexpected brainteasers andguesstimates, we will prepare you for any job
candidacy in the fields of data science, dataanalytics, or BI analytics and Big Data
These guides are the result of our data analyticsexpertise, direct experience interviewing at
companies, and countless conversations with jobcandidates Its goal is to teach by example - not onlyby giving you a list of interview questions and theiranswers, but also by sharing the techniques andthought processes behind each question and theexpected answer
Become a global tech talent and unleash your next,best self with all the knowledge and tools to succeedin a data analytics interview with this series of guides
Introduction
Trang 3Data Science interview questions cover a widescope of multidisciplinary topics That meansyou can never be quite sure what challengesthe interviewer(s) might send your way That being said, being familiar with the type ofquestions you can encounter is an importantaspect of your preparation process
Below you’ll find examples of real-life questionsand answers Reviewing those should help youassess the areas you’re confident in and whereyou should invest additional efforts to improve.
ExploreZEP ANALYTICSGUIDE TO
INTERVIEWS FOR DATASCIENCE
Become a Tech Blogger
at Zep!!Why don't you start your journey as ablogger and enjoy unlimited free perksand cash prizes every month.
Trang 41 What is Scala?
Scala is a general-purpose programming languageproviding support for both functional and Object-Orientedprogramming
2 What is tail-recursion in Scala?
There are several situations where programmers have towrite functions that are recursive in nature The mainproblem with recursive functions is that, it may eat up all theallocated stack space To overcome this situation, Scalacompiler provides a mechanism “tail recursion” to optimizethese recursive functions so that it does not create newstack space, instead uses the current function stack space.To qualify for this, annotation “@annotation.tailrec” has to beused before defining the function and recursive call has tobe the last statement, then only the function will compileotherwise, it will give an error
3 What are ‘traits’ in Scala?
‘Traits’ are used to define object types specified by thesignature of the supported methods Scala allows to bepartially implemented but traits may not have constructorparameters A trait consists of method and field definition,by mixing them into classes it can be reused
Trang 54 Who is the father of Scala programming language?
Martin Oderskey, a German computer scientist, is the fatherof Scala programming language
5 What are case classes in Scala?
Case classes are standard classes declared with a specialmodifier case Case classes export their constructor
parameters and provide a recursive decompositionmechanism throughpattern matching The constructorparameters of case classes are treated as public valuesand can be accessed directly For a case class, companionobjects and its associated method also
get generated automatically All the methods in the class, aswell, methods in the companion objects are generated
based on the parameter list The only advantage of Caseclass is that it automatically generates the methods fromthe parameter list
6 What is the super class of all classes in Scala?
In Java, the super class of all classes (Java API Classes orUser Defined Classes) is java.lang.Object In the same wayin Scala, the super class of all classes or traits is “Any” class.Any class is defined in scala package like “scala.Any”
zepanalytics.com
Trang 67 What is a ‘Scala Set’? What are methods through whichoperation sets are expressed?
Scala set is a collection of pairwise elements of the sametype Scala set does not contain any duplicate elements.There are two kinds of sets, mutable and immutable
8 What is a Scala Map??
Scala Map is a collection of key value pairs wherein thevalue in a map can be retrieved using the key Values in aScala Map are not unique, but the keys are unique Scalasupports two kinds of maps- mutable and immutable Bydefault, Scala supports immutable map and to make use ofthe mutable map, programmersmust import
thescala.collection.mutable.Mapclass explicitly Whenprogrammers want to use mutable and immutable maptogether in the same program then the mutable map canbe accessed as mutable.map and the immutable map canjust be accessed with the name of
Trang 710 What is the use of tuples in Scala?
Scala tuples combine a fixed number of itemstogether so that they can be passed around aswhole A tuple is immutable and can hold objectswith different types, unlike an array or list
11 What do you understand by a closure in Scala?
A closure is also known as an anonymous functionwhose return value depends upon the value of thevariables declared outside the function
12 What do you understand by Implicit Parameter?
Wherever, we require that function could be invokedwithout passing all the parameters, we use implicitparameter We provide the default values for all theparameters or parameters which we want to beused as implicit When the function is invokedwithout passing the implicit parameters, local valueof that parameter is used We need to use implicitkeyword to make a value, function parameter orvariable as implicit
13.What is the companion object in Scala?
A companion object is an object with the samename as a class or trait and is defined in the samesource file as the associated file or trait A
companion object differs from other objects as ithas access rights to the class/trait that otherobjects do not In particular it can access methodsand fields that are private in the class/trait
zepanalytics.com
Trang 814 What are the advantages of Scala Language?
Advantages of Scala - Simple and Concise Code
Language: Very Expressive Code- More Readable Code- 100% Type-Safe Language- Immutability and No Side-Effects- More Reusable Code
- More Modularity- Do More with Less Code- Supports all OOP Features- Supports all FP Features Highly Functional.- Less Error Prone Code
- Better Parallel and Concurrency Programming- Highly Scalable and Maintainable code
- Highly Productivity- Distributed Applications- Full Java Interoperability- Powerful Scala DSLs available
15 What are the major drawbacks of Scala Language?
Drawbacks of Scala - Less Readable Code
Language: Bit tough to Understand the Code for beginners- Complex Syntax to learn
- Less Backward Compatibility
16 What is Akka, Play, and Sleek in Scala?
Akka is a concurrency framework in Scala which usesActor based model for building highly concurrent,distributed, and resilient message-driven applications on
Trang 9the JVM It uses high-level abstractions like Actor,Future, and Stream to simplify coding for concurrentapplications It also provides load balancing,
routing, partitioning, and adaptive clustermanagement If you are interested in learning Akka,
17 What is ‘Unit’ and ‘()’ in Scala?
The 'Unit' is a type like void in Java You can say it isa Scala equivalent of the void in Java, while stillproviding the language with an abstraction over the Java platform The empty tuple '()' is a termrepresenting a Unit value in Scala
18 What is the difference between a normal classand a case class in Scala?
Following are some key differences between a caseclass and a normal class
in Scala:- case class allows pattern matching on it.- you can create instances of case class withoutusing the new keyword
- equals(), hashcode() and toString() method areautomatically generated for case classes in Scala- Scalaautomatically generate accessormethods forallconstructor argument
19 What are High Order Functions in Scala?
High orderfunctions are functionsthat can receiveorreturn other functions Common examples in Scalaare the filter, map, and flatMap functions, whichreceive other functions as arguments
zepanalytics.com
Trang 1020 Which Scala library is used for functionalprogramming?
Scalaz library has purely functional data structuresthat complement the standard Scala library It haspre-defined set of foundational type classes likeMonad, Functor, etc
21 What is the best scala style checker toolavailable for play and scala based applications?
Scalastyle is best Scala style checker tool availablefor Play and Scala based applications Scalastyleobserves the Scala source code and indicatespotential problems with it It has three separateplug-ins to supports the following build tools:SBT
Maven Gradle
22 What is the difference between concurrency andparallelism?
When several computations execute sequentiallyduring overlapping time periods itis referred toasconcurrency whereaswhen processes are executedsimultaneously it is known as parallelism Parallelcollection, Futures and Async library are examplesof achieving parallelism in Scala
Trang 1123 What is the difference between a Java methodand a Scala function?
Scala function can be treated as a value It can beassigned to a val or var, or even returned fromanother function, which is not possible in Java.Though Java 8 brings lambda expression which alsomakes function as a first-class object, which meansyou can pass a function to a method just like youpass an object as an argument See here to learnmore about the difference between Scala and Java
24 What is the difference between Function andMethod in Scala?
Scala supports both functions and methods We usesame syntax to define functions and methods, thereis no syntax difference
However, they have one minor difference:We can define a method in a Scala class or trait.Method is associated with an object (An instance ofa Class) We can call a method by using an
instance of a Class We cannot use a Scala Methoddirectly without using object
Function is not associated with a class or trait It isdefined in a Scala Package We can access
functions without using objects, like Java’s StaticMethods
25 What is Extractor in Scala?
In Scala, Extractor is used to decompose ordisassemble an object into its parameters (or
Trang 1226 Is Scala a Pure OOP Language?
Yes, Scala is a Pure Object-Oriented ProgrammingLanguage because in Scala, everything is an Object, andeverything is a value Functions are values and values areObjects
Scala does not have primitive data types and does nothave static members
27 Is Java a pure OOP Language?
Java is not a Pure Object-Oriented Programming (OOP)Language because it supports the following two Non-OOPconcepts: Java supports primitive data types They arenot objects.Java supports Static members They are notrelated to objects
28 Does Scala support Operator Overloading?
Scala supports Operator Overloading.Scala has given this flexibility to Developer to decide which methods/functions name should use When wecall 4 + 5 that means ‘+’ is not an operator, it is a methodavailable in Int class (or it’s implicit type) Internally, thiscall is converted into “4.+(5)“
29 Does Java support Operator Overloading?
Java does not support Operator Overloading
30 What is an Expression?
Expression is a value that means it will evaluate to aValue As an Expression returns a value, we can assign itto a variable
Example:- Scala’s If condition, Java’s Ternary operator
Trang 1331 What are the default imports in Scala Language?
We know, java.lang is the default package importedinto all Java Programs by JVM automatically Wedon’t need to import this package explicitly
In the same way, the following are the defaultimports available in all Scala Programs:
java.lang package Scala package scala.PreDef
32.What is a Statement? Difference betweenExpression and Statement?
Statement defines one or more actions oroperations That means Statement
performs actions As it does not return a value, wecannot assign it to a
Variable Example:- Java’s If condition
33 How to compile and run a Scala program?
You can use Scala compiler scalac to compile Scalaprogram (like javac) and scala command to runthem (like scala)
34 How to tell Scala to look into a class file forsome Java class?
We can use -classpath argument to include a JARin Scala's classpath, as shown below
$ scala -classpath jarAlternatively, you can also use CLASSPATHenvironment variable
zepanalytics.com
Trang 1435.What is the difference between Java’s “If Else”and Scala’s “If Else”?
Java’s “If Else”:In Java, “If Else” is a statement, not an expression Itdoes not return a value and cannot assign it to avariable
int year;if( count == 0) year = 2018; else
Example:-year = 2017;Scala’s “If Else”:In Scala, “If Else” is an expression It evaluates avalue i.e returns a value We can assign it to avariable
val year = if( count == 0) 2018 else 2017NOTE:-Scala’s “If Else” works like Java’s TernaryOperator We can use Scala’s “If Else” like Java’s“If Else” statement as shown below:
val year = 0if( count == 0) year = 2018 else
Trang 1537 What exactly is wrong with a recursive functionthat is not tail-recursive?
You run the risk of running out of stack space andthus throwing an exception
38 What is the difference between var and value?
In scala, you can define a variable using either a,val or var keywords The difference between val andvar is, var is much like java declaration, but valislittle different We cannot change the reference topoint to another reference, once the variable isdeclared using val The variable defined using varkeywords are mutable and can be changed anynumber of times
39 What is scala anonymous function?
In a source code, anonymous functions are called‘function literals’ and at run time, function literalsare instantiated into objects called function values.Scala provides a relatively easy syntax for defininganonymous functions
40 What is function currying in scala?
Currying is the technique of transforming a functionthat takes multiple arguments into a function thattakes a single argument Many of the same
techniques as language like Haskell and LISP aresupported by Scala Function currying is one of theleast used and misunderstood one
zepanalytics.com
Trang 1641 What do you understand by “Unit” and “()” inScala?
Unit is a subtype of scala.anyval and is nothing butScala equivalent of Java void that provides theScala with an abstraction of the java platform.Empty tuple i.e () in Scala is a term that representsunit value
42 What’s the difference ‘Nil’, ‘Null’, ‘None’ and’Nothing’ in Scala?
Null - It’s a sub-type of AnyRef type in Scala Typeshierarchy As Scala runs on JVM, it uses NULL toprovide the compatibility with Java null keyword, orin Scala terms, to provide type for null keyword, Nulltype exists It represents the absence of type
information for complex types that are inheritedfrom AnyRef
Nothing - It’s a sub-type of all the types exists inScala Types hierarchy It helps in providing thereturn type for the operations that can affect anormal program’s flow It can only be used as atype, as instantiation of nothing cannot be done Itincorporates all types under AnyRef and AnyVal.Nothing is usually used as a return type for methodsthat have abnormal termination and result in anexception
Trang 17Nil - It’s a handy way of initializing an empty listsince, Nil, is an object, which extends List [Nothing].None - In programming, there are many
circumstances, where we unexpectedly received nullfor the methods we call In java these are handledusing try/catch or left unattended causing errors inthe program Scala provides a very graceful way ofhandling those situations In cases, where you don’tknow, if you would be able to return a value as expected, we can use Option [T] It is an abstractclass, with just two sub-classes, Some [T] and none.With this, we can tell users that, the method mightreturn a T of type Some [T] or it might return none
43 What is Lazy Evaluation?
Lazy Evaluation means evaluating program at time on-demand that means when clients accessthe program then only its evaluated
run-The difference between “val” and “lazy val” is that“val” is used to define variables which are evaluatedeagerly and “lazy val” is also used to define
variables but they are evaluated lazily
44 What is call-by-name?
Call-by-name means evaluates method/functionparameters only when we need them, or we accessthem If we don’t use them, then it does not evaluatethem
zepanalytics.com
Trang 1845 Does Scala and Java support call-by-name?
Scala supports both value and name function parameters However, Java supportsonly call-by-value, but not call-by-name
call-by-46 What is the difference between call-by-valueand call-by-name function parameters?
Difference between value and name:
call-by-The major difference between these two aredescribed below:
In Call-by-name, the function parameters areevaluated only whenever they are needed but notwhen the function is called
In Call-by-value, thefunction parametersareevaluated when the function is called In Call-by-value, the parameters are evaluated beforeexecuting function and they are evaluated onlyonce irrespective of how many times we used themin that function
In Call-by-name, the parameters are evaluatedwhenever we access them, and they are evaluatedeach time we use them in that function
47 What is an anonymous function in Scala?
Anonymous Function is also a Function, but it doesnot have any function name It is also known as aFunction Literal
Trang 1948 What do you understand by apply and unapplymethods in Scala?
Apply and unapply methods in Scala are used formapping and unmapping data between form andmodel data
Apply method - Used to assemble an object fromits components For example, if we want to createan Employee object then use the two componentsfirstName and lastName and compose the
Employee object using the apply method.Unapply method - Used to decompose an objectfrom its components It follows the reverse processof apply method So, if you have an employee
object, it can be decomposedinto two firstName and lastName
components-49 What is the difference between unapply andapply, when would you use them?
Unapply is a method that needs to be implementedby an object in order for it to be an extractor
Extractors are used in pattern matching to accessan object constructor parameter It’s the opposite ofa constructor.The applymethod is aspecial methodthatallows you towrite someObject(params)
instead of someObject.apply(params) This usageiscommon in case classes, which contain a
companion object with the apply method thatallows the nice syntax to instantiate a new objectwithout the new keyword
zepanalytics.com