Sunday, May 22, 2022

Senior developer Interview Questions

 

  1. What are the advantaged of using interfaces
  2. Difference between abstract class and encapsulation
  3. Can we have strings in enum? what is the default value and type, Can enum be long and short?
  4. What is managed, unmanaged code? give examples
  5. What is sealed class? Can I have abstract sealed class?-
  6. static const? Can I apply static to const?
  7. Can I use new modifier on static
  8. Sealed, Virtual, overide
  9. Difference between new and overrride
  10. this keyword on static class
  11. Can a virtual method have static
  12. Difference between dispose, finalize ( Used by Garbage collector)
  13. What are Anoymous method
  14. Difference between IQueryable and Ienumarable? HAve ou used Entity Framework
  15. linq - iqueryable-code side filter - performance, ienumerable, filter
  16. Difference between Thread and Task
Task is a background task. 
Use Task for quick operations
Execute task asynchronously and in parallel(multiple cores)
Task by default, uses CLR threadpool
Tasks support cancellation
Task supports: async,await keywords
Threads are expensive
Thread can be a foreground or background
  1. difference between Dependency Injection and IOC
  2. What is Transient, Scoped, singleton
  3. How is DI managed in .NET core
builder.Services.AddScoped<IMyDependency, MyDependency>()
asp.net core injects the instances of dependency classes by using builtin IOC container

Routing is he process of mapping an incoming http request to a specific method in our app code.
Attribute routing is used to create REST API endpoints for web services
It uses a set of attributes to map action methods to route templates

Action filters are used to implement logic that gets executed before and after a controller action executes.

What is common table expression
Common Table expression is a temporary named result set that you can reference with a SELECT, INSERT, UPDATE OR DELETE statement
WITH expression_name ([column_names..).]
AS
    cte query definition
Two types of CTE:
1. Recursive: Use recursive procedural loops
2. Non-recursive: CTE ddoesn;t use recursion
  1. Difference between Temp table and table variable:Temp table: supports transactions and error handling, DDL statements, table variable do not support transaction, error handling ddl statements, Tmp table is for big datasets, table variable is for small datasets
TABLE VARIABLE:
DECLARE @T ABLEVARIABLE TABLE(COLUMN1 DATATYPE, COLUMN2 DATATYPE)
TEMP TABLE:
CREATE TABLE {# | ##} TEMP_TABLE_NAME(DOLUMN DATATYPE OCNSTRAINT)

Triggers and types of triggers. Trigger is a piece of code executed automatically in response to a specific event occurrent on a table in a database, it is invoked before or after Insert, update delete, there are two types of triggers: row and statement level triggers. row level trigger executes each time a row is affected by an update statement. statement trigger is called once regardless of how many rows affected by the UPDATE statement
  1. What did you work on AWS? Have you worked with AWS lambda
  2. What is self join? join in which a table is joined with itself means each row of the table is combined with itself and with every other row of the table,
  3. What PMP tools have you used? I have used Trello, Asana, Jira, Google sheets
  4. var result = employees.Where(x1 => x1.Salary == employees.OrderByDescending(x => x.Salary) .Select(x => x.Salary).Distinct().Take(NthNumber) .Skip(NthNumber - 1).FirstOrDefault()).ToArray();

Sunday, May 1, 2022

ASP.NET Web API Interview Questions and Answers

 

 

 

 

1.                   What is ASP.NET Web API?

The term API stands for Application Programming Interface. ASP.NET Web API is a framework that makes it easy to build Web APIs, i.e. HTTP based services on top of the .NET Framework. ASP.NET Web API is an ideal platform for building Restful services. These services can then be consumed by a broad range of clients like

·       Browsers

·       Mobile applications

·       Desktop applications

·       IOTs

2.                   What is the Rest?

REST stands for Representational State Transfer. This is an architectural pattern used for exchanging data over a distributed environment. In Rest, there is something called Client and Server, and the data can be exchanged between the client and server over a distributed environment. Distributed environment means the client can be on any platform like Java, .NET, PHP, etc. and the server can also be on any platform like Java, .NET, PHP, etc. The REST architectural pattern treats each service as a resource and a client can access those resources by using HTTP Protocol methods such as GET, POST, PUT, PATCH, and DELETE.

3.                   What are the RESTful services?

REST stands for Representational State Transfer.. REST is an architectural pattern for exchanging data over a distributed environment. REST architectural pattern treats each service as a resource and a client can access these resources by using HTTP protocol methods such as GET, POST, PUT, PATCH, and DELETE. The REST architectural pattern specifies a set of constraints that a system should be adhered to. Here are the REST constraints.

4.                   What are the differences between REST and SOAP?

The difference between REST and SOAP is given below:

·       SOAP stands for Simple Object Access Protocol whereas REST stands for Representational State Transfer.

·       The SOAP is an XML-based protocol whereas REST is not a protocol rather it is an architectural pattern i.e. resource-based architecture.                        

·       SOAP has specifications for both stateless and state-full implementation whereas REST is completely stateless.

·       SOAP enforces message format as XML whereas REST does not enforce message format as XML or JSON.

·       The SOAP message consists of an envelope that includes SOAP headers and body to store the actual information we want to send whereas REST uses the HTTP build-in headers (with a variety of media-types) to store the information and uses the HTTP Methods such as GET, POST, PUT, PATCH, and DELETE  to perform CRUD operations.

·       SOAP uses interfaces and named operations (i.e. Service Contract and Operation Contract) to expose the service whereas to expose resources (service) REST uses URI and methods like (GET, PUT, POST, PATCH, and DELETE).

·       SOAP Performance is slow as compared to REST.

 

5.                   State management

SQL Interview Questions

1.     Index ?


Index is a lookup table associated with actual table or view that is used by the database to improve the data retrieval performance timing. In index, keys are stored in a structure (B-tree) that enables SQL Server to find the row or rows associated with the key values quickly and efficiently. Index gets automatically created if primary key and unique constraint is defined on the table


2.     Differences between clustered and non-clustered indexes.


There can be only one clustered index per table. However, you can create multiple non-clustered indexes on a single table.

Clustered indexes only sort tables. Therefore, they do not consume extra storage. Non-clustered indexes are stored in a separate place from the actual table claiming more storage space.

Clustered indexes are faster than non-clustered indexes since they don’t involve any extra lookup step


3.     What do you understand by query optimization?


The phase that identifies a plan for evaluation query which has the least estimated cost is known as query optimization.

The advantages of query optimization are as follows:

·       The output is provided faster

       A larger number of queries can be executed in less time

·       Reduces time and space complexity


4.     Explain different types of Normalization.

There are many successive levels of normalization. These are called normal forms. Each consecutive normal form depends on the previous one.The first three normal forms are usually adequate.

·       First Normal Form (1NF) – No repeating groups within rows

·       Second Normal Form (2NF) – Every non-key (supporting) column value is dependent on the whole primary key.

·       Third Normal Form (3NF) – Dependent solely on the primary key and no other non-key (supporting) column value.

5.     What is the ACID property in a database?

ACID stands for Atomicity, Consistency, Isolation, Durability. It is used to ensure that the data transactions are processed reliably in a database system.

·       Atomicity: Atomicity refers to the transactions that are completely done or failed where transaction refers to a single logical operation of a data. It means if one part of any transaction fails, the entire transaction fails and the database state is left unchanged.

·       Consistency: Consistency ensures that the data must meet all the validation rules. In simple words,  you can say that your transaction never leaves the database without completing its state.

·       Isolation: The main goal of isolation is concurrency control.

·       Durability: Durability means that if a transaction has been committed, it will occur whatever may come in between such as power loss, crash or any sort of error

6.     What do you mean by “Trigger” in SQL?

A SQL trigger is a database object which fires when an event occurs in a database. We can execute a SQL query that will "do something" in a database when a change occurs on a database table such as a record is inserted or updated or deleted. For example, a trigger can be set on a record insert in a database table

7.     List the ways to get the count of records in a table?

To count the number of records in a table in SQL, you can use the below commands:

·       SELECT COUNT(*) FROM table1

·       SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2

8.     Write a SQL query to get the third-highest salary of an employee from employee_table?

TOP keyword

SELECT TOP 1 salary

FROM(


SELECT TOP 3 salary

FROM employee_table

ORDER BY salary DESC) AS emp

ORDER BY salary ASC;


Using Limit :

SELECT salary 

FROM employee_table 

ORDER BY salary DESC 

LIMIT 2, 1


Sub Query

SELECT salary  

FROM 

    (SELECT salary 

     FROM employee_table 

     ORDER BY salary DESC 

     LIMIT 3) AS Comp 

ORDER BY salary 

LIMIT 1;


Rank:

select * from(

select ename, sal, dense_rank() 

over(order by sal desc)r from Employee) 

where r=&n;


To find to the 2nd highest sal set n = 2

To find 3rd highest sal set n = 3 and so on.

SELECT EmpName , Salary FROM(

SELECT ROW_NUMBER() OVER(ORDER BY Salary DESC) AS SNo , EmpName, Salary

FROM Employee

)Sal

WHERE SNo = 3


9.       How can you fetch alternate records from a table?

You can fetch alternate records i.e both odd and even row numbers. For example- To display even numbers, use the following command:

Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=0

Now, to display odd numbers:

Select studentId from (Select rowno, studentId from student) where mod(rowno,2)=1


10.   What is a View?

A view is a virtual table which consists of a subset of data contained in a table. Since views are not present, it takes less space to store. View can have data of one or more tables combined and it depends on the relationship


11.

1. An organization is having multiple departments

2. Organization is having multiple employees

3. An employee can play one or multiple roles in same or various departments


employee(eid, ename, salary)

department(did, dname)

empdept(eid, did, role)


Write down the query to select employee count of the department along with the department name. It should select those department as well which are having no employees.


SELECT department_name AS 'Department Name', 

COUNT(*) AS 'No of Employees' 

FROM departments 

INNER JOIN employees 

ON employees.department_id = departments.department_id 

GROUP BY departments.department_id, department_name 

ORDER BY department_name;

1212.

The nth highest salary in SQL SERVER using TOP keyword

SELECT TOP 1 salary FROM ( SELECT DISTINCT TOP N salary FROM #Employee ORDER BY salary DESC ) AS temp ORDER BY salary 


using row num 


 SELECT * FROM ( SELECT e.*, ROW_NUMBER() OVER (ORDER BY salary DESC) rn FROM Employee e ) WHERE rn = N



Difference Between SCOPE_IDENTITY() and @@IDENTITY

 

@@IDENTITY - Returns the last identity values that were generated in any table in the current session. @@IDENTITY is not limited to a specific scope.

 

SCOPE_IDENTITY() - Return the last identity values that are generated in any table in the current session. SCOPE_IDENTITY returns values inserted only within the current scope.

.Net Interview Questions

  

 

 

1.       Main components of .NET framework

.NET framework consists of 2 main components. They are:

 

Common Language Runtime- It is an execution engine that runs the code and provides services that make the development process easier.

Framework Class Library- It has pre-defined methods and properties to implement common and complex functions that can be used by .NET applications.

 

2.       What is CTS?

CTS stands for Common Type System. It follows a set of structured rules according to which a data type should be declared and used in the program code. It is used to describe all the data types that are going to be used in the application.

 

We can create our own classes and functions by following the rules in the CTS. It helps in calling the data type declared in one programming language by other programming languages.

 

3.        Explain CLS

Common Language Specification (CLS) helps the application developers to use the components that are inter-language compatible with certain rules that come with CLS. It also helps in reusing the code among all of the .NET-compatible languages.

 

4.        What is JIT?

JIT stands for Just In Time. It is a compiler that converts the intermediate code into the native language during the execution.

5.       What is a delegate in .NET?

Delegate is representative which helps us to call back to the function and do data communication.

A delegate is a .NET object which defines a method signature and it can pass a function as a parameter.

Delegate always points to a method that matches its specific signature. Users can encapsulate the reference of a method in a delegate object.

When we pass the delegate object in a program, it will call the referenced method. To create a custom event in a class, we can make use of delegate

6. get 4th highest array ?

sort array and remove duplicates c#

// 4th highest 123,123,122,12334,1212,1211,321,2334,1211,12334,2123,1221,222,122

public static void Main()

{

Console.WriteLine("Hello World");

getArray();

}

public static void getArray()

{

int[] myArr=new []{123,123,122,12334,1212,1211,321,2334,1211,12334,2123,1221,222,122};

int[] newArr=myArr.Distinct().ToArray();

Array.Sort(newArr);

Console.WriteLine("Sorted array:");

for(int i=0;i<newArr.Length;i++)

Console.WriteLine(newArr[i].ToString());

Array.Reverse(newArr);

Console.WriteLine("4th highest: "+newArr[3].ToString());

}



  • C# reverse of String without changing special characters position
  • polymorphism c# example with program
  • Web Api Security implementation
  • Web Api session management
  • MVC Session management
  • MVC Security