Wednesday, 19 April 2017

LINQ INTERVIEW QUESTIONS & ANSWERS PART-2

1) Explain what is LINQ? Why is it required?
Language Integrated Query or LINQ is the collection of standard query operators which provides query facilities into.NET framework language like C#, VB.NET.
LINQ is required as it bridges the gap between the world of data and world of objects.

2) What are the types of LINQ?
· LINQ to Objects
· LINQ to XML
· LINQ to Dataset
· LINQ to SQL
· LINQ to Entities

3) Explain how LINQ is useful than Stored Procedures?
Debugging: It is difficult to debug a stored procedure but as LINQ is part of.NET, visual studios debugger can be used to debug the queries.
Deployment: For stored procedure, additional script should be provided but with LINQ everything gets compiled into single DLL hence deployment becomes easy.
Type Safety: LINQ is type safe, so queries errors are type checked at compile time.

4) List out the three main components of LINQ? Explain what is the extension of the file, when LINQ to SQL is used?
Three main components of LINQ are
· Standard Query Operators.
· Language Extensions.
· LINQ Providers.
The extension of the file used is .dbml.

5) Define what is Where clause and Let clause?
Where clause: It allows adding some conditional filters to the query.
Let clause: It allows defining a variable and assigning it a value calculated from the data values.

6) Explain why SELECT clause comes after FROM clause in LINQ?
With other programming language and C#, LINQ is used, it requires all the variables to be declared first. “FROM” clause of LINQ query defines the range or conditions to select records. So, FROM clause must appear before SELECT in LINQ.

7) Explain what is the use of System.XML.Xlinq.dll?
System.Data.Dlinq.dll provides the functionality to work with LINQ to SQL.

8) Explain what is lambda expressions in LINQ?
Lambda expression is referred as a unique function use to form delegates or expression tree types, where right side is the output and left side is the input to the method. For writing LINQ queries particularly, Lambda expression is used.

9) Explain how LINQ with databases can be used?
LINQ supports XML, SQL, Dataset and Objects. Through LINQ to objects or LINQ to Datasets one can use LINQ with other databases. The objects and datasets take care of database particular operations, and LINQ only needs to deal with those objects and not the database operations directly.

10) Explain what is the difference between Skip() and SkipWhile() extension method?
Skip() : It will take an integer argument and from the given IEnumerable it skips the top n numbers.
SkipWhile (): It will continue to skip the elements as far as the input condition is true. It will return all remaining elements if the condition is false.

11) In LINQ how will you find the index of the element using where () with Lambda Expressions?
In order to find the index of the element using where () with the lambda expression
Where ( ( i, ix ) => i == ix);

12) Explain how you can assign a lambda expression to a delegate?
To assign a lambda expression to a delegate
Delegate int del (int i);
Del myDelegate=x=>x*x;
Intj = myDelegate (4); //j=16

13) Explain what is the difference between Statement Lambda and Expression Lambda?
Expression Lambdas are extensively used in the construction of Expression Trees.
To create expression trees statement lambdas cannot be used.

14) Mention what is the role of DataContext classes in LINQ?
DataContext class acts as a bridge between SQL Server database and the LINQ to SQL. For accessing the database and also for changing the data in the database, it contains connections string and the functions.

15) Explain what are LINQ query expressions?
Query expression is nothing but an LINQ query. It is a combination of query clauses that identifies the data sources for a query. It contains information for sorting, filtering, grouping or joining to apply to the source data. It determines what information should be retrieved from the data source.CV.
16) Explain what are compiled queries?
In compiled LINQ queries, the plan is cached in a static class and static class is a global cache. Rather than preparing the query plan from scratch, LINQ prepares plan using stating class object.

17) Explain how standard query operators useful in LINQ?
Standard Query Operators useful in LINQ are
·         Get a total count of elements in the collection.
·         Order the results of a collection.
·         Grouping.
·         Computing average.
·         Joining two collections based on matching keys.
·         Filter the results.

18) Explain what is the purpose of LINQ providers in LINQ?
LINQ providers are set of classes that take an LINQ query which generates method that executes an equivalent query against a particular data source.

19) Explain how you can retrieve a single row with LINQ?
To retrieve a single row with LINQ we need
Public User GetUser (string userName)
{
DBNameDataContext myDB = new DBNameDataContext ( ) ;
User user = myDB. Users. Single ( u, u.UserName => userName );
Return user;
}

20) LINQ query is executed in which statement?
In VB, an LINQ query is executed in the For Each Statement, and in the foreach statement for C#.

21) Explain what is “LINQ to Objects”?
When LINQ queries any IEnumerable(Of T) collection or IEnumerable directly without the use of an intermediate LINQ provider or API such as LINQ to SQL or LINQ to XML is referred as “LINQ to Objects.”

22) Explain how you can differentiate between Conversion Operator “ToDictionary” and “IEnumerable” of LINQ?
To solve the conversion type problems “IEnumerable” and “ToDictionary” conversion operator are used.
“ToDictionary” conversion operator is the instance of Dictionary (k, T). The “keySelector” predicate recognizes the key of each item, while “elementSelector”, is used to extract each single item, if it is given.
Extension method on “IEnumerable” is.AsEnumerable. AsEnumerable simply returns the source sequence as an object of type IEnumerable <T>.


LINQ INTERVIEW QUESTIONS & ANSWERS PART-1


1. What is Language Integrated Query (LINQ)?
LINQ is a programming model that is the composition of general-purpose standard query operators that allow you to work with data, regardless of the data source in any .NET based programming language. It is the name given to a set of technologies based on the integration of query capabilities into any .NET language.

2. What are LINQ query expressions?
A LINQ query, also known as a query expression, consists of a combination of query clauses that identify the data sources for the query. It includes instructions for sorting, filtering, grouping, or joining to apply to the source data. The LINQ query expressions syntax is similar to the SQL syntax. It specifies what information should be retrieved from the data source.

3. Write the basic steps to execute a LINQ query.
The following are the three basic steps to execute a LINQ query:
• Obtain the data source (The data source can be either an SQL database or an XML file).
• Create a query.
• Execute the query.

4. Write the basic syntax of a LINQ query in Visual Basic as well as in C#.
In Visual Basic, the basic syntax of a LINQ query starts with the From clause and ends with the Select or Group Byclause. In addition, you can use the Where, Order By, and Order By Descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.
In C#, the basic syntax of a LINQ query starts with the From clause and ends with the Select or group by clause. In addition, you can use the where, orderby, and Orderby descending clauses to perform additional functions, such as filtering data and generating the data in a specific order.

5. In which statement the LINQ query is executed?
A LINQ query is executed in the For Each statement in Visual Basic and in the foreach statement in C#.

6. In LINQ, lambda expressions underlie many of the standard query operators. Is it True or False?
It is true.

7. What is PLINQ?
PLINQ stands for Parallel Language Integrated Query. It is the parallel implementation of LINQ, in which a query can be executed by using multiple processors. PLINQ ensures the scalability of software on parallel processors in the execution environment. It is used where data grows rapidly, such as in telecom industry or where data is heterogeneous.
PLINQ also supports all the operators of LINQ. In addition, you can query 'collections by using PLINQ. It can also run several LINQ queries simultaneously and makes use of the processors on the system. Apart from this, PLINQ uses parallel execution, which helps in running the queries quickly. Parallel execution provides a major performance improvement to PLINQ over certain types of legacy code, which takes too much time to execute.

8. What are the different Visual Basic features that support LINQ?
Visual Basic includes the following features that support LINQ:
• Anonymous types - Enables you to create a new type based on a query result.
• Implicitly typed variables - Enables the compiler to infer and assign a type when you declare and initialize a variable.
• Extension method - Enables you to extend an existing type with your own methods without modifying the type itself.

9. What is the function of the DISTINCT clause in a LINQ query?
The DISTINCT clause returns the result set without the duplicate values.

10. What is the DataContext class and how is it related to LINQ?
After you add a LINQ to SQL Classes item to a project and open the O/R Designer, the empty design surface represents an empty DataContext class ready to be configured. The DataContext class is a LINQ to SQL class that acts as a conduit between a SQL Server database and the LINQ to SQL entity classes mapped to that database. This class contains the connection string information and the methods for connecting to a database and manipulating the data in the database. It is configured with connection information provided by the first item that is dragged onto the design surface.

11. What is the difference between the Take and Skip clauses?
The Take clause returns a specified number of elements. For example, you can use the Take clause to return two values from an array of numbers. The Skip clause skips the specified number of elements in the query and returns the rest. For example, you can use the Skip clause to skip the first four strings in an array of strings and return the remaining array of string.

12. What is Object Relational Designer (0/R Designer)?
The 0/R Designer provides a visual design surface to create LINQ to SQL entity classes and associations (relationships) that are based on objects in a database.

13. Which interface implements the standard query operators in LINQ?
The standard query operators implement the IEnumerable<T> or the IQueryable<T> interface in C# and the IEnumerable(Of T) or the IQueryable(Of T) interface in Visual Basic.

14. What are standard query operators in LINQ?
The standard query operators in LINQ are the extension methods that form the LINQ pattern. These operators form an API that enables querying of any .NET array or collection. It operates on sequences and allows you to perform operations, such as determining if a value exists in the sequence and performing an aggregated function, such as a summation over a sequence.

15. On what parameter does the GroupBy clause group the data?
The GroupBy clause groups the elements that share a common attribute.

16. What is a LinqDataSource control?
The LinqDataSource control enables you to use LINQ. In an ASP.NET Web page by setting the properties in the markup text. You can use the control retrieve or modify data. It is similar to the SqIDataSource and ObjectDataSource controls in the sense that it can be used to declaratively bind other ASP.NET controls on a page to a data source. The difference is that instead of binding directly to a database or to a generic class, the LinqDataSource control is designed to bind a LINQ enabled data model.

17. How can you open the O/R Designer?
You can open the O/R Designer by adding a new LINQ to SQL Classes item to a project.

18. The standard query operators are themselves a set of extension methods that provide the LINQ query functionality for any type that implements the IEnumerable<T> interface in Visual Basic. Is it True or False?
False, as it implements the IEnumerable(T) interface in Visual Basic and the IEnumerable<T> interface is implemented in C#.

19. What are lambda expressions in LINQ?
A lambda expression is a function without a name that calculates and returns a single value. All lambda expressions use the lambda operator =>, which read as goes to. The left side of the lambda operator specifies the input parameters and the right side holds the expression or statement block.

20. before you query a DataSet object by using LINQ to DataSet, you must first populate the dataset how can you do this?
You can load the data into the dataset by using different methods, such as:
• Using the DataAdapter class
• Using LINQ to SQL

21. What are the different implementations of LINQ?
The different implementations of LINQ are:
• LINQ to SQL - Refers to a component of.NET Framework version 3.5 that provides a run-time infrastructure to manage relational data as objects.
• LINQ to DataSet - Refers to a component that makes it easier and faster to query over data cached in a DataSet object.
• LINQ to XML - Provides an in-memory XML programming interface.
• LINQ to Objects - Refers to the use of LINQ queries with any IEnumerable or IEnumerable(T) collection directly, without the use of an intermediate LINQ provider or API, such as LINQ to SQL or LINQ to XML.

22. Which command-line tool generates code and mapping for the LINQ to SQL component of .NET Framework?
The SqlMetal.exe command-line tool generates code and map the LINQ to SQL component.

23. Name the control that exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.
The LinqDataSource control exposes the LINQ features to Web developers through the ASP.NET data-source control architecture.

24. What is the difference between the Select clause and SelectMany() method in LINQ?
Both the Select clause and SelectMany() method are used to produce a result value from a source of values. The difference lies in the result set. The Select clause is used to produce one result value for every source value. The result value is a collection that has the same number of elements from the query. In contrast, the SelectMany() method produces a single result that contains a concatenated collection from the query.

25. Which extension method do you need to run a parallel query in PLINQ?
The As Parallel extension method is required to run a parallel query in PLINQ.


JavaScript Interview Questions & Answers PART-3

(1) Enumerate the differences between Java and JavaScript?
Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent.  Java is an object – oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language and it is said to be unstructured programming.

(2) What is the use of is NaN function?
isNan function returns true if the argument is not a number otherwise it is false.

(3) What is negative infinity?
Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

(4) Is it possible to break JavaScript Code into several lines?
Breaking within a string statement can be done by the use of a backslash, ‘’, at the end of the first line
Example: document.write(“This is \a program”);
And if you change to a new line when not within a string statement, then JavaScript ignores break in line.
Var x=1, y=2, z=x+y;
The above code is perfectly fine, though not advisable as it hampers debugging.

(5) What are undeclared and undefined variables?
Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.
Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

(6) What are global variables? How are these variable declared and what are the problems associated with using them?
Global variables are those that are available throughout the length of the code, that is, these have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.
Example:
// Declare a global globalVariable = “Test”;
The problems that are faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.

(7) What is a prompt box?
A prompt box is a box which allows the user to enter input by providing a text box.  Label and box will be provided to enter the text or number.

(8) What is the difference between ViewState and SessionState?
‘ViewState’ is specific to a page in a session.
‘SessionState’ is specific to user specific data that can be accessed across all pages in the web application.

(9) Does JavaScript support automatic type conversion?
Yes JavaScript does support automatic type conversion; it is the common way of type conversion used by JavaScript developers.

(10) Explain how to read and write a file using JavaScript?
There are two ways to read and write a file using JavaScript
=> Using JavaScript extensions
=> Using a web page and Active X objects

(11) What is called Variable typing in Javascript?
Variable typing is used to assign a number to a variable and the same variable can be assigned to a string.
Example:-
i=10;
i=”string”
This is called variable typing.

(12) How can you convert the string of any base to integer in JavaScript?
The parseInt() function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter, and the second parameter is the base of the given string.
In order to convert 4F (of base 16) to integer, the code used will be –
parseInt(“4F”,16);

(13)What would be the result of 3+2+”7″?
Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.

(14) Explain how to detect the operating system on the client machine?
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.

(15) What do mean by NULL in Javascript?
The NULL value is used to represent no value or no object.  It implies no object or null string, no valid boolean value, no number and no array object.

(16) What is the function of delete operator?
The functionality of delete operator is used to delete all variables and objects in a program but it cannot delete variables declared with VAR keyword.

(17) What are all the types of Pop up boxes available in JavaScript?
· Alert
· Confirm and
· Prompt

(18) What is the use of Void(0)?
Void(0) is used to prevent the page from refreshing and parameter “zero” is passed while calling.
Void(0) is used to call another method without refreshing the page.

(19) How can a page be forced to load another page in JavaScript?
The following code has to be inserted to achieve the desired effect:
<script language="JavaScript" type="text/javascript" >
<!-- location.href="http://newhost/newpath/newfile.html"; //--></script>

(20) What is the difference between an alert box and a confirmation box?
An alert box displays only one button which is the OK button.
But a Confirmation box displays two buttons namely OK and cancel.

(21) What are escape characters?
Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes and ampersands. Place backslash before the characters to make it display.
Example: document.write “I am “good” boy”

(22) What are JavaScript Cookies?
Cookies are the small test files stored in a computer and it gets created when the user visits the websites to store information that they need. Example could be User Name details and shopping cart information from the previous visits.

(23) Explain what is pop()method in JavaScript?
The pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array. 
Also the pop() method take the last element off of the given array and returns it. The array on which is called is then altered.
Example:
Var cloths= [“Shirt”,”Pant”,”TShirt”];
cloths.pop();
//Now cloth becomes Shirt,Pant

(24) Whether JavaScript has concept level scope?
No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.

(25) Mention what is the disadvantage of using innerHTML in JavaScript?
Content is replaced everywhere.
We cannot use like “appending to innerHTML”.
Even if you use +=like “innerHTML = innerHTML + ‘html’” still the old content is replaced by html.
The entire innerHTML content is re-parsed and build into elements, therefore its much slower
The innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it.

(26) What is break and continue statements?
Break statement exits from the current loop.
Continue statement continues with next statement of the loop.

(27) What are the two basic groups of dataypes in JavaScript?
They are as –Primitive, Reference types.
Primitive types are number and Boolean data types. Reference types are more complex types like strings and dates.

(28) How generic objects can be created?
Generic objects can be created as:
Var I=NEW OBJECT();

(29) Which keywords are used to handle exceptions?
Try… Catch—finally is used to handle exceptions in the JavaScript
Try{
Code
}
Catch(exp){
Code to throw an exception
}
Finally{
Code runs either it finishes successfully or after catch
}

(30) How will you get the Checkbox status whether it is checked or not? 
var status = document.getElementById('checkbox1').checked;
alert(status);
will return true or false.

(31) Describe the properties of an anonymous function in JavaScript?
A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.
Anonymous function declaration –   
var anon = function() {
alert('I am anonymous');
};
anon();

(32) What is the difference between .call() and .apply()?
The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function’s arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.
The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.
var someObject = {
myProperty : 'Foo',
myMethod : function(prefix, postfix) {
alert(prefix + this.myProperty + postfix);
}
};
someObject.myMethod('<', '>'); // alerts '<Foo>'
var someOtherObject  = {
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>'); // alerts '<Bar>'
someObject.myMethod.apply(someOtherObject, ['<', '>']); // alerts '<Bar>'

(33) How are DOM utilized in JavaScript?
DOM stands for Document Object Model and is responsible for how various objects in a document interact with each other. DOM is required for developing web pages, which includes objects like paragraph, links, etc. These objects can be operated to include actions like add or delete. DOM is also required to add extra capabilities to a web page. On top of that, the use of API gives an advantage over other existing models.

(34) Why it is not advised to use innerHTML in JavaScript?
innerHTML content is refreshed every time and thus is slower. There is no scope for validation in innerHTML and, therefore, it is easier to insert rouge code in the document and, thus, make the web page unstable.

(35) How are JavaScript and ECMA Script related?
ECMA Script are like rules and guideline while Javascript is a scripting language used for web development.

(36)What is namespacing in JavaScript and how is it used?
Namespacing is used for grouping the desired functions, variables etc. under a unique name. It is a name that has been attached to the desired functions, objects and properties. This improves modularity in the coding and enables code reuse.

(37) How can JavaScript codes be hidden from old browsers that don’t support JavaScript?
For hiding JavaScript codes from old browsers:
Add “<!–” without the quotes in the code just after the <script> tag.
Add “//–>” without the quotes in the code just before the <script> tag.

(38) Explain the unshift() method ?
This method is functional at the starting of the array, unlike the push(). It adds the desired number of elements to the top of an array. For example –
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
The output is:- [" joseph "," Jane ", " charlie ", " john "]

(39) Define unescape() and escape() functions?
The escape () function is responsible for coding a string so as to make the transfer of the information from one computer to the other, across a network.
For Example:
<script>
document.write(escape(“Hello? How are you!”));
</script>
Output: Hello%3F%20How%20are%20you%21
The unescape() function is very important as it decodes the coded string.
For example:
<script>
document.write(unescape(“Hello%3F%20How%20are%20you%21”));
</script>
Output: Hello? How are you!

(40) Between JavaScript and an ASP script, which is faster?
JavaScript is faster. JavaScript is a client-side language and thus it does not need the assistance of the web server to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript.  JavaScript now is also a server side language (nodejs).

(41) What is the use of blur function?     
Blur function is used to remove the focus from the specified object.

(42) How to find operating system in the client machine using JavaScript?
The ‘Navigator.appversion’ is used to find the name of the operating system in the client machine.

(43) What is the ‘Strict’ mode in JavaScript and how can it be enabled?
Strict Mode adds certain compulsions to JavaScript. Under the strict mode, JavaScript shows errors for a piece of codes, which did not show an error before, but might be problematic and potentially unsafe. Strict mode also solves some mistakes that hamper the JavaScript engines to work efficiently.
Strict mode can be enabled by adding the string literal “use strict” above the file. This can be illustrated by the given example:
function myfunction()
{
    “use strict";
var v = “This is a strict mode function";
}

(44) How can the OS of the client machine be detected?
The navigator.appVersion string can be used to detect the operating system on the client machine.

(45) Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
(46) Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.

(47) How can a particular frame be targeted, from a hyperlink, in JavaScript?
This can be done by including the name of the required frame in the hyperlink using the ‘target’ attribute.
<a href=”newpage.htm” target=”newframe”>>New Page</a>

(48) Write the point of difference between web-garden and a web-farm?
Both web-garden and web-farm are web hosting systems. The only difference is that web-garden is a setup that includes many processors in a single server while web-farm is a larger setup that uses more than one server.

(49) What is the method for reading and writing a file in JavaScript?
This can be done by Using JavaScript extensions (runs from JavaScript Editor), example for opening of a file – fh = fopen(getScriptPath(), 0);

(50) How are event handlers utilized in JavaScript?
Events are the actions that result from activities, such as clicking a link or filling a form, by the user. An event handler is required to manage proper execution of all these events. Event handlers are an extra attribute of the object. This attribute includes event’s name and the action taken if the event takes place.

(51) Explain the role of deferred scripts in JavaScript?
By default, the parsing of the HTML code, during page loading, is paused until the script has not stopped executing. It means, if the server is slow or the script is particularly heavy, then the webpage is displayed with a delay. While using Deferred, scripts delays execution of the script till the time HTML parser is running. This reduces the loading time of web pages and they get displayed faster.

(52) What are the various functional components in JavaScript?
The different functional components in JavaScript are-
First-class functions: Functions in JavaScript are utilized as first class objects. This usually means that these functions can be passed as arguments to other functions, returned as values from other functions, assigned to variables or can also be stored in data structures.
Nested functions: The functions, which are defined inside other functions, are called Nested functions. They are called ‘everytime’ the main function is invoked.

(53) What are Screen objects?
Screen objects are used to read the information from the client’s screen. The properties of screen objects are –
·         AvalHeight: Gives the height of client’s screen.
·         AvailWidth: Gives the width of client’s screen.
·         ColorDepth: Gives the bit depth of images on the client’s screen.
·         Height: Gives the total height of the client’s screen, including the taskbar.
·         Width: Gives the total width of the client’s screen, including the taskbar.

(54) What are the decodeURI() and encodeURI()?
EncodeURl() is used to convert URL into their hex coding. And DecodeURI() is used to convert the encoded URL back to normal.
<script>
var uri="my test.asp?name=ståle&car=saab";
document.write(encodeURI(uri)+ "<br>");
document.write(decodeURI(uri));
</script>
Output –
my%20test.asp?name=st%C3%A5le&car=saab
my test.asp?name=ståle&car=saab