Skip to content

Instantly share code, notes, and snippets.

@pradhuman7d1
pradhuman7d1 / FAQ
Created December 15, 2021 11:47
scala-abstract-trait
Q. What does abstract class means?
A. Abstract class is one which declares variables or functions but does not initialize or define their body.
Q. What are traits?
A. Traits are like interfaces the simply define some values or functions and then inplemented into classes. Their can also be concrete methods.
Q. Why we use traits when we can do the same with abstract class?
A. We use trait because we can use multiple traits in one class whereas only one abstract class can be used.
Q. What is the purpose of traits?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 15, 2021 11:30
scala-class-inheritance
Q. What are classes?
A. A class is a block of code that contains declaration on some member variables and functions and then we create multiple objects for the class that assigns the values to the variables.
Q. What is inheritance?
A. Inheritance is the use of properties and variables of an existing class into a new class.(a new class inherits from old class)
Q. What is an object?
A. A variable that we create in our program using a class that we have created. That object contains the values corresponding to variables declared in the class.
Q. Why we use inheritance?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 15, 2021 11:04
scala-tuples-maps
Q. What is the difference between arrays ans tuples?
A. Tuples are just like arrays but they are immutable.
Q. Can we traverse a tuple using foreach loop?
A. Yes we can, but we have to use the tuple function .productIterator for doing the same.
Q. What datatypes are allowed for keys or values in a map?
A. No limitations whatsoever, you can store any datatype for keys as well as values.
Q. Can we edit or add new values to a map?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 15, 2021 10:14
scala-arrays
Q. What is the difference between array and arraybuffer?
A. Arrays are fixed in size and insert or remove operations are not possible, while arraybuffer is dynamic.
Q. How we initialize an array in scala?
A. val arr = new Array[Int](10) this is the syntax to create an array of size 10.
Q. What we need to import to create an ArrayBuffer?
A. the import we need is - scala.collection.mutable.ArrayBuffer
Q. Can we update the value of an element in an array?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 15, 2021 08:36
scala-functions
Q. What is unit return type?
A. unit is used whenever we don't need to return a value.
Q. val p = pow _ ; what is p storing here?
A. p is storing the function pow and this is an example of higher order functions.
Q. What are closures?
A. Closures are special functions that can access and use values declared outside of it.
Q. What are anonymous functions?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 6, 2021 11:40
perl-File i/o
Q. What is the use of die keyword?
A. When the program fail to read or write a file then it will kill itself and print the error provided with die keyword.
Q. Perl is used mainly to deal with what files?
A. Perl stands for practical extraction and report language and as the name suggests it is most efficient in handling txt files.
Q. What operations are supported by the file handler of perl?
A. Open and read, open and append, open and write are the common operations supported by perl.
Q. What does <$fh> do?
@pradhuman7d1
pradhuman7d1 / FAQ
Created December 6, 2021 11:07
PERL-OOPS
Q. What is inheritance?
A. The process by which a class can use the properties and methods of another class by inheriting it is inheritance.
Q. What is a ".pm" file?
A. A ".pm" file is a package file for a perl script, pm stands for perl module, it can be used to write code for some specific task and call it from main script.
Q. What is the use of '->'?
A. This notation is used to access or create a perticular object in a class.
Q. How we can create and use a class?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 12:37
Kotlin Collections
Q. What are some examples of collections ?
A. Lists, Arrays, Maps, Sets are collections.
Q. How many types of lists are there?
A. Lists are of two types : Mutable Lists and Immutable Lists.
Q. What is a map?
A. A map is a collection that holds and key and a value pair.
Q. What datatypes can be stored in collections?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 12:19
Kotlin Collection operators and exception handling
Q. What are collection operator?
A. Collection operators are prebuilt functions that can perform certain operations on a collection.
Q. What is the difference in reduce and fold?
A. Reduce only performs the defined operation on the collection whereas fold have an initial value and performs the operation defined with it.
Q. What is exception handling?
A. When performing certain tasks, there are cases where some exceptions might occur, to prevent them we can use try and catch to.
Q. What is map operator?
@pradhuman7d1
pradhuman7d1 / FAQ
Created November 26, 2021 11:52
Kotlin Tail Recursion and Higher Order Functions
Q. What is tailrec?
A. tailrec keyword is used for tail recursion in kotlin.
Q. What are higher order functions?
A. higher order functions are the functions that can return a function and can accept a function as argument.
Q. What is the use of higher order functions?
A. Higher order functions are used a lot in functional programming, they can help generate new functions as per requirements.
Q. What is it keyword?