Wednesday, 3 July 2019

Procedures and Functions


Procedures
Functions
Procedure can return zero on N values
Functions can return only single value
Returning a value is not mandatory
Returning a single value is mandatory
Can have both input and output parameters
Can have only input parameters
Can select as well as other DML, Data Manipulation Language (INSERT, UPDATE, DELETE,) statements
Can only do select statement
Function can be called from procedure
Procedure cannot be called from functions
Try catch block can be used to handle the errors
Try catch block cannot be used in functions
Procedures cannot be utilized in select, where, having statement
Whereas functions can be utilized in select, where, having statement

Monday, 3 February 2014

Abstract, Sealed, Static, Partial - Classes

Class Types:
1) Abstract class
2) Sealed Class
3) Static Class
4) Partial Class
-----------------------------------------
A-- Abstract
S-- Sealed
S--Static
ASS is order by name
Keyword
Can be instantiated(object)
Can be inherited
Abstract
 NO
 YES
Sealed
YES
 NO
Static
NO
NO

Abstract Class
  1. It only represents the base class and thus has be inherited for its use.
  2. Object can NOT be created. can NOT be instantiated.
  3. Abstract class and methods can NOT be sealed ( class which can not be inherited).
  4. Abstract methods can NOT be private.
  5. Abstract methods can NOT be virtual ( by default they are virtual).
  6. Abstract class and methods can NOT be static.
  7. Abstract method definition can be given only inside a Abstract class. In non abstract class no abstract method can be defined.
  8. Can have either abstract method or non-abstract methods.
  9. Abstract method do not have any implementation of methods but has to be provided the same in the derived class.
  10. Abstract class may contain NO abstract method at all. 
  11. Abstract methods has to be override in derived class. 
  12. Derived class has to implement all abstract methods of abstract class.

abstract class absClass
{
   public abstract int abstractMethod(int Num1, int Num2);
}

 public override int abstractMethod(int Num1, int Num2)
{
    return Num1 * Num2;
 }

Sealed Class
  1. Restrict inheritance. can NOT be inherited. Its just to take away the inheritance feature.
  2. Structs are sealed in nature.
  3. NO restriction on object creation. sealed class can be instantiated.
  4. If you make a sealed a method / property that overrides a virtual method /property  it will get prevented from further overriding.
  5. Best use of sealed class is when your sealed class has static members (How?).
class X
{
  protected virtual void F() { Console.WriteLine("X.F"); }
  protected virtual void F2() { Console.WriteLine("X.F2"); }
}

class Y : X
{
 sealed protected override void F() { Console.WriteLine("Y.F"); }
 protected override void F2() { Console.WriteLine("X.F3"); }
}

class Z : Y
{
 // Attempting to override F causes compiler error CS0239.
 // protected override void F() { Console.WriteLine("C.F"); }
// Overriding F2 is allowed.
 protected override void F2() { Console.WriteLine("Z.F2"); }
}

Static Class
  1. Static class must have all methods and variables as static.
  2. Even in static class only static constructor can be called and NO instance constructor allowed.
  3. can NOT be instantiated.
  4. static class is Sealed(can not be inherited) by default.
  5. Static class can NOT be abstract class ( as it can not be inherited).
  6. Static class can only inherit system.object class as system.object class is the base class for every class.
  7. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
  8. Use a static class to contain methods that are not associated with a particular object.
Partial Class
a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword

SOAP and REST

SOAP
REST
Only XML format is allowed for data transfer.
Multiple format like Plain Text, XML, JSON HTML
Stateless by default, but it’s possible to make a SOAP API stateful.
Stateless (no server-side sessions).
While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features.
Less Secure
Requires more bandwidth and computing power
Requires fewer resources.



WCF and ASP.net Services















































Const
Read-only
A constant member is defined at compile time and cannot be changed at runtime.
read-only member can be initialized at runtime, in a constructor as well being able to be initialized as they are declared
They must be initialized as they are declared
Not implicitly static (only single object ) and has to explicitly made static



Monday, 21 October 2013

Encapsulation

Note: All this data has been copied from various sources for the purpose of knowledge sharing. Data content  can be either as it is or with little modification.
---------------------------------------------------------------------------------------------------------------------
Encapsulation prevents data from unwanted access by encapsulating data in a single object.

In a programming language, methods and properties that correspond to actions and attributes respectively are kept under a unit called object. The advantage of encapsulation is that the implementation is not accessible to the client. The user has to know only the functionality of encapsulated unit and information to be supplied to get the result.

Abstraction is supported using interface and abstract class while Encapsulation is supported using access modifiers e.g. public, private and protected.

Thursday, 3 October 2013

NIIT

1. Explain different type of identity? [SQL Server]
2. What is scope_identity? [SQL Server]
3. What is CodePage?[SQL Server]
4. What is an Assembly?
5. What are the benefits of MSIL?
6. Describe ASP.NET Page Life Cycle?
7. Write down ASP.NET Page events?
8. What is the use of Interface?
9. What are the differences between VB.NET and C#.NET?
10. what are soap headers and soap extensions ?
11. can we return a Person type object from a web method ? what will be the WSDL then of this webservice ?
12. which method we use in webservices to send the request ? Get or Post ? explian
13. what is WSDL in webservices ?
14. Can we return a dataset from w webservice 
15. how can u do authentication a webservice ? so that only the person that have writes able to hit our service ?

--------------------------------
(1, 2)
 In most of our application scenario, we need to get latest inserted row information through SQL query. And for that, we have multiple options like:


SELECT @@IDENTITY  -- 
SELECT SCOPE_IDENTITY()
SELECT IDENT_CURRENT('table name')

All three functions return last-generated identity values. However, the scope and session on which last is defined in each of these functions differ.

SELECT @@IDENTITY --
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.

SELECT SCOPE_IDENTITY()--
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

SELECT IDENT_CURRENT('table name') --
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
========================================================================
(4) Assembly is a pre compiled code of .net clr in form of DLL or self executing file .EXE. It is of two forms private assembly and public assembly
private assembly is kept in the local folder of the project while the public assembly is kept in GAC.
public assembly has 4 main parts (Face value, version, public key token, culture info). public assebly is also called strong name assembly.
========================================================================
(5) MSIL -- Microsoft intermediate language
C# code --> CLR --> MSIL(can be read by any language) --> JIT --> Machine language