Saturday 8 April 2017

Angular 1 vs Angular 2

Angular 1 vs Angular 2


  • First thing, Angular 2 is not the upgrade of Angular 1 Angular 2 is completely rewritten.
  • Angular  is using Typescript which is super set of javascript (It doesn’t mean only typescript, dart also).
  • Angular 1.x was not built with mobile support in mind, where Angular 2 is mobile oriented.
  • Angular 1 core concept was $scope, and you will not find $scope in angular 2.0. Angular 2 is using zone.js to detect changes. See the below code.
  • Angular 1.x controllers are gon. We can say that controllers are replaced with “Components” in Angular 2.


  • In Angular 2, Structural directives syntax is changed. ng-repeat is replaced with *ngFor.

  • In Angular 2local variables are defined using hash(#) prefix.



  • Two-way data bindingng-model replaced with [(ngModel)]



In Short below are the comparison points


· Angular 2 is mobile oriented & better in performance.
· Angular 2 provides more choice for languages.
· Angular 2 implements web standards like components.
· AngularJS 2.0 is not easy to setup as AngularJS 1.x.
· Angular 1.x controllers and $scope are gone.
· Different ways to define local variables.
· Structural directives syntax is changed.
· Angular 2 uses camelCase syntax for built-in directives.
· Angular 2, directly uses the valid HTML DOM element properties and events.
· One-way data binding directive replaced with [property].
· Two-way data binding: ng-model replaced with [(ngModel)]
· Way of Bootstrapping Angular Application is changed:
· Ways of Dependency Injection is Changed- syntax changed.
· Way of routing is Changed- syntax changed.

Saturday 10 December 2016

Exception Handling

Exception Handling (try- catch- finally)


What happens if a finally block throws an exception?


Three things will be happen

ONE # That exception propagates out and up, and it should be handled at a higher  level. If it is not handled at the higher level, the application crashes.

TWO # The "finally" block execution stops at the point where the exception thrown.

Three # 
a) if the "finally" block is being executed after an exception has occurred in the try block,
b)and if that exception is not handled 
c) and if the finally block throws an exception
Then the original exception occurs in the try block is lost.



Will finally run if i put return in catch block?

Yes.The finally section is guaranteed to execute whatever happens including exceptions or return statement.


Does finally get executed if the code throws an error ?

Finally is always executed.


Is it mandatory for a piece of code to have catch or finally when try block is there ?

Yes. If a try block is there then either catch or finally has to be there or else a compiler error is generated.


Can finally bock have return statement ?

No,a compile time error is generated. Thats bcz finally contains the clean up code.


Can there be many catch statements for a single try block ?

Yes.But the rule is most specific exceptions should be caught first.


Will the foll code compile ?

           try 
            {
                throw new SystemException();
            }            
            catch(Exception e)
            {
            }
            catch(ArgumentException e)
            {
            }
No.It gives the foll error
A previous catch clause already catches all exceptions of this or of a super type ('System.Exception')





Thank you for taking your valuable time look at my blog - Sadiq Ali Syed



Friday 9 December 2016

Sealed Class


Sealed Class


Sealed classes are used to restrict the inheritance feature of object oriented programming. Once a class is defined as a sealed class, the class cannot be inherited. 

In C#, the sealed modifier is used to define a class as sealed. If a class is derived from a sealed class then the compiler throws an error. 

If you have ever noticed, structs are sealed. You cannot derive a class from a struct.  

The following class definition defines a sealed class in C#: 


        // Sealed class
       sealed class SealedClass
       {

       } 



In the following code, I create a sealed class SealedClass and use it from Class1. If you run this code then it will work fine. But if you try to derive a class from the SealedClass, you will get an error. 

        using System;
        class Class1
        {
   
        }
        // Sealed class
        sealed class SealedClass
        {
    
        }  

Sealed Methods and Properties 

You can also use the sealed modifier on a method or a property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent other developers that are using your classes from overriding specific virtual methods and properties. 

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"); }
}

Why Sealed Classes?
 

We just saw how to create and use a sealed class. The main purpose of a sealed class is to take away the inheritance feature from the user so they cannot derive a class from a sealed class. One of the best usage of sealed classes is when you have a class with static members. For example, the "Pens" and "Brushes" classes of the "System.Drawing" namespace. 

The Pens class represents the pens for standard colors. This class has only static members. For example, "Pens.Blue" represents a pen with the blue color. Similarly, the "Brushes" class represents standard brushes. "Brushes.Blue" represents a brush with blue color.
 

So when you're designing your application, you may keep in mind that you have sealed classes to seal the user's boundaries. 




Thank you for taking your time to look at my blog- Sadiq Ali Syed.








Using


USING BLOCK


Generally in our applications we will write code like create connection object to handle connectionstring after that open a connection and create command object etc. to interact with database to get data that would be like this 


It’s very easy way to write above code but problem is SqlConnection and SqlCommand objects will create IDISPOSABLE interface that means it could create unmanaged resources in our application to cleanup those objects we need to call Dispose() method at the end of our process otherwise those objects will remain in our application.

Suppose we use using statement in our applications it will automatically create try / finally blocks for the objects and automatically runs Dispose() method for us no need to create any try/finally block and no need to run any Dispose() method.

If we use using statement we need to write code will be like this 

C# Code



In above code using statement no need to worry about close connection because using statement automatically close the connection once process is complete and automatically it will run Dispose() method to dispose objects. 

The above using statement code will equal to below code








Thank you for taking your valuable time look at my blog - Sadiq Ali Syed




Wednesday 7 December 2016

Named Vs Optional Parameters


Optional Parameters

In C# 4.0 Parameters could be either required or optional. Now as a functional call, only required parameter is needed to pass. Optional Parameter, if not passed  will take default value.

Syntax





Key Points about Optional Parameter:
  • Each Optional Parameter has a default value as its part of the definition.
  • If no argument is sent for the Optional Parameter default is being used.
  • Default value of the Optional Parameter must be constant


  • Optional Parameter must define at the end of the any required parameter.

  • Optional Parameter could be applied on Constructor, Method, and Indexer etc.




Named Parameters

One case where optional parameters run into trouble is when there is more than one optional parameter with the same data type. For example:

public void DoSomething(int a = 5, int b = 10)
{
        ...
}


In this case, it's not clear what a call to DoSomething(37) means. Are you passing in a or b? This is where named arguments come in handy. Named parameters (also new to .NET 4.0) allow you to specify which parameter you intended.

// a = 37.  b = the default value.
DoSomething(a: 37);
 
// a = the default value.  b = 37.
DoSomething(b: 37);






Sunday 4 December 2016

AngularJS Test

My Quiz


  1. AngularJS directives are used in ________.

  2. Model
    View
    Controller
    Module

  3. Which of the following is a valid AngularJS expression?

  4. {{ 2 + 2 }}
    { 2 + 2 }
    (( 2 + 2 ))
    { (2 + 2) }

  5. Which of the following statements are true?

  6. Expression cannot contain condition, loop or RegEx
    Expression cannot declare a function
    Expression cannot contain comma, void or return keyword
    All of the above

  7. What is $scope?

  8. It transfers data between a controller and view
    It transfers data between model and controller
    It is a global scope in AngularJS.
    None of the above

  9. AngularJS filters ___________.

  10. Format the data without changing original data
    bind the data to display on UI
    Fetch the data from remote server
    Cache the subset of data on the browser

  11. AngularJS module can be created using ________.

  12. angular.module();
    var myModule = new module();
    module.create();
    angular.create();

  13. Which of the following statements are true?

  14. AngularJS controller maintains application data & behaviour using $scope
    AngularJS controller can be created in separate JS file
    AngularJS controller can be added into module
    All of the above

  15. Which of the followings are validation directives?

  16. ng-required
    ng-minlength
    ng-pattern
    All of the above

  17. How to acheive SPA in AngularJS?

  18. By using Routing
    By using Modules
    By using services
    None

  19. Angular JS hadles Dependecy injection by default?

  20. True
    False
    May be
    None

Thursday 24 November 2016

ADO Test

ADO.Net

  1. What is ADO Full form?

  2. Active Dependency Object
    Active Data Option
    ActiveX Data Object

  3. Which Namespace is needed to work with SqlServer?

  4. Using System.Data;
    Using System.Data.Sql;
    Using System.Data.SqlClient;

  5. What is DataSet?

  6. DataSet is collection of Database
    DataSet is colection of tables
    DataSet is will get data from database

  7. Which statement is TRUE?

  8. Dataset work with Disconnected Architecture
    DatReader work with Disconnected Architecture
    DataAdapter work with connected Architecture

  9. What is the purpose of Ado.Net?

  10. Ado.net is used to create classes in c#
    Ado.net is used to communicate with Database
    Ado.Net is used to create create object of classes

  11. which statemetn is false?

  12. data adapter is meadiator between dataset and database
    data set is not a collection of tables
    None

  13. what is connection object?

  14. It is used to perform DML operations
    It is used make a connection
    It is used to manipulate data in DB

  15. which method is used to fill that data in dataset

  16. Fall()
    Full()
    Fill()

  17. How will you access data from dataset

  18. By using index
    bu using name of table
    All the above

  19. whihc method of command object do you use to perform Insert operation

  20. ExecuteReader()
    ExceCuteScalar()
    ExcecuteNonQuery()

Tuesday 22 November 2016

JAVASCRIPT Test2

JavaScript

  1. How do you create a function in JavaScript?

  2. function:myFunction()
    function myFunction()
    function = myFunction()

  3. How do you write "Hello World" in an alert box?

  4. alert("Hello World");
    msg("Hello World");
    alertBox("Hello World");

  5. How do you call a function named "myFunction"?.

  6. myFunction()
    call function myFunction()
    call myFunction()

  7. How to write an IF statement in JavaScript?

  8. if i = 5
    if (i == 5)
    if i = 5 then

  9. How to write an IF statement for executing some code if "i" is NOT equal to 5?

  10. if (i <> 5)
    if i =! 5 then
    if (i != 5)

  11. How does a WHILE loop start?

  12. while i = 1 to 10
    while (i <= 10; i++)
    while (i <= 10)

  13. What is the correct way to write a JavaScript array?

  14. var colors = "red", "green", "blue"
    var colors = (1:"red", 2:"green", 3:"blue")
    var colors = ["red", "green", "blue"]

  15. Which operator is used to assign a value to a variable?

  16. =
    *
    /

  17. Boolean(10 > 9)

  18. True
    False
    None

  19. Is JavaScript case-sensitive?

  20. Yes
    No
    May be

Monday 21 November 2016

SQL Advance

SQL

  1. What are the different types of replication available in SQL server?

  2. Snapshot Replication
    Transactional Replication
    Merge Replication
    All of the above.

  3. ACID stands for _______.

  4. Atomic, Cryptic, Independent, Durable
    Atomicity, Consistency, Isolation, Durability
    Automatic, Concurrent, Isolation, Durability
    Atomicity, Consistency, Isolation, Decoupled

  5. Which of the followings are valid Transaction levels in SQL Server?

  6. READ COMMITTED
    READ UNCOMMITTED
    REPEATABLE READ
    All of the above

  7. What is the correct order of query operators in a SQL query?

  8. SELECT -> FROM -> OUTER -> WHERE
    FROM -> OUTER -> WHERE -> ON
    SELECT -> FROM -> WHERE -> OUTER
    FROM -> OUTER -> GROUP BY -> WHERE

  9. RAID stands for ________.

  10. Reduce Array of Independent Disks
    Redundant Array of Independent Disks
    Redundant Automatic Individual Durable
    Redundancy Accelerator Independent Disks

  11. OLTP stands for _________.

  12. Online Transaction Processing
    Offline Transaction Processing
    Ontime Transaction Program
    Online Timebound Processing

  13. Which of the followings are the types of locks in SQL Server?

  14. Shared locks
    Exclusive locks
    Schema locks
    All of the above

  15. What are the different types of temporary tables in SQL server?

  16. Indexed and non-index temporary tables
    Global and local temporary tables
    Unique and shared temporary tables
    Small and large temporary tables

  17. What are the different types of trigger

  18. DDL and DCL
    DDL and DUL
    DML and DTL
    DML and DDL

  19. Which of the following is not a valid data type in SQL server

  20. xml
    nvarchar
    money
    blob

SQL Basic

SQL

  1. What is Primary Key?

  2. Primary keys are unique names of a table.
    Primary keys are integer ids in a table rows.
    Primary keys are unique identifiers for each row in a table.
    None of the above.

  3. which is not a constraint in below options?

  4. Foreign Key
    Unique
    Varchar
    All of the above

  5. A column that automatically generates numeric values is called __________.

  6. Unique column
    Integer column
    Identity column
    Candidate column

  7. Select which is not in Joins?

  8. Inner Join
    Outer Join
    Primary Join
    Cross Join

  9. What are indexes?

  10. Index speed up the data retrieval
    Index stores large number of integer values
    Index minimize the data redundancy
    None of the above.

  11. What is the difference between Primary key and Unique key?

  12. Primary key doesn’t allow null value whereas unique key allows multiple null values
    Primary key allows one null value whereas unique key doesn’t allow null value.
    Primary key doesn’t allow null value whereas unique key allows one null value.
    Primary key allows one null value whereas unique key allows multiple null values.

  13. What is a trigger?

  14. A trigger is a SQL procedure that initiates an action when event (INSERT, DELETE or UPDATE) occurs
    A trigger is an event that can be raised from Stored Procedures.
    A trigger is a SQL procedure that performs some tasks on accessing db tables.
    A trigger is a procedure which executes when an error occurred.

  15. How many types of indexes in SQL server?

  16. Integer and string
    Unique and non-unique
    Clustered and Nonclustered
    None of the above

  17. What is View?

  18. Virtual table
    Physical table
    It's not a virtual table
    None of the above

  19. what is Order by ?

  20. It will arrange in asecnding/ descending order
    It won't arrange in asecnding/ descending order
    It will join the tables
    None of the above