Friday 15 February 2013

End of Week

Today, the end of the great week. Had posted some Question answers in the MindQ, practiced some CSharp basic programs etc.  Also today, I played carom(its a indoor game) in my floor itself  where other colleagues use to play it for refreshment. Today even I played with them. I still remember the last time I played carom, around 3-4 years back. And after a long period I got the chance to play again over here, and guess what? I won the game. It was fun. One of the good experience in Inforica.

The Concept of 'Joins' in SQL Server

Combining data from multiple tables using single select statement is called as a JOIN.
Joins are classified into
  • Inner Join.
  • Outer Join
  • Cross Join
 Inner Join are again classified into:
  • Equi Join
  • Natural Join
  • Non-Equi Join
  • Self Join
Outer Join are classified into
  • Left Outer Join
  • Right Outer Join
  • Full Outer Join
  • Cross Join
  1. Inner Join:  Inner Join is the join that can display only the rows that satisfy the given join condition.
  2. Equi Join: The Inner Join that uses equal operator in the join condition is called as Equi Join.
  3. Natural Join: An inner join is called as natural join only when it satisfies the following three condition.
  • Join is Equi Join.
  • All common columns in the table must be in the joined condition.
  • Only one set of common columns is displayed in the output.
   4. Non Equi Join: The inner join that uses the operator other than equal in the join condition is called as non-Equi Join.

    5.  Self Join: A join that joins a taable to its self is called as Self Join.
  • Outer Join:  Outer Join is a join that can display the rows that does not satisfy the given join condition along with the rows that satisfy the given condition.
  1. Left Outer Join: Left outer Join is an Outer Join that can display the rows that does not satisfy the given condition only from left hand side table. To perform Left outer join with ANSI syntax use the keyword Left Outer Join and to perform Left Outer Join with non-ANSI syntax use the keyword *= in the join condition.
  2. Right Outer Join: Right outer Join is an Outer Join that can display the rows that does not satisfy the given condition only from right hand side table. To perform right outer join with ANSI syntax use the keyword Left Outer Join and to perform Right Outer Join with non-ANSI syntax use the keyword =* in the join condition.
  3. Full Outer Join:  Full outer Join is an Outer Join that can display the rows that does not satisfy the given condition only from both the tables. To perform full outer join with ANSI syntax use the keyword full Outer Join and to perform Full Outer Join with non-ANSI syntax perform union on left outer join and right outer join statements.
  4. Cross Outer Join: The join that joins every row in the first table with every row in the second table is called as Cross Join.

Constant Variables And Read only variables

 Constant Variables
  • Its a variable whose value cannot be modified once after declaration so it is compulsory to initialize the variable at the time of declaration so it is compulsory to initialize the modified once after declaration so it is compulsory to initialize the variable at the time of declaration only and to declare a variable as constant we need to use const
  • The behavior of a constant variable will be similar to the behavior of static variables i.e maintains a single copy by initializing one and only one time immediately once the execution of class starts.
 Read only variables
  • Its a variable whose value cannot be modified once after initialization and should be declared using readonly keyword.
  • As readonly variables cannot be initializing after declaration also i.e it can initialized under a constructor.



Static Modifier

This is used for declaring the members of the class as well as the class as static. As we aware that a class is a collection of members and those members are divided into two categories :-
  • Static Members
  • Non-static Members
The  members of a class which doesn't require the object of the class for initialization or execution are known as static members, whereas the members of class which requires object of class for initialization and execution are known as non static members.

Note:  Non static members can also be called as instance method because they are associated with an object or instance of class.

Static members vs non static variables
  • A variable that is declared using static modifier or a variable that is declared under any static block is a static variable rest of the other are non-static only.
         int x=100                  // non static
         static int y=200         //static
         static void  Main()
        { 
          int z=300;               //static
        } 
  • A static variables get initialized immediately once the execution of class starts and whereas a non-static variables get initialized on when the object of the class is created as well as each time the object is created.
  •    A static variable get initialized one and only one time in the life cycle of class whereas a non static variables mat be initialized for 0 or n times.

TestMath.cs

To test the below, add a new class TestMath.cs and write the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
    class TestMath
    {
        static void Main()
        {
            Math m = new Math(100,50);
            m.Add(100, 50);
            m.Sub(60, 30);
            m.Mul(10, 20);
            m.Div(50, 25);
            Console.ReadLine();
           
        }
    }
}

What is the need of defining a Constructor explicitly?

 We are already aware that if we don't define a constructor in the class, still a implicit constructor comes  into picture and initializes some variables of class but we explicitly defines constructor under class so we have a chance of initializing variables of class with desired values.

Each and every class requires some initialization values foe execution so if we defined a constructor under the class we have a chance of sending our own initialization values for the class to execute and this values can be changed whenever wee create a new object for the class.

In the below below case, the four methods of the class requires the values for x and y to execute and those two variables are being initialized under the constructor so when and where we want to consume this class we can send values for x and y while creating the objects and then call all the four methods:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpConsole
{
    class Math
    {
        int x, y;
        public Math(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public void Add(int x, int y)
        {
            Console.WriteLine(x + y);
        }
        public void Sub(int x, int y)
        {
            Console.WriteLine(x - y);
        }
        public void Mul(int x, int y)
        {
            Console.WriteLine(x * y);
        }
        public void Div(int x, int y)
        {
            Console.WriteLine(x / y);
        }
       
     }
}