Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Define Closure in Scala with example?

Answer»

Define Closure in SCALA with example?
Closure is ONE of the FUNCTION define in Scala whose return value depends on the value of the variable declared OUTSIDE the closure function. Below is the example of closure function:-
Example 1:-


Closure Scala
Output:-
res45:Int = 25

Example 2:-


Closure Scala Example
Output
res46:Int = 35

In example 2 mul2 takes the new value of 'C' when it is second time.

2.

Difference between Java, Scala, Python and R

Answer»

Difference between Java, Scala, Python and R
Below are main difference between Java, Scala, Python and R
(A)Performance:-
(1)Java:-Java is Faster then Python and R language
(1)Scala:-Scala is 10x faster than Python
(1)Python:-Python is much slower then Java and Scala
(1)R:-R is also slower then Java and Scala

(B)Type of User/Developer:-
(2)Java:-In java developer can be either of Web and Hadoop programmers
(2)Scala:-In Scala Developer is like Big data Programmers
(2)Python:-Here developer can be beginners and data engineers
(2)R:-IN R most developer are Data Scientists or statisticians

(C)Interpreted Language(REPL):-
(3)Java:-N.A
(3)Scala:-N.A
(3)Python:-Yes
(3)R:-Yes

(D)Concurrency:-
(4)Java:-Java will support Concurrency
(4)Scala:-Scala also support concurrency
(4)Python:-Python will not support Concurrency
(4)R:-Not Applicable

(E)Learning Curve:-
(5)Java:-Learning Curve in Java is much tougher than python
(5)Scala:-In Scala steep learning curve than Java and Python
(5)Python:-Learning Curve is easiest in all four
(5)R:-Learning curve is moderate in R language

(F)Usage:-
(6)Java:-It is used in Web Development and in Hadoop Native
(6)Scala:-It is used for Spark Native
(6)Python:-We use Python in Data Engineering, Machine Learning and in Data Visualization
(6)R:-We use R Language MAINLY for Visualization, Data analysis and for Statistics use cases.

(G)Type of Language:-
(7)Java:-Used for General Purpose and for Object oriented tasks.
(7)Scala:-Used for General functional purpose and object-oriented features
(7)Python:-We use this as General purpose.
(7)R:-Specifically for Data Scientists Needs conversion into Scala/Python before productizing

(H)Ease of Use:-
(8)Java:- It is verbose
(8)Scala:-Lesser verbose than scala
(8)Python:-It is least verbose
(8)R:-Not applicable

(I)Type Safety:-
(9)Java:-Java is always statically typed
(9)Scala:-Scala is statically typed only one version 2.0 is not.
(9)Python:-It is dynamically typed
(9)R:-R language is also dynamically types

(J)Support and Learning LIBRARIES availability:-
(10)Java:-Support has limited
(10)Scala:-Support has limited
(10)Python:-Support is excellent
(10)R:-Support is excellent

(K)Web Notebooks Support:-
(11)Java:-Ijava Kernel in Jupyter Notebook
(11)Scala:-Apache Zeppelin Notebook Support
(11)Python:-Jupyter Notebook Support
(11)R:-R Notebook

3.

Can you please define the uses of Concurrency and Actor Model?

Answer»

Can you please define the USES of Concurrency and Actor Model?
If you are a java developer you MAY know that Java must follow the conventional thread based concurrency model and this approach will split the PROGRAM into several concurrently running tasks during execution.
Where as on another side in Scala we uses actor model where we can define each OBJECT as an actor with unique behavior and mailbox. So scala will simplifies the thread communication and CONTROL and this will enhance the eficiency of the process.

4.

In Java and Scala which one is pure OOP language?

Answer»

In Java and Scala which one is pure OOP language?
When everything should be an object in programming language it is called as pure Object-Oriented language. Java is not pure OOP language due to below TWO non-oop concepts
(i)Java supports primitive DATA types and they are not objects
(ii)Java also supports STATIC members which are not allowed to objects.
On the other hand Scala is pure OOP Languagebecause everthing in scala is an object and everything is a value. Functions are also values and values are objects. Because scala does not have primitive data types and also not have static members LIKE Java have.

5.

Yield keyword in Scala?

Answer» YIELD keyword in Scala?
We use Yield keyword as a Loop in scala. Yield keyword will returns a result once the loop iteration is complete. Here for loop used buffer internally stored iterated result and when iterations is finisihed it yields the result from that buffer. And this will not work like imperative loop. Because type of collection which is returned is of same type that we tend to were iterating over, Therefore a Map yields a Map, a List yields a List, and so on. And syntax for Yield keyword is given below

VAR result = for{ var x yield x

In above code we have used curly braces that keep the VARIABLE conditions and result is variable where all the VALUES of x are kept within the form of collection.

Below are some silent features of Yield:-
(1)It is used as a Loop.
(2)It produced value for each iteration.
(3)It supports the use of Map, FlatMap, and Filters along with nomads.
6.

Define Streams in Scala with and example?

Answer» DEFINE Streams in SCALA with and example?
To define Streams in scala we use Lazy list to define streams in scala. Its a lazy list which is evaluates the ELEMENTS when we need that. And this types of lazy computation enhances the PERFORMANCE of the program. Below is the example of Streams in Scala.

scala> val stream=12#::14#::16#::Stream.empty
stream: scala.collection.immutable.Stream[int] = Stream(12, ?)

as in above code we DONOT need second element so we have not evaluate the second element
7.

Different types of variables in Scala explain them?

Answer»

Different types of variables in Scala explain them?
There are mainly TWO types of variables in Scala which are given below
(1)Mutable Variables
(2)Immutable variables
(1)Mutable Variables:-
(i)Mutable variable are declare by using the "var" keyword.
(ii)And the values in Mutable variables support changes.
(2)Immutable variables:-
(i)Immutable variables are declare by using "VAL" keyword.
(ii)And the values in Immutable variable do not support changes.

8.

Syntax to Append single and multiple data element in list in Scala?

Answer» SYNTAX to Append single and multiple DATA element in list in SCALA?
We can append single and multiple data element in list in scala. Below is the syntax to ADD single value to the list. And we should use ":+" to append data in list


Add Scala Single
And if we want to multiple values to the list we use "++" to append data in the list.


multivalue in scala
9.

what is use of Tuples in Scala?

Answer»

what is use of Tuples in Scala?
Tuples is a combination of finite numbers of items in Scala. And it is all together programmer can pass TUPLE AROUND as a whole. Tuple is IMMUTABLE and this can hold OBJECTS with different datatypes. This is not LIKE Array or list because these two are mutable.