Object:: Oops
Object:: Oops
Object:: Oops
Constructor Method
To initialise the state of an object. To expose behaviour of a object.
No return type. Return type must
Can be variable, Gets memory allocated only once at the Can be invoked without the
method, blocks, nested time of class loading. need for creating an instance of
class a class.
Memory efficient. Can access static data member
an can change value of it.
New Override
when base class has not declared method as used with virtual/abstract/override type of
virtual/abstract/override. method in base class
New hides the method of base class Override extend the method of base class with
new definition.
This is a keyword
Access modifiers:
Non- Access Modifiers : Static, final, abstract, synchronised, native, volatile, transient etc
Static: Used for creating class methods and variables. Variables will exist independently of any instances of
classes created. Only 1 copy exists. Also known as class variables. Local variables can’t be static.
Final : for finalizing the implementations of class, methods, variables. Variables can be initialized
only once. A ref variable declared final can never be reassigned to refer to diff object. State and data
of the object can be changed but not the reference. Final methods cannot be overridden. Content of the
method should never be changed by outsider.
Abstract: to create abstract class and methods. Abstract class can never be instantiated. Abstract class
can only be extended. Cannot be both abstract and final. If a class has abstract methods then class
should be abstract if not compile time error. Abstract methods are declared without any
implementations. Abstract methods can never be strict or final
Synchronized : Indicates that a method can be accessed by only 1 thread at a time. Can be applied
with any four of the access modifiers.
Transient :To indicate the JVM to skip particular variable when serialising the object containing it.
Volatile: used for threads.
Difference between constant, read only and static read only:
A const field is a compile time A readonly field can be used as A static readonly field can be
constant a run-time constant used as a runtime constant
Once a value is assigned to a We can change the readonly Static readonly values can only
constant, it can’t be initialized variable values any number of be changed inside static
again it will throw error. time provided that we are contructors only. It can be
Left hand side of an changing it inside the instance changed only once at runtime.
assignment must be a variable, constructors
property or indexer.
It can be accessed using It can be accessed using It can be accessed using
classname.constname interfaces classname.constname
Difference between var and dynamic keyword
Var Dynamic
The variables are declared using var keyword The variables are declared using dynamic
are statically typed. keyword are dynamically typed.
The type of the variable is decided by the The type of the variable is decided by the
compiler at compile time. compiler at run time.
The variable of this type should be initialized at The variable of this type need not be initialized
the time of declaration. So that the compiler will at the time of declaration. Because the compiler
decide the type of the variable according to the does not know the type of the variable at
value it initialized. compile time.
If the variable does not initialized it throw an If the variable does not initialized it will not
error. throw an error.
Boxing Unboxing
The process of Converting a Value Type (char, The process of converting reference type into
int etc.) to a Reference Type(object) is the value type is known as Unboxing.
called Boxing.
Boxing is implicit conversion process in which It is explicit conversion process.
object type (super type) is used.
The Value type is always stored in Stack. The Referenced Type is stored in Heap.
int num = 23; int num = 23;
Object Obj = num; // Boxing Object Obj = num; // Boxing
int i = (int)Obj; // Unboxing
== Equals()
== compares object references. .Equals compares object content.
public class Test {
public static void main(String[] args)
{
String s1 = new String("HELLO");
String s2 = new String("HELLO");
System.out.println(s1 == s2); //false
System.out.println(s1.equals(s2)); //true
}
}
Stored procedure in sql server:
CREATE PROCEDURE SelectAllCustomers @City nvarchar(30), @PostalCode nvarchar(10)
AS
SELECT * FROM Customers WHERE City = @City AND PostalCode = @PostalCode
GO;
EXEC SelectAllCustomers @City = "London", @PostalCode = "WA1 1DP";
Second max salary:
Select top 1 salary select max(salary)
From ( select distinct top N salary from employee
From employee where salary< (select max(salary)
Order by salary DESC ) As temp from employee);
Order by salary; //where N=1,2,3,…
Difference between clustered and non clustered index
Collection Collections
Collection is an interface Collections is a class
Collection is base interface for list, set and Collections is a class and it is called utility
queue. class.
Difference between array and arraylist:
Array ArrayList
A data structure consisting of a collection of A class that supports dynamic arrays which can
elements each identified by array index grow as needed
Using = operator for storing elements Add() method for storing elements
Helps to implement fixed size data structure Helps to implement dynamic size arrays
Can contain primitive or objects Can only store objects
Arraylist Linkedlist
It is index based data structure where each Uses doubly linkedlist i.e previous element,
element is associated with index value and next element referencing
Occcupies less memory Occupies more memory because of nodes
holding the reference elements
It is used when application requires more It is used when application requires more
retrivals than insertions insertions than retrivals
Better for storing and accessing data Better for manipulating data
Difference between hashmap and hashset
Hashmap Hashset
Hash table based implementation of Map It is a set. Uses hash table for storage
interface
Faster than hashset because it has uniq Slower than HashMap because member obj is
values used for calculating hashcode which can be
same 2 objects.
Only 1 object is created during the add Two objects created when add() operation is
operation done. 1 for key 2 value
HashMap Hashtable
One null key , multiple null values Does not allow any null key/value
Fast Slow
MVC life cycle: MVC has two life cycles – 1)The application life cycle 2)The request life cycle
The Application Life Cycle:
The application life cycle refers to the time at which the application process actually begins running
IIS until the time it stops. This is marked by the application start and end events in the startup file of
your application.
Creating the request object: -The request object creation has four major steps. Below is the
detail explanation of the same.
Step 1 Fill route: - MVC requests are mapped to route tables which in turn specify which controller
and action to be invoked. So if the request is the first request the first thing is to fill the route table
with routes collection. This filling of route table happens in the global.asax file.
Step 2 Fetch route: - Depending on the URL sent “UrlRoutingModule” searches the route table to
create “RouteData” object which has the details of which controller and action to invoke.
Step 3 Request context created: - The “RouteData” object is used to create the “RequestContext”
object.
Step 4 Controller instance created: - This request object is sent to “MvcHandler” instance to create
the controller class instance. Once the controller class object is created it calls the “Execute” method
of the controller class.
Creating Response object: - This phase has two steps executing the action and finally sending the
response as a result to the view.
Routing in MVC: Routing helps you to define a URL structure and map the URL with the controller.
The route mapping code is written in "RouteConfig.cs" file and registered using "global.asax"
application start event.
{ routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
Bundling : It helps us improve request load times of a page thus increasing performance.Web
projects always need CSS and script files. Bundling helps us combine multiple JavaScript and
CSS files in to a single entity thus minimizing multiple requests in to a single request.
Minification reduces the size of script and CSS files by removing blank spaces , comments etc.
For example below is a simple javascript code with comments.
Sessions in MVC: Sessions can be maintained in MVC by three ways: tempdata, viewdata, and
viewbag.
“TempData” maintains data for the complete request while “ViewData” maintains data only from
Controller to the view.
Partial view: Partial view is a reusable view (like a user control) which can be embedded inside other
view. For example let’s say all your pages of your site have a standard structure with left menu,
header, and footer.
Razor in MVC: It’s a light weight view engine. Till MVC we had only one view type, i.e.,
ASPX. Razor is clean, lightweight, and syntaxes are easy as compared to ASPX. For example, in
ASPX to display simple time, we need to write:
Return types of action result MVC: ActionResult is an abstract class. Below are derived class
EmptyResult, FileResult.