Expert Interviews for Extra Traffic EBook
what is connected architecture and disconnected architecture
Connected Architecture
The architecture of ADO.net, in which connections must be opened to access the data retrieved from database is called a connected architecture. The connected architecture was built on the classes connection, command, datareader and transaction.
Disconnected Architecture in ADO.NET
The architecture of ADO.net in which data retrieved from the database can be accessed even when connection to the database was closed is called disconnected architecture. The disconnected architecture of ADO.net was built on classes connection, DataAdapter, command builder, and dataset and data view.
Difference between Primary vs foreign vs unique key.
A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.
A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.There can be many unique constraint defined per table, but only one Primary key constraint defined per table.
A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.
What are the types of join and explain each?
There are various types of join which can be used to retrieve data and it depends on the relationship between tables.
Inner Join.= Inner join return rows when there is at least one match of rows between the tables.
Right Join.= Right join return rows which are common between the tables and all rows of Right hand side table. Simply, it returns all the rows from the right hand side table even though there are no matches in the left hand side table.
Left Join.= Left join return rows which are common between the tables and all rows of Left hand side table. Simply, it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.
Full Join.= Full join return rows when there are matching rows in any one of the tables. This means, it returns all the rows from the left hand side table and all the rows from the right hand side table.
What is store procedure with advantage n disadvantages?
Stored Procedure is a function consists of many SQL statement to access the database system. Several SQL statements are consolidated into a stored procedure and execute them whenever and wherever required.
Stored procedure can be used as a modular programming – means create once, store and call for several times whenever required. This supports faster execution instead of executing multiple queries.
Disadvantage is that it can be executed only in the Database and utilizes more memory in the database server.
write query of sql to display second highest salary
SELECT NAME, MAX(salary) AS salary FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);
select salary from employee order by salary desc limit 2;
select MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) from Employee);
Write query of SQL to display date in between range.
SELECT * from Product_sales where From_date BETWEEN '2013-01-03'AND '2013-01-09';
What are 1,2,3 and N tier of Architecture?
One Tier Architecture:
One-tier architecture has all the layers such as Presentation, Business, and Data Access layers in a single software package. Applications which handles all the three tiers such as MP3 player, and MS Office come under the one-tier application. The data is stored in the local system or a shared drive.
Two-Tier Architecture:
The Two-tier architecture is divided into two parts:
Client Application (Client Tier)
Database (Data Tier)
The client system handles both Presentation and Application layers and the Server system handles the Database layer. It is also known as a client-server application. The communication takes place between the Client and the Server. The client system sends the request to the server system and the server system processes the request and sends back the data to the Client System
Three-Tier Architecture:
The Three-tier architecture is divided into three parts:
Presentation layer (Client Tier)
Application layer (Business Tier).
3. Database layer (Data Tier)
Client system handles Presentation layer, Application server handles Application layer and Server system handles Database layer.
Nth Tier Architecture:
Tier application AKA Distributed application. It is similar to three tier architecture but number of application servers are increased and represented in individual tiers in order to distributed the business logic so that the logic will be distributed.
Difference between Delete Truncate and Drop.
DELETE command is used to remove rows from the table, and WHERE clause can be used for conditional set of parameters. Commit and Rollback can be performed after delete statement.
TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.
DROP command removes a table from the database and operation cannot be rolled back.
What is function and method?
A function is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:
A method is implicitly passed the object on which it was called.
A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).
Difference between Authentication and Authorization.
Authentication is the process of validating a user on the credentials (username and password) and authorization performs after authentication. After Authentication a user will be verified for performing the various tasks, It access is limited it is known as authorization
Difference between Static page n Dynamic Page.
What are Types of Events?
Page_PreInit
2) Page_Init
3) Page_InitComplete
4) Page_PreLoad
5) Page_Load
6) Page_LoadComplete
7) Page_PreRender
8) Render
RenderComplete
10) SaveState
11) SaveState Complete
12)Unload
13.What is Assembly?
An assembly is a file that is automatically generated by the compiler upon successful compilation of every .NET application. It can be either a Dynamic Link Library or an executable file. It is generated only once for an application and upon each subsequent compilation the assembly gets updated.
14. What is View in SQL?
A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store.
What is Asp.net and MVC?
It is a framework developed by Microsoft on which we can develop new generation web sites using web forms(aspx), MVC, HTML, Javascript, CSS etc. Its successor of Microsoft Active Server Pages(ASP).
MVC is a framework used to create web applications. The web application base builds on Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.
16.What is Index and Types of Index?
An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.
Unique Index:- This indexing does not allow the field to have duplicate values if the column is unique indexed. Unique index can be applied automatically when primary key is defined.
Clustered Index:-This type of index reorders the physical order of the table and search based on the key values. Each table can have only one clustered index i.e Primary key.
NonClustered Index:-NonClustered Index does not alter the physical order of the table and maintains logical order of data. Each table can have 999 nonclustered indexes i.e unique key.
17.What is Trigger?
A DB trigger is a code or programs that automatically execute with response to some event on a table or view in a database. Mainly, trigger helps to maintain the integrity of the database.
Difference Between Execute Scalar and ExecuteNonQuery.
ExecuteScalar returns output value where as ExecuteNonQuery does not return any value but the number of rows affected by the query. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.
What are the commands of SQL Server?
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and update data in database.
SELECT – Retrieves data from a table
INSERT – Inserts data into a table
UPDATE – Updates existing data into a table
DELETE – Deletes all records from a table
DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database objects in database.
CREATE – Creates objects in the database
ALTER – Alters objects of the database
DROP – Deletes objects of the database
TRUNCATE – Deletes all records from a table and resets table identity to initial value.
DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential integrity as well it is used to control access to database by securing it.
GRANT – Gives user’s access privileges to database
REVOKE – Withdraws user’s access privileges to database given with the GRANT command
TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring within a database.
COMMIT – Saves work done in transactions
ROLLBACK – Restores database to original state since the last COMMIT command in transactions
SAVE TRANSACTION – Sets a savepoint within a transaction
20.What are the different types of cookies in ASP.NET?
Session Cookie - Resides on the client machine for a single session until the user does not log out.
Persistent Cookie - Resides on a user's machine for a period specified for its expiry, such as 10 days, one month, and never.
21.What is Caching, Session and State Management?
Caching is a technique used to increase performance by keeping frequently accessed data or files in memory. The request for a cached file/data will be accessed from cache instead of actual location of that file.
There are 2 types State Management:
1. Client – Side State Management
This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator(url), or a cookie. The techniques available to store the state information at the client end are listed down below:
a. View State – ViewState is used to retain the state of server-side objects between page post back
b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.
c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.
d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.
e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.
2. Server – Side State Management
a. Application State - Application State information is available to all pages, regardless of which user requests a page.
b. Session State – Session State information is available to all pages opened by a user during a single visit.
Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.
What are Oops Concepts and explain each of it
OOP including inheritance, encapsulation, abstraction, and polymorphism:
Encapsulation is when a group of related methods, properties, and other members are treated as a single object.
Inheritance is the ability to receive (“inherit”) methods and properties from an existing class.
Polymorphism The name means, one name, many forms. It is achieved by having multiple methods with the same name but different implementations.
Abstraction is used to display only the essential features of the class and hides the unnecessary information.
How to Connect Database?
Write a Query of Connection Strings.
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
What is Delegate?
A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.
Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegateclass.
What is Generics in C#?
Generics allow you to delay the specification of the data type of programming elements in a class or a method, until it is actually used in the program. In other words, generics allow you to write a class or method that can work with any data type.
Write a Code of Binding Data in Gridview using store procedure?
protectedvoid Page_Load(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection(@"Data Source=MAXGEN-PC\SQLEXPRESS;Initial Catalog=gura\;Integrated Security=True;Pooling=False");
SqlCommand cmd = newSqlCommand("gridview", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = newSqlDataAdapter(cmd);
DataSet ds = newDataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
What is Httphandler and Httpmodule?
There are two ways in which you can inject logic in the request pipeline of an ASP.NET application -- HttpHandlers and HttpModules. An HttpModule is a component that is part of the ASP.NET request processing pipeline and is called on every request that is made to your application.
Note that HttpModules can have access to the life cycle events of a request and hence they can be used to modify the response as well. HttpModules are generally used for plugging in the cross cutting concerns like security, logging, etc. in the request processing pipeline and can also be used for URL re-writing and even for creating custom headers in the response.
What is CLR,CLS, CTS?
Common Language Runtime (CLR)
.Net Framework provides runtime environment called Common Language Runtime (CLR).It provides an environment to run all the .Net Programs. The code which runs under the CLR is called as Managed Code. Programmers need not to worry on managing the memory if the programs are running under the CLR as it provides memory management and thread management.
Common Type System (CTS)
It describes set of data types that can be used in different .Net languages in common. (i.e), CTS ensures that objects written in different .Net languages can interact with each other.
Common Language Specification (CLS)
It is a sub set of CTS and it specifies a set of rules that needs to be adhered or satisfied by all language compilers targeting CLR. It helps in cross language inheritance and cross language debugging.
30.What is ASP.Net Page Lifecycle?
Page Request- This is when the page is first requested from the server. When the page is requested, the server checks if it is requested for the first time. If so, then it needs to compile the page, parse the response and send it across to the user. If it is not the first time the page is requested, the cache is checked to see if the page output exists. If so, that response is sent to the user.
Page Start – During this time, 2 objects, known as the Request and Response object are created. The Request object is used to hold all the information which was sent when the page was requested. The Response object is used to hold the information which is sent back to the user.
Page Initialization – During this time, all the controls on a web page is initialized. So if you have any label, textbox or any other controls on the web form, they are all initialized.
Page Load – This is when the page is actually loaded with all the default values. So if a textbox is supposed to have a default value, that value is loaded during the page load time.
Validation – Sometimes there can be some validation set on the form. For example, there can be a validation which says that a list box should have a certain set of values. If the condition is false, then there should be an error in loading the page.
Postback event handling – This event is triggered if the same page is being loaded again. This happens in response to an earlier event. Sometimes there can be a situation that a user clicks on a submit button on the page. In this case, the same page is displayed again. In such a case, the Postback event handler is called.
Page Rendering – This happens just before all the response information is sent to the user. All the information on the form is saved, and the result is sent to the user as a complete web page.
Unload – Once the page output is sent to the user, there is no need to keep the ASP.net web form objects in memory. So the unloading process involves removing all unwanted objects from memory.
31. What are different Types of Validators in Asp.net?
Required field Validator
Range Validator
Compare Validator
Custom Validator
Regular expression Validator
Summary Validator
32. What is Thread in C# ?
Thread allows creating and accessing individual threads in a multithreaded application. The first thread to be executed in a process is called the main thread. When a C# program starts execution, the main thread is automatically created.
33. What is an Interface?
An Interface is a class with no implementation. The only thing that it contains is the declaration of methods, properties, and events.
34. What is a Deadlock?
A Deadlock is a situation where a process is not able to complete its execution because two or more processes are waiting for each other to finish.
35. What is Constraint?
Constraint can be used to specify the limit on the data type of table. Constraint can be specified while creating or altering the table statement.Not Null, Check, Defalut, Unique, Primary key, Foreign key,
36. What is database Normalization?
Normalization is the process of organizing the data in the database.it is used to minimize the redundancy from a relation
37. What is Class and Object?
Class is a blueprint or a set of instruction to build a specific type of object. It provides initial values for member variables and member functions or method. An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. A class that is declared using “abstract” keyword is known as an abstract class.
38. What is method overloading and method overriding?
If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. Declaring a method in sub class which is already present in parent class is known as method overriding.
--------------------------------
MVC
Explain Model, View, and Controller in Brief.
A model can be defined as the data that will be used by the program. Commonly used examples of models in MVC are the database, a simple object holding data (such as any multimedia file or the character of a game), a file, etc.
A view is a way of displaying objects (user interfaces) within an application. This is the particular vertical through which end users will communicate.
A controller is the third vertical which is responsible for updating both models and views. It accepts input from users as well as performs the equivalent update. In other words, it is the controller which is responsible for responding to user actions.
=-=-
How will you define the 3 logical layers of MVC?
The 3 logical layers of MVC can be defined as follows:
- Model logic acts as a business layer.
- View logic acts as a display layer.
- Controller logic acts as input control.
=-=-=
What are the different return types used by the controller action method in MVC?
The various return types of controller action methods in MVC are:
- View Result
- JSON Result
- Content Result
- Redirect Result
- JavaScript Result
=-=
Explain the MVC Application life cycle.
Web applications usually have 2 primary execution steps. These are:
Understanding the request.
Sending an appropriate response based on the type of request.
The same thing can be related to MVC applications also whose life cycle has 2 foremost phases:
For creating a request object.
For sending the response to any browser.
=-=--
What are the various steps to create the request object?
In order to create a request object, we have to go through 4 different steps. These are:
Step 1: Fill the route.
Step 2: Fetch the route.
Step 3: Create a request context.
Step 4: Create a controller instance.
=-=-
Explain some benefits of using MVC?
Some common benefits of MVC are:
Support of multiple views: Since there is a separation of the model from its view, the user interface (UI) gets the capability to implement multiple views of the same data concurrently.
Faster development process: MVC has the ability to provide rapid and parallel development. This means that while developing an application, it is more likely that one programmer will perform some action on the view and in parallel, another can work on creating the application’s business logic.
SEO-friendly development: The platform of MVC can support the SEO-friendly development of web pages or web applications.
More Control: The MVC framework (of ASP.NET) offers additional control over HTML, CSS and JavaScript than that of traditional WebForms.
Lightweight: MVC framework does not make use of View State which eventually minimises the requested bandwidth to some extent
=-=-=-=-=-=-=-=-
How are sessions maintained in MVC?
Sessions can be maintained in MVC in three ways:
- tempdata,
- viewdata, and
- viewbag
=-=-
What is the difference between Temp data, View data, and View Bag?
- Temp data: It helps to maintain data when you shift from one controller to another controller.
- View data: It helps to maintain data when you move from controller to view.
- View Bag: It’s a dynamic wrapper around view data
=-=-
What is Partial View in MVC?
A partial view is a chunk of HTML that can be safely inserted into an existing DOM. Most commonly, partial views are used to componentize Razor views and make them easier to build and update. It can also be returned directly from controller methods. In this case, the browser still receives text/HTML content but not necessarily HTML content that makes up an entire page. As a result, if a URL that returns a partial view is directly invoked from the address bar of a browser, an incomplete page may be displayed. This may be something like a page that misses the title, script, and style sheets.
=-=-
Explain briefly the GET and POST Action types?
The GET Action Type is implemented for requesting the data from a particular resource. Using these GET requests, a developer can pass the URL (that is compulsory).
The POST Action Type is implemented for submitting the data that needs to be handled to a certain resource. Using these POST requests, a developer can move with the URL, which is essential along with the data.
=-=
How is the routing carried out in MVC?
The RouteCollection contains a set of routes that are responsible for registering the routes in the application. The RegisterRoutes method is used for recording the routes in the collection. The URL patterns are defined by the routes and a handler is used which checks the request matching the pattern. The MVC routing has 3 parameters. The first parameter determines the name of the route. The second parameter determines a specific pattern with which the URL matches. The third parameter is responsible for providing default values for its placeholders.
-=-
What is the difference between adding routes to a webform application and an MVC application?
To add routes to a webform application, we use the MapPageRoute() method of the RouteCollection class, while for adding routes to an MVC application, we use MapRoute() method.
=-=-=
How will you navigate from one view to another view in MVC? Explain with a hyperlink example.
We will make use of the ActionLink method which will help us to navigate from one view to another. Here is an example of navigating the Home controller by invoking the Go to Home action. He is how we can code it:
<%=Html.ActionLink("Home","GoTo Home")%>
=-=-=-=
Explain the 3 concepts in one line; Temp data, View, and Viewbag?
We can briefly describe Temp data, View, and Viewbag as:
- Temp data: This is used for maintaining the data when there is a shift of work from one controller to another.
- View data: This is used for maintaining the data when we will shift from a controller to a view within an application.
- View Bag: This acts as a view data’s dynamic wrapper
=-=-=-=
Mention & explain the different approaches you will use to implement Ajax in MVC?
There are 2 different approaches to implementing Ajax in MVC. These are:
jQuery: This is a library written using JavaScript for simplifying HTML-DOM manipulation.
AJAX libraries: Asynchronous JavaScript and XML libraries are a set of web development libraries written using JavaScript and are used to perform common operations
=-=-=-=
How will you differentiate between ActionResult and ViewResult?
Some common differentiation between ActionResult and ViewResult is:
ActionResult | ViewResult |
---|---|
It becomes effective if you want to derive different types of views dynamically. | It is not so effective in deriving different types of views dynamically. |
It is an abstract class, meaning it has methods and variables without the implementation body of instruction. | This has been derived from the ActionResult class. |
JsonResult, ViewResult, and FileStreamResult are some examples of its derived class. | This class do not have its own derived class. |
=-=-=-=
How MVC works in Spring?
Here is how MVC works in Spring:
- DispatcherServlet receives a request.
- After that, the DispatcherServlet communicates with HandlerMapping. It also revokes the controller associated with that specific request.
- The Controller processes this request by calling the service methods, and a ModelAndView object is returned by the DispatcherServlet.
- The view name is sent to a ViewResolver to find the actual View to invoke.
- After that, DispatcherServlet is passed to View to render the result.
- By using the model data, the View renders and sends back result back to the user.
=-=-=-=
What is the use of Keep and Peek in “TempData”?
Once “TempData” is read in the current request, it’s not available in the subsequent request. If we want “TempData” to be read and also available in the subsequent request then after reading we need to call “Keep” method as shown in the code below.
1 2 | @TempData["MyData"]; TempData.Keep("MyData"); |
The more shortcut way of achieving the same is by using “Peek”. This function helps to read as well advices MVC to maintain “TempData” for the subsequent request.
1 | string str = TempData.Peek("Td").ToString(); |
=-=-=-=
Define Output Caching in MVC?
Output Caching is an approach used for improving the performance of an MVC application. It is used for enabling its users to cache the data sent back by the controller method so that the data used earlier does not get generated each time while invoking the same controller method. It has advantages to using Output Caching as it cuts down database server round trips, minimizes server round trips as well as reduces the network traffic
=-=-=-=
How is JSON response returned from the Action method?
To return the JSON response Action method, we need to return the JsonResult object. This object calls the Json helper method. The given an example returns a response in JSON format:
public JsonResult sample()
{
string send = "hello";
return Json(send, JsonRequestBehavior.AllowGet);
}
=-=-=-=
What is Partial View in MVC?
A partial view is a chunk of HTML that can be safely inserted into an existing DOM. Most commonly, partial views are used to componentize Razor views and make them easier to build and update. It can also be returned directly from controller methods. In this case, the browser still receives text/HTML content but not necessarily HTML content that makes up an entire page. As a result, if a URL that returns a partial view is directly invoked from the address bar of a browser, an incomplete page may be displayed. This may be something like a page that misses title, script and style sheets.
=-=-=-=
Make a differentiation between View and Partial View?
The major differentiation between View and Partial View is as follows:
View | Partial View |
---|---|
The view is not as lightweight as that of the Partial view. | Partial view, as the name suggests, is lightweight than View. |
The view has its own layout page. | The partial view does not have its own layout page. |
The Viewstart page is rendered just before rendering any view. | A partial view is designed particularly for rendering within the view. |
The view can have markup tags of HTML such as HTML, head, body, title, meta, etc. | The partial view does not contain any markup. |
=-=-=-=
How to perform Exception Handling in MVC?
In the controller, you can override the “OnException” event and set the “Result” to the view name which you want to invoke when an error occurs. In the below code you can see we have set the “Result” to a view named as “Error”.
We have also set the exception so that it can be displayed inside the view.
1 2 3 4 5 6 7 8 9 10 11 12 | public class HomeController : Controller{ protected override void OnException(ExceptionContext filterContext){ Exception ex = filterContext.Exception; filterContext.ExceptionHandled = true ; var model = new HandleErrorInfo(filterContext.Exception, "Controller" , "Action" ); filterContext.Result = new ViewResult() { ViewName = "Error" , ViewData = new ViewDataDictionary(model) }; } } |
=-=-=-=
What do you mean by MVC Scaffolding?
Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio includes pre-installed code generators for MVC and Web API projects. You add scaffolding to your project when you want to quickly add the code that interacts with data models. Using scaffolding can reduce the amount of time to develop standard data operations in your project.
It consists of page templates, entity page templates, field page templates, and filter templates. These templates are called Scaffold templates and they allow you to quickly build a functional data-driven Website
=-=-=-=
What is ViewStart?
A new layout called _ViewStart is introduced by the Razor View Engine that is applied to all views automatically. ViewStart is executed at the very beginning followed by the start rendering as well as other views.
Example:
@ {
Layout = "~/ Views/ Shared/ _
file.cshtml";
}
<html>
<head>
<meta name="viewport" />
<title> InitialView </title> </head>
<body> ….
</body>
</html>
=-=-=-=
Mention the possible file extensions used for razor views?
The different file extensions that are used by razor views are:
- .cshtml: When your MVC application is using C# as the programming language.
- .vbhtml: When your MVC application is using VB is the programming language
=-=-=-=
Explain briefly the two approaches of adding constraints to an MVC route?
For adding constraints to an MVC route, the 2 different approaches are:
- By making use of regular expressions.
- By making use of objects that implement the “IRouteConstraint” interface
Define Default Route in MVC?
The default Route of project templates in MVC includes a generic route that makes use of the given URL resolution for breaking the URL based on the request into 3 tagged segments. URL: “{controller} / {action} / {id}”
How can you implement the MVC forms authentication?
Authentication in forms is added in order to include a layer of security to access the user for a specific service. This authentication is done by verifying the user’s identity through the credentials such as username with password or email with a password.
The code snippet will look something like this:
<system.web>
<authentication mode = "Forms" >
<formsloginUrl = "Login.aspx" protection = "All" timeout = "30" name = ".ASPXAUTH" path = "/" requireSSL = "false" defaultUrl = "default.aspx" cookieless = "UseDeviceProfile" />
</authentication>
</system.web>
How will you explain the concept of RenderBody and RenderPage of MVC?
RenderBody can be considered as a ContentPlaceHolder of web forms. It is available on the layout page and will be responsible for rendering the child pages/views. On the other hand, the layout page contains a single RenderBody() method. Multiple RenderPage() can reside within the Layout page
How does View Data differ from View Bag in MVC?
View Data | View Bag |
ViewData is used to pass data from a controller to view | ViewBag is also used to pass data from the controller to the respective view. |
It is available for the current request only. | It is also available for the current request only. |
Requires typecasting for complex data types and checks for null values to avoid error | Doesn’t require typecasting for the complex data type. |
If redirection occurs, then its value becomes null. | If redirection occurs, then its value becomes null |
Explain the concept of Razor in ASP.NET MVC?
ASP.NET MVC has always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options. The “default” view engine for ASP.NET MVC uses the same .aspx/.ascx/. master file templates as ASP.NET WebForms. Other popular ASP.NET MVC view engines are Spart & Nhaml. Razor is the new view-engine introduced by MVC 3
What is Database first approach in MVC using Entity Framework?
Database First Approach is an alternative or substitutes to the Code First and Model First approaches to the Entity Data Model. The Entity Data Model creates model codes (classes, properties, DbContext, etc.) from the database in the project and that class behaves as the link between the database and controller.
There are the following approaches, that are used to connect the database with the application.
- Database First
- Model First
- Code First
What is MVC Routing?
The URLs in ASP.NET MVC are mapped to action methods and controllers instead of physical files of the system. To accurately map action methods and controllers to URLs, the routing engine forms appropriate routes. Using this, the controllers can handle specific requests.
What is the difference between 3-tier Architecture and MVC Architecture?
Here is a difference between 3-tier Architecture and MVC Architecture:
Parameter | 3-Tier Architecture | MVC Architecture |
---|---|---|
Communication | This type of architecture pattern never communicates directly with the data layer. | All layers communicate directly using triangle topology. |
Usage | 3-tier: widely used in web applications where the client, data tiers, and middleware run on physically separate platforms. | Generally used on applications that run on a single graphical workstation. |
What is the difference between Web Forms and MVC?
Here is a difference between Web Forms and MVC:
Parameters | Web Forms | MVC |
---|---|---|
Model | Asp.Net Web Forms follow event-driven development model. | Asp.Net MVC uses MVC pattern-based development model. |
Used Since | Been around since 2002 | It was first released in 2009 |
Support for View state | Asp.Net Web Forms supports view state for state management at the client-side. | .Net MVC doesn’t support view state. |
URL type | Asp.Net Web Forms has file-based URLs. It means file name exists in the URLs, and they must exist physically. | Asp.Net MVC has route-based URLs that means URLs are redirected to controllers and actions. |
Syntax | Asp.Net MVC follows Web Forms Syntax. | Asp.Net MVC follows the customizable syntax. |
View type | Web Forms views are tightly coupled to Code behind(ASPX-CS), i.e., logic. | MVC Views and logic are always kept separately. |
Consistent look and feels | It has master pages for a consistent look. | Asp.Net MVC has layouts for a consistent look. |
Code Reusability | Web Forms offers User controls for code re-usability. | Asp.Net MVC offers partial views for code re-usability. |
Control for HTML | Less control over rendered HTML. | Full control over HTML |
State management | Automatic state management of controls. | Manual state management. |
TDD support | Weak or custom TDD required. | Encourages and includes TDD! |
What is the main difference between MVC and WebAPI?
Here is the main difference between MVC and WebAPI:
MVC framework is used for developing applications that have a User Interface. For that, views can be used for building a user interface.
WebAPI is used for developing HTTP services. Other apps can also be called the WebAPI methods to fetch that data.
https://www.guru99.com/mvc-interview-questions.html
=--==--==--=
What is the purpose of using OOPs concepts?
The aim of OOP is to implement real-world entities like inheritance, hiding, and polymorphism in programming. The main purpose of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
=--==--==--=
What are the four main features of OOPs?
The OOP has the following four features:
- Inheritance
- Encapsulation
- Polymorphism
- Data Abstraction
=--==--==--=
Why OOP is so popular?
OOPs, programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs - Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular.
=--==--==--=
What do you understand by class and object? Also, give example.
Class: A class is a blueprint or template of an object. It is a user-defined data type. Inside a class, we define variables, constants, member functions, and other functionality. It does not consume memory at run time. Note that classes are not considered as a data structure. It is a logical entity. It is the best example of data binding.
Object: An object is a real-world entity that has attributes, behavior, and properties. It is referred to as an instance of the class. It contains member functions, variables that we have defined in the class. It occupies space in the memory. Different objects have different states or attributes, and behaviors.
The following figure best illustrates the class and object.
=--==--==--=
What are the differences between class and object?
Class | Object |
---|---|
It is a logical entity. | It is a real-world entity. |
It is conceptual. | It is real. |
It binds data and methods together into a single unit. | It is just like a variable of a class. |
It does not occupy space in the memory. | It occupies space in the memory. |
It is a data type that represents the blueprint of an object. | It is an instance of the class. |
It is declared once. | Multiple objects can be declared as and when required. |
It uses the keyword class when declared. | It uses the new keyword to create an object. |
A class can exist without any object. | Objects cannot exist without a class. |
=--==--==--=
What are the key differences between class and structure?
Class | Structure |
---|---|
Class is a group of common objects that shares common properties. | The structure is a collection of different data types. |
It deals with data members and member functions. | It deals with data members only. |
It supports inheritance. | It does not support inheritance. |
Member variables cannot be initialized directly. | Member variables can be initialized directly. |
It is of type reference. | It is of a type value. |
It's members are private by default. | It's members are public by default. |
The keyword class defines a class. | The keyword struct defines a structure. |
An instance of a class is an object. | An instance of a structure is a structure variable. |
Useful while dealing with the complex data structure. | Useful while dealing with the small data structure. |
=--==--==--=
What is the concept of access specifiers when should we use these?
In OOPs language, access specifiers are reserved keyword that is used to set the accessibility of the classes, methods, and other members of the class. It is also known as access modifiers. It includes public, private, and protected. There is some other access specifier that is language-specific. Such as Java has another access specifier default. These access specifiers play a vital role in achieving one of the major functions of OOP, i.e. encapsulation. The following table depicts the accessibility.
=--==--==--=
What are the differences between the constructor and the method in Java?
Constructor | Method |
---|---|
Constructor has the same name as the class name. | The method name and class name are not the same. |
It is a special type of method that is used to initialize an object of its class. | It is a set of instructions that can be invoked at any point in a program. |
It creates an instance of a class. | It is used to execute Java code. |
It is invoked implicitly when we create an object of the class. | It gets executed when we explicitly called it. |
It cannot be inherited by the subclass. | It can be inherited by the subclass. |
It does not have any return type. | It must have a return type. |
It cannot be overridden in Java. | It can be overridden in Java. |
It cannot be declared as static. | It can be declared as static. |
Java compiler automatically provides a default constructor. | Java compiler does not provide any method by default. |
=--==--==--=
What are the differences between error and exception?
Basis of Comparison | Exception | Error |
---|---|---|
Recoverable/ Irrecoverable | Exception can be recovered by using the try-catch block. | An error cannot be recovered. |
Type | It can be classified into two categories i.e. checked and unchecked. | All errors in Java are unchecked. |
Occurrence | It occurs at compile time or run time. | It occurs at run time. |
Package | It belongs to java.lang.Exception package. | It belongs to java.lang.Error package. |
Known or unknown | Only checked exceptions are known to the compiler. | Errors will not be known to the compiler. |
Causes | It is mainly caused by the application itself. | It is mostly caused by the environment in which the application is running. |
Example | Checked Exceptions: SQLException, IOException Unchecked Exceptions: ArrayIndexOutOfBoundException, NullPointerException, ArithmaticException | Java.lang.StackOverFlow, java.lang.OutOfMemoryError |
=--==--==--=
What are the limitations of inheritance?
- The main disadvantage of using inheritance is two classes get tightly coupled. That means one cannot be used independently of the other. If a method or aggregate is deleted in the Super Class, we have to refactor using that method in SubClass.
- Inherited functions work slower compared to normal functions.
- Need careful implementation otherwise leads to improper solutions.
=--==--==--=
What are the differences between Inheritance and Polymorphism?
Inheritance | Polymorphism |
---|---|
Inheritance is one in which a derived class inherits the already existing class's features. | Polymorphism is one that you can define in different forms. |
It refers to using the structure and behavior of a superclass in a subclass. | It refers to changing the behavior of a superclass in the subclass. |
It is required in order to achieve polymorphism. | In order to achieve polymorphism, inherence is not required. |
It is applied to classes. | It is applied to functions and methods. |
It can be single, hybrid, multiple, hierarchical, multipath, and multilevel inheritance. | There are two types of polymorphism compile time and run time. |
It supports code reusability and reduces lines of code. | It allows the object to decide which form of the function to be invoked at run-time (overriding) and compile-time (overloading). |
=--==--==--=
Name the operators that cannot be overload.
- Scope Resolution Operator (::)
- Ternary Operator (? :)
- Member Access or Dot Operator (.)
- Pointer to Member Operator (.*)
- sizeof operator
=--==--==--=
What is the difference between new and override?
The new modifier instructs the compiler to use the new implementation instead of the base class function. Whereas, Override modifier helps to override the base class function.
virtual: indicates that a method may be overridden by an inheritor
override: Overrides the functionality of a virtual method in a base class, providing different functionality.
new: Hides the original method (which doesn't have to be virtual), providing different functionality. This should only be used where it is absolutely necessary.
When you hide a method, you can still access the original method by upcasting to the base class. This is useful in some scenarios, but dangerous.
=--==--==--=
Explain overloading and overriding with example?
Overloading
Overloading is a concept in OOP when two or more methods in a class with the same name but the method signature is different. It is also known as compile-time polymorphism. For example, in the following code snippet, the method add() is an overloaded method.
Overriding
If a method with the same method signature is presented in both child and parent class is known as method overriding. The methods must have the same number of parameters and the same type of parameter. It overrides the value of the parent class method. It is also known as runtime polymorphism. For example, consider the following program.
32) What is Cohesion in OOP?
In OOP, cohesion refers to the degree to which the elements inside a module belong together. It measures the strength of the relationship between the module and data. In short, cohesion represents the clarity of the responsibilities of a module. It is often contrasted with coupling.
It focuses on a how single module or class is intended. The higher the cohesiveness of the module or class, the better the object-oriented design.
There are two types of cohesion, i.e. High and Low.
- High cohesion is associated with several required qualities of software including robustness, reliability, and understandability.
- Low cohesion is associated with unwanted qualities such as being difficult to maintain, test, reuse, or even understand.
High cohesion often associates with loose coupling and vice versa.
=--==--==--=
Give a real-world example of polymorphism?
The general meaning of Polymorphism is one that has different forms. The best real-world example of polymorphism is a person that plays different roles at different palaces or situations.
- At home a person can play the role of father, husband, and son.
- At the office the same person plays the role of boss or employee.
- In public transport, he plays the role of passenger.
- In the hospital, he can play the role of doctor or patient.
- At the shop, he plays the role of customer.
Hence, the same person possesses different behavior in different situations. It is called polymorphism.
=--==--==--=
What is the need for OOPs?
There are many reasons why OOPs is mostly preferred, but the most important among them are:
- OOPs helps users to understand the software easily, although they don’t know the actual implementation.
- With OOPs, the readability, understandability, and maintainability of the code increase multifold.
- Even very big software can be easily written and managed easily using OOPs
=--==--==--=
Why is OOPs so popular?
OOPs programming paradigm is considered as a better style of programming. Not only it helps in writing a complex piece of code easily, but it also allows users to handle and maintain them easily as well. Not only that, the main pillar of OOPs - Data Abstraction, Encapsulation, Inheritance, and Polymorphism, makes it easy for programmers to solve complex scenarios. As a result of these, OOPs is so popular.
=--==--==--=
What is a class?
A class can be understood as a template or a blueprint, which contains some values, known as member data or member, and some set of rules, known as behaviors or functions. So when an object is created, it automatically takes the data and functions that are defined in the class.
Therefore the class is basically a template or blueprint for objects. Also one can create as many objects as they want based on a class.
For example, first, a car’s template is created. Then multiple units of car are created based on that template.
10. What is an object?
An object refers to the instance of the class, which contains the instance of the members and behaviors defined in the class template. In the real world, an object is an actual entity to which a user interacts, whereas class is just the blueprint for that object. So the objects consume space and have some characteristic behavior.
For example, a specific car.
11. What is encapsulation?
One can visualize Encapsulation as the method of putting everything that is required to do the job, inside a capsule and presenting that capsule to the user. What it means is that by Encapsulation, all the necessary data and methods are bind together and all the unnecessary details are hidden to the normal user. So Encapsulation is the process of binding data members and methods of a program together to do a specific job, without revealing unnecessary details.
Encapsulation can also be defined in two different ways:
1) Data hiding: Encapsulation is the process of hiding unwanted information, such as restricting access to any member of an object.
2) Data binding: Encapsulation is the process of binding the data members and the methods together as a whole, as a class.
12. What is Polymorphism?
Polymorphism is composed of two words - “poly” which means “many”, and “morph” which means “shapes”. Therefore Polymorphism refers to something that has many shapes.
In OOPs, Polymorphism refers to the process by which some code, data, method, or object behaves differently under different circumstances or contexts. Compile-time polymorphism and Run time polymorphism are the two types of polymorphisms in OOPs languages
=--==--==--=
What is meant by Inheritance?
The term “inheritance” means “receiving some quality or behavior from a parent to an offspring.” In object-oriented programming, inheritance is the mechanism by which an object or class (referred to as a child) is created using the definition of another object or class (referred to as a parent). Inheritance not only helps to keep the implementation simpler but also helps to facilitate code reuse
=--==--==--=
What is Abstraction?
If you are a user, and you have a problem statement, you don't want to know how the components of the software work, or how it's made. You only want to know how the software solves your problem. Abstraction is the method of hiding unnecessary details from the necessary ones. It is one of the main features of OOPs.
For example, consider a car. You only need to know how to run a car, and note how the wires are connected inside it. This is obtained using Abstraction
=--==--==--=
What is a constructor?
Constructors are special methods whose name is the same as the class name. The constructors serve the special purpose of initializing the objects.
For example, suppose there is a class with the name “MyClass”, then when you instantiate this class, you pass the syntax:MyClass myClassObject = new MyClass();
Now here, the method called after the “new” keyword - MyClass(), is the constructor of this class. This will help to instantiate the member data and methods and assign them to the object myClassObject.
=--==--==--=
Explain Inheritance with an example?
Inheritance is one of the major features of object-oriented programming, by which an entity inherits some characteristics and behaviors of some other entity and makes them their own. Inheritance helps to improve and facilitate code reuse.
Let me explain to you with a common example. Let's take three different vehicles - a car, truck, or bus. These three are entirely different from one another with their own specific characteristics and behavior. But. in all three, you will find some common elements, like steering wheel, accelerator, clutch, brakes, etc. Though these elements are used in different vehicles, still they have their own features which are common among all vehicles. This is achieved with inheritance. The car, the truck, and the bus have all inherited the features like steering wheel, accelerator, clutch, brakes, etc, and used them as their own. Due to this, they did not have to create these components from scratch, thereby facilitating code reuse.
=--==--==--=
What are the various types of inheritance?
The various types of inheritance include:
- Single inheritance
- Multiple inheritances
- Multi-level inheritance
- Hierarchical inheritance
- Hybrid inheritance
=--==--==--=
What is a subclass?
The subclass is a part of Inheritance. The subclass is an entity, which inherits from another class. It is also known as the child class
=--==--==--=
Define a superclass?
Superclass is also a part of Inheritance. The superclass is an entity, which allows subclasses or child classes to inherit from itself.
What is meant by static polymorphism?
Static Polymorphism is commonly known as the Compile time polymorphism. Static polymorphism is the feature by which an object is linked with the respective function or operator based on the values during the compile time. Static or Compile time Polymorphism can be achieved through Method overloading or operator overloading
What is meant by dynamic polymorphism?
Dynamic Polymorphism or Runtime polymorphism refers to the type of Polymorphism in OOPs, by which the actual implementation of the function is decided during the runtime or execution. The dynamic or runtime polymorphism can be achieved with the help of method overriding
What is the difference between overloading and overriding?
Overloading is a compile-time polymorphism feature in which an entity has multiple implementations with the same name. For Examples, Method overloading and Operator overloading.
Whereas Overriding is a runtime polymorphism feature in which an entity has the same name, but its implementation changes during execution. For example, Method overriding
What is an abstract class?
An abstract class is a special class containing abstract methods. The significance of abstract class is that the abstract methods inside it are not implemented and only declared. So as a result, when a subclass inherits the abstract class and needs to use its abstract methods, they need to define and implement them
What is meant by exception handling?
No one wants its software to fail or crash. Exceptions are the major reason for software failure. The exceptions can be handled in the program beforehand and prevent the execution from stopping. This is known as exception handling.
So exception handling is the mechanism for identifying the undesirable states that the program can reach and specifying the desirable outcomes of such states.
Try-catch is the most common method used for handling exceptions in the program
============
What is SQL?
SQL stands for the Structured Query Language. It is the standard language used to maintain the relational database and perform many different data manipulation operations on the data. SQL was initially invented in 1970. It is a database language used for database creation, deletion, fetching and modifying rows, etc. sometimes, it is pronounced as 'sequel.' We can also use it to handle organized data comprised of entities (variables) and relations between different entities of the data
What are the subsets of SQL?
The following are the four significant subsets of the SQL:
- Data definition language (DDL): It defines the data structure that consists of commands like CREATE, ALTER, DROP, etc.
- Data manipulation language (DML): It is used to manipulate existing data in the database. The commands in this category are SELECT, UPDATE, INSERT, etc.
- Data control language (DCL): It controls access to the data stored in the database. The commands in this category include GRANT and REVOKE.
- Transaction Control Language (TCL): It is used to deal with the transaction operations in the database. The commands in this category are COMMIT, ROLLBACK, SET TRANSACTION, SAVEPOINT, etc.
What is the purpose of DDL Language?
DDL stands for Data definition language. It is the subset of a database that defines the data structure of the database when the database is created. For example, we can use the DDL commands to add, remove, or modify tables. It consists of the following commands: CREATE, ALTER and DELETE database objects such as schema, tables, indexes, view, sequence, etc
What is the purpose of DML Language?
Data manipulation language makes the user able to retrieve and manipulate data in a relational database. The DML commands can only perform read-only operations on data. We can perform the following operations using DDL language:
- Insert data into the database through the INSERT command.
- Retrieve data from the database through the SELECT command.
- Update data in the database through the UPDATE command.
- Delete data from the database through the DELETE command
What are tables and fields in the database?
A table is a set of organized data in the form of rows and columns. It enables users to store and display records in the structure format. It is similar to worksheets in the spreadsheet application. Here rows refer to the tuples, representing the simple data item, and columns are the attribute of the data items present in a particular row. Columns can categorize as vertical, and Rows are horizontal.
Fields are the components to provide the structure for the table. It stores the same category of data in the same data type. A table contains a fixed number of columns but can have any number of rows known as the record. It is also called a column in the table of the database. It represents the attribute or characteristics of the entity in the record.
Example
Table: Student
Field: Stud_rollno, Stud_name, Date of Birth, Branch, etc.
What is a primary key?
A primary key is a field or the combination of fields that uniquely identify each record in the table. It is one of a special kind of unique key. If the column contains a primary key, it cannot be null or empty. A table can have duplicate columns, but it cannot have more than one primary key. It always stores unique values into a column. For example, the ROLL Number can be treated as the primary key for a student in the university or college.
We can define a primary key into a student table as follows:
What is a foreign key?
The foreign key is used to link one or more tables together. It is also known as the referencing key. A foreign key is specified as a key that is related to the primary key of another table. It means a foreign key field in one table refers to the primary key field of the other table. It identifies each row of another table uniquely that maintains the referential integrity. The primary key-foreign key relationship is a very crucial relationship as it maintains the ACID properties of the database sometimes. It also prevents actions that would destroy links between the child and parent tables.
We can define a foreign key into a table as follows:
What is a unique key?
A unique key is a single or combination of fields that ensure all values stores in the column will be unique. It means a column cannot stores duplicate values. This key provides uniqueness for the column or set of columns. For example, the email addresses and roll numbers of student's tables should be unique. It can accept a null value but only one null value per column. It ensures the integrity of the column or group of columns to store different values into a table.
We can define a foreign key into a table as follows:
What is the difference between a primary key and a unique key?
The primary key and unique key both are essential constraints of the SQL. The main difference among them is that the primary key identifies each record in the table. In contrast, the unique key prevents duplicate entries in a column except for a NULL value. The following comparison chart explains it more clearly:
Primary Key | Unique Key |
---|---|
The primary key act as a unique identifier for each record in the table. | The unique key is also a unique identifier for records when the primary key is not present in the table. |
We cannot store NULL values in the primary key column. | We can store NULL value in the unique key column, but only one NULL is allowed. |
We cannot change or delete the primary key column values. | We can modify the unique key column values. |
What is a view in SQL?
A view is a database object that has no values. It is a virtual table that contains a subset of data within a table. It looks like an actual table containing rows and columns, but it takes less space because it is not present physically. It is operated similarly to the base table but does not contain any data of its own. Its name is always unique. A view can have data from one or more tables. If any changes occur in the underlying table, the same changes reflected in the views also.
The primary use of a view is to implement the security mechanism. It is the searchable object where we can use a query to search the view as we use for the table. It only shows the data returned by the query that was declared when the view was created.
We can create a view by using the following syntax:
What is an Index in SQL?
An index is a disc structure associated with a table or view that speeds up row retrieval. It reduces the cost of the query because the query's high cost will lead to a fall in its performance. It is used to increase the performance and allow faster retrieval of records from the table. Indexing reduces the number of data pages we need to visit to find a particular data page. It also has a unique value meaning that the index cannot be duplicated. An index creates an entry for each value which makes it faster to retrieve data.
For example: Suppose we have a book which carries the details of the countries. If you want to find out information about India, why will you go through every page of that book? You could directly go to the index. Then from the index, you can go to that particular page where all the information about India is given.
What are the differences between SQL, MySQL, and SQL Server?
The following comparison chart explains their main differences:
SQL | MySQL | SQL Server |
---|---|---|
SQL or Structured Query Language is useful for managing our relational databases. It is used to query and operate the database. | MySQL is the popular database management system used for managing the relational database. It is a fast, scalable, and easy-to-use database. | SQL Server is an RDBMS database system mainly developed for the Windows system to store, retrieve, and access data requested by the developer. |
SQL first appeared in 1974. | MySQL first appeared on May 23, 1995. | SQL Server first appeared on April 24, 1989. |
SQL was developed by IBM Corporation. | MySQL was developed by Oracle Corporation. | SQL Server was developed by Microsoft Company. |
SQL is a query language for managing databases. | MySQL is database software that uses SQL language to conduct with the database. | SQL Server is also a software that uses SQL language to conduct with the database. |
SQL has no variables. | MySQL can use variables constraints and data types. | SQL Server can use variables constraints and data types. |
SQL is a programming language, so that it does not get any updates. Its commands are always fixed and remain the same. | MySQL is software, so it gets frequent updation. | SQL Server is also software, so it gets frequent updation. |
What is the difference between SQL and PL/SQL?
The following comparison chart explains their main differences:
SQL | PL/SQL |
---|---|
SQL is a database structured query language used to communicate with relational databases. It was developed by IBM Corporations and first appeared in 1974. | PL/SQL or Procedural Language/Structured Query Language is a dialect of SQL used to enhance the capabilities of SQL. Oracle Corporation developed it in the early 90's. It uses SQL as its database language. |
SQL is a declarative and data-oriented language. | PL/SQL is a procedural and application-oriented language. |
SQL has no variables. | PL/SQL can use variables constraints and data types. |
SQL can execute only a single query at a time. | PL/SQL can execute a whole block of code at once. |
SQL query can be embedded in PL/SQL. | PL/SQL cannot be embedded in SQL as SQL does not support any programming language and keywords. |
SQL can directly interact with the database server. | PL/SQL cannot directly interact with the database server. |
SQL is like the source of data that we need to display. | PL/SQL provides a platform where SQL data will be shown. |
What is the SQL query to display the current date?
There is a built-in function in SQL called GetDate(), which is used to return the current timestamp
What is the difference between IN and BETWEEN operators?
The following comparison chart explains their main differences:
BETWEEN Operator | IN Operator |
---|---|
This operator is used to selects the range of data between two values. The values can be numbers, text, and dates as well. | It is a logical operator to determine whether or not a specific value exists within a set of values. This operator reduces the use of multiple OR conditions with the query. |
It returns records whose column value lies in between the defined range. | It compares the specified column's value and returns the records when the match exists in the set of values. |
The following syntax illustrates this operator: SELECT * FROM table_name WHERE column_name BETWEEN 'value1' AND 'value2'; | The following syntax illustrates this operator: SELECT * FROM table_name WHERE column_name IN ('value1','value 2'); |
What is the difference between DELETE and TRUNCATE statements in SQL?
The main difference between them is that the delete statement deletes data without resetting a table's identity, whereas the truncate command resets a particular table's identity. The following comparison chart explains it more clearly:
No. | DELETE | TRUNCATE |
---|---|---|
1) | The delete statement removes single or multiple rows from an existing table depending on the specified condition. | The truncate command deletes the whole contents of an existing table without the table itself. It preserves the table structure or schema. |
2) | DELETE is a DML command. | TRUNCATE is a DML command. |
3) | We can use the WHERE clause in the DELETE command. | We cannot use the WHERE clause with TRUNCATE. |
4) | DELETE statement is used to delete a row from a table. | TRUNCATE statement is used to remove all the rows from a table. |
5) | DELETE is slower because it maintained the log. | TRUNCATE statement is faster than DELETE statement as it deletes entire data at a time without maintaining transaction logs. |
6) | You can roll back data after using the DELETE statement. | It is not possible to roll back after using the TRUNCATE statement. |
7) | DELETE query takes more space. | TRUNCATE query occupies less space. |
What is the difference between the WHERE and HAVING clauses?
The main difference is that the WHERE clause is used to filter records before any groupings are established, whereas the HAVING clause is used to filter values from a group. The below comparison chart explains the most common differences:
WHERE | HAVING |
---|---|
This clause is implemented in row operations. | This clause is implemented in column operations. |
It does not allow to work with aggregate functions. | It can work with aggregate functions. |
This clause can be used with the SELECT, UPDATE, and DELETE statements. | This clause can only be used with the SELECT statement. |
How many Aggregate functions are available in SQL?
The aggregate function is used to determine and calculate several values in a table and return the result as a single number. For example, the average of all values, the sum of all values, and the maximum and minimum value among particular groupings of values.
The following syntax illustrates how to use aggregate functions:
SQL provides seven (7) aggregate functions, which are given below:
- AVG(): This function is used to returns the average value from specified columns.
- COUNT(): This function is used to returns the number of table rows, including rows with null values.
- MAX(): This function is used to returns the largest value among the group.
- MIN(): This function is used to returns the smallest value among the group.
- SUM(): This function is used to returns the total summed values(non-null) of the specified column.
- FIRST(): This function is used to returns the first value of an expression.
- LAST(): This function is used to returns the last value of an expression.
What is SQL Injection?
SQL injection is a type of vulnerability in website and web app code that allows attackers to control back-end operations and access, retrieve, and destroy sensitive data from databases. In this technique, malicious SQL statements are inserted into a database entry field, and once they are performed, the database becomes vulnerable to an attacker. This technique is commonly used to access sensitive data and perform administrative activities on databases by exploiting data-driven applications. It is also known as SQLi attack.
Some common examples of SQL injection are:
- Accessing confidential data to modify an SQL query to get desired results.
- UNION attacks to steal data from different database tables.
- Examine the database to extract information regarding the version and structure of the database.
What are SQL comments?
Comments are explanations or annotations in SQL queries that are readable by programmers. It's used to make SQL statements easier to understand for humans. During the parsing of SQL code, it will be ignored. Comments can be written on a single line or across several lines.
- Single Line Comments: It starts with two consecutive hyphens (--).
- Multi-line Comments: It starts with /* and ends with */.
@mesameegaikwad
Object-Oriented Programming is one of the main concepts in the programming world, therefore, every interview that you attend requires knowledge of OOPs. This article compiles the most frequently asked OOPs Interview Questions for freshers which will help you ace your interviews. So go ahead and get prepared.
Let’s take a quick look at all the topics of discussion:
- Basic OOPs Interview Questions
- OOPs Interview Questions Classes and Objects
- Interview Questions on Features of OOPs
- Inheritance
- Polymorphism
- Encapsulation
- Data abstraction
- Methods and functions Interview Questions
- Exception handling Interview Questions
- Limitations of OOPs
OOPs Interview Questions
- What is the difference between OOP and SOP?
- What is OOPs?
- Why use OOPs?
- What are the main features of OOPs?
- What is an object?
- What is a class?
- What is the difference between a class and a structure?
- Can you call the base class method without creating an instance?
- What is the difference between a class and an object?
- What is inheritance?
Basic OOPs Interview Questions for Freshers
1. What is the difference between OOP and SOP?
2. What is Object-Oriented Programming?
Object-Oriented Programming(OOPs) is a type of programming that is based on objects rather than just functions and procedures. Individual objects are grouped into classes. OOPs implements real-world entities like inheritance, polymorphism, hiding, etc into programming. It also allows binding data and code together.
3. Why use OOPs?
- OOPs allows clarity in programming thereby allowing simplicity in solving complex problems
- Code can be reused through inheritance thereby reducing redundancy
- Data and code are bound together by encapsulation
- OOPs allows data hiding, therefore, private data is kept confidential
- Problems can be divided into different parts making it simple to solve
- The concept of polymorphism gives flexibility to the program by allowing the entities to have multiple forms
4. What are the main features of OOPs?
To know more about OOPs in JAVA, Python, and C++ you can go through the following blogs:
Classes and Objects OOPs Interview Questions and Answers
5. What is an object?
An object is a real-world entity which is the basic unit of OOPs for example chair, cat, dog, etc. Different objects have different states or attributes, and behaviors.
6. What is a class?
A class is a prototype that consists of objects in different states and with different behaviors. It has a number of methods that are common the objects present within that class.
7. What is the difference between a class and a structure?
Class: User-defined blueprint from which objects are created. It consists of methods or set of instructions that are to be performed on the objects.
Structure: A structure is basically a user-defined collection of variables which are of different data types.
8. Can you call the base class method without creating an instance?
Yes, you can call the base class without instantiating it if:
- It is a static method
- The base class is inherited by some other subclass
9. What is the difference between a class and an object?
To know more about objects and classes in JAVA, Python, and C++ you can go through the following blogs:
- Objects in Java
- Class in Java
- Objects and classes in Python
- Objects in C++
OOPs Interview Questions – Inheritance
10. What is inheritance?
Inheritance is a feature of OOPs which allows classes inherit common properties from other classes. For example, if there is a class such as ‘vehicle’, other classes like ‘car’, ‘bike’, etc can inherit common properties from the vehicle class. This property helps you get rid of redundant code thereby reducing the overall size of the code.
11. What are the different types of inheritance?
- Single inheritance
- Multiple inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Hybrid inheritance
12. What is the difference between multiple and multilevel inheritance?
Multiple Inheritance | Multilevel Inheritance |
Multiple inheritance comes into picture when a class inherits more than one base class | Multilevel inheritance means a class inherits from another class which itself is a subclass of some other base class |
Example: A class defining a child inherits from two base classes Mother and Father | Example: A class describing a sports car will inherit from a base class Car which inturn inherits another class Vehicle |
13. What is hybrid inheritance?
Hybrid inheritance is a combination of multiple and multi-level inheritance.
14. What is hierarchical inheritance?
Hierarchical inheritance refers to inheritance where one base class has more than one subclasses. For example, the vehicle class can have ‘car’, ‘bike’, etc as its subclasses.
15. What are the limitations of inheritance?
- Increases the time and effort required to execute a program as it requires jumping back and forth between different classes
- The parent class and the child class get tightly coupled
- Any modifications to the program would require changes both in the parent as well as the child class
- Needs careful implementation else would lead to incorrect results
To know more about inheritance in Java and Python, read the below articles:
- Inheritance in Java
- Inheritance in Python
16. What is a superclass?
A superclass or base class is a class that acts as a parent to some other class or classes. For example, the Vehicle class is a superclass of class Car.
17. What is a subclass?
A class that inherits from another class is called the subclass. For example, the class Car is a subclass or a derived of Vehicle class.
OOPs Interview Questions – Polymorphism
18. What is polymorphism?
Polymorphism refers to the ability to exist in multiple forms. Multiple definitions can be given to a single interface. For example, if you have a class named Vehicle, it can have a method named speed but you cannot define it because different vehicles have different speed. This method will be defined in the subclasses with different definitions for different vehicles.
19. What is static polymorphism?
Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time. An example of compile-time polymorphism is method overloading.
20. What is dynamic polymorphism?
Runtime polymorphism or dynamic polymorphism (dynamic binding) is a type of polymorphism which is resolved during runtime. An example of runtime polymorphism is method overriding.
21. What is method overloading?
Method overloading is a feature of OOPs which makes it possible to give the same name to more than one method within a class if the arguments passed differ.
22. What is method overriding?
Method overriding is a feature of OOPs by which the child class or the subclass can redefine methods present in the base class or parent class. Here, the method that is overridden has the same name as well as the signature meaning the arguments passed and the return type.
23. What is operator overloading?
Operator overloading refers to implementing operators using user-defined types based on the arguments passed along with it.
24. Differentiate between overloading and overriding.
Overloading | Overriding |
Two or more methods having the same name but different parameters or signature | Child class redefining methods present in the base class with the same parameters/ signature |
Resolved during compile-time | Resolved during runtime |
To know more about polymorphism in Java and Python, read the below articles:
- Polymorphism in Java
- Polymorphism in Python
OOPs Interview Questions – Encapsulation
25. What is encapsulation?
Encapsulation refers to binding the data and the code that works on that together in a single unit. For example, a class. Encapsulation also allows data-hiding as the data specified in one class is hidden from other classes.
26. What are ‘access specifiers’?
Access specifiers or access modifiers are keywords that determine the accessibility of methods, classes, etc in OOPs. These access specifiers allow the implementation of encapsulation. The most common access specifiers are public, private, and protected. However, there are a few more which are specific to the programming languages.
27. What is the difference between public, private and protected access modifiers?
Name | Accessibility from own class | Accessibility from derived class | Accessibility from world |
Public | Yes | Yes | Yes |
Private | Yes | No | No |
Protected | Yes | Yes | No |
To know more about encapsulation read along:
- Encapsulation in Java
- Encapsulation in C++
- Encapsulation in Python
Data abstraction
28. What is data abstraction?
Data abstraction is a very important feature of OOPs that allows displaying only the important information and hiding the implementation details. For example, while riding a bike, you know that if you raise the accelerator, the speed will increase, but you don’t know how it actually happens. This is data abstraction as the implementation details are hidden from the rider.
29. How to achieve data abstraction?
Data abstraction can be achieved through:
- Abstract class
- Abstract method
30. What is an abstract class?
An abstract class is a class that consists of abstract methods. These methods are basically declared but not defined. If these methods are to be used in some subclass, they need to be exclusively defined in the subclass.
31. Can you create an instance of an abstract class?
No. the Instances of an abstract class cannot be created because it does not have a complete implementation. However, instances of subclass inheriting the abstract class can be created.
32. What is an interface?
It is a concept of OOPs that allows you to declare methods without defining them. Interfaces, unlike classes, are not blueprints because they do not contain detailed instructions or actions to be performed. Any class that implements an interface defines the methods of the interface.
33. Differentiate between data abstraction and encapsulation.
Data abstraction | Encapsulation |
Solves the problem at the design level | Solves the problem at the implementation level |
Allows showing important aspects while hiding implementation details | Binds code and data together into a single unit and hides it from the world |
To know more about data abstraction, the below articles might help you:
- Abstraction in Java
- Abstraction in Python
Methods and Functions OOPs interview questions
34. What are virtual functions?
Virtual functions are functions that are present in the parent class and are overridden by the subclass. These functions are used to achieve runtime polymorphism.
35. What are pure virtual functions?
Pure virtual functions or abstract functions are functions that are only declared in the base class. This means that they do not contain any definition in the base class and need to be redefined in the subclass.
36. What is a constructor?
A constructor is a special type of method that has the same name as the class and is used to initialize objects of that class.
37. What is a destructor?
A destructor is a method that is automatically invoked when an object is destroyed. The destructor also recovers the heap space that was allocated to the destroyed object, closes the files and database connections of the object, etc.
38. Types of constructors
Types of constructors differ from language to language. However, all the possible constructors are:
- Default constructor
- Parameterized constructor
- Copy constructor
- Static constructor
- Private constructor
39. What is a copy constructor?
A copy constructor creates objects by copying variables from another object of the same class. The main aim of a copy constructor is to create a new object from an existing one.
40. What is the use of ‘finalize’?
Finalize as an object method used to free up unmanaged resources and cleanup before Garbage Collection(GC). It performs memory management tasks.
41. What is Garbage Collection(GC)?
GC is an implementation of automatic memory management. The Garbage collector frees up space occupied by objects that are no longer in existence.
42. Differentiate between a class and a method.
Class | Method |
A class is basically a template that binds the code and data together into a single unit. Classes consist of methods, variables, etc | Callable set of instructions also called a procedure or function that are to be performed on the given data |
43. Differentiate between an abstract class and an interface?
Basis for comparison | Abstract Class | Interface |
Methods | Can have abstract as well as other methods | Only abstract methods |
Final Variables | May contain final and non-final variables | Variables declared are final by default |
Accessibility of Data Members | Can be private, public, etc | Public by default |
Implementation | Can provide the implementation of an interface | Cannot provide the implementation of an abstract class |
44. What is a final variable?
A variable whose value does not change. It always refers to the same object by the property of non-transversity.
OOPs Interview Questions – Exception Handling
45. What is an exception?
An exception is a kind of notification that interrupts the normal execution of a program. Exceptions provide a pattern to the error and transfer the error to the exception handler to resolve it. The state of the program is saved as soon as an exception is raised.
46. What is exception handling?
Exception handling in Object-Oriented Programming is a very important concept that is used to manage errors. An exception handler allows errors to be thrown and caught and implements a centralized mechanism to resolve them.
47. What is the difference between an error and an exception?
Error | Exception |
Errors are problems that should not be encountered by applications | Conditions that an application might try to catch |
48. What is a try/ catch block?
A try/ catch block is used to handle exceptions. The try block defines a set of statements that may lead to an error. The catch block basically catches the exception.
49. What is a finally block?
A finally block consists of code that is used to execute important code such as closing a connection, etc. This block executes when the try block exits. It also makes sure that finally block executes even in case some unexpected exception is encountered.
OOPs Interview Questions – Limitations of OOPs
50. What are the limitations of OOPs?
- Usually not suitable for small problems
- Requires intensive testing
- Takes more time to solve the problem
- Requires proper planning
- The programmer should think of solving a problem in terms of objects
0 Comments