Monday, March 31, 2014

Access Modifiers

In this article am going to discuss about access modifiers and their functionality along with, how they differ from each other and what are the basics of all these.
I’ll include all 4 access modifiers in this article.

Access Modifiers in C#

·         By default, data and methods defined in a class can only be used inside that class itself.
·         We must choose to expose them.
·         Access modifiers let you specify how programs that use your classes can access their data and methods.

 Class Access Modifiers | C#

Am going to explain this through an example-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hello_Word
{
    class Program

    {
       static void Main(string[] args)

                public int Value;
      // public access modifier

                private string Message;
      // private access modifier

                protected void function();
      // protected access modifier


        }
}



We can use any of the class modifiers in our class but working mechanism of all these modifiers are different.


Modifiers | Types

Public

PUBLIC modifier is used at that place in the class of which values, attributes can be easily accessed by the any other object.

Private

PRIVATE access modifier is used where we want the functionality of attribute of that class can be only used within that class only.

Protected

-          It is used where the class member can only be accessed within the same class.
-          Inherited class of that class(child/subclass)

 Internal

-         -    It is the advanced functionality of C# 5.0 or above.
-         -    In this modifier class member can be accessed by any class in the same assembly.
-         -    Package of code like a library or other program.

Example

There are 2 parts in this code; first part is representing construction building and access modifiers definitions. In the second code there is a calling of the access modifiers functionalities.

Part: 1 | Code

// Book.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hello_Word
{
    class Book

    {
        // access modifier- PUBLIC
        public string Name;
        public decimal Price;
        public string Description;

        // access modifier- PRIVATE
        private decimal discount;

        // public constructer
        public Book(string bookName, decimal price)      

        {
            Name = bookName;
            Price = price;
            discount = 0.0m;
        }
    }
}

Part: 2 | Code

    class Program
    {
        static void Main(string[] args)
        {

            Book b1 = new Book("Black Book", 1050.00m);
            Book b2 = new Book("Complete Refrence", 1250.00m);

            string str = b1.Name;

          }
     }


When you do try to define b1.discount there will be no option in the list as




But if you do try to declare, it will show an error like this


// Program.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hello_Word
{
    class Program
    {
        static void Main(string[] args)
        {

            Book b1 = new Book("Black Book", 1050.00m);
            Book b2 = new Book("Complete Refrence", 1250.00m);

            string str = b1.Name;

            decimal dsc = b2.discount;
        }
     }
}


// We can not directly use discount in our next file, because it is defined under a private class, we didn’t get the options from the list but if we do try to do so, it will surely show an error-
“Inaccessible due to private modifier”



Same in the case of protected modifier, if you try to access its properties it will again show the same message-



___________________________________________________________

For more technical blogging stuffs please visit,
http://www.c-sharpcorner.com/authors/2072a9/abhishek-jaiswal.aspx

___________________________________________________________

Sunday, March 30, 2014

Break and Continue Statements in CSharp

In this article am going to explain to of the most useful concepts of C#, these are also called loops. I’ll explain and differentiate between them through an example.


Break Statement

Break statement breaks out of the loop at current point or we can say that it terminates the loop condition.
It is represented by
break;

Continue Statement

Continue statement jumps out of the current loop condition and jumps back to the starting of the loop code.
It is represented by
continue;

Example | Break vs Continue

In this example am showing functioning of both the statements together, afterwards I’ll explain them one by one with their functionality.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {

            int i;        

          for (i = 0; i <= 10; i++)
          {

              if (i == 5)                             
                  continue;
             
              if (i == 8)              
                  break;

              Console.WriteLine("value is"  +i);            
          }

          Console.ReadLine();
              
            }    
        }
    }


Output Window



Explanation

In this example the out is from 0 to 7 excepting 5, 8, 9 ?

CASE: 1 It is because in the first case-

              if (i == 5)                             
                  continue;

Means it will skip the current loop and jumps to the top of the loop, so there is no 5 in the output window.

CASE: 2 In second cases-

              if (i == 8)              
                  break;

It will terminate the loop or get out of it when value becomes 8, so there is no 8, 9 in the output window.
Now let’s do some changes in the code and see what happens, here we go-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {

            int i;        

          for (i = 0; i <= 10; i++)
          {

             if (i == 5)                             
                  continue;
             
          //   if (i == 8)              
          //        break;

             Console.WriteLine("value is: "  +i);            
          }

          Console.ReadLine();
              
            }    
        }
    }




Now you can see the output.  Condition continues to flow according to the continue statement functioning.
Now am making some other modifications, in the code snippet, as-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {

            int i;        

          for (i = 0; i <= 10; i++)
          {

          //   if (i == 5)                             
          //        continue;
             
             if (i == 8)              
                  break;

             Console.WriteLine("value is: "  +i);            
          }

          Console.ReadLine();
              
            }    
        }
    }




Now you can see, it again showing from 0 to 7 and because of the break statement condition, it’s again out of the loop so there is no 8, 9, 10

Big Data (Real Picture)

Hello geeks…!
Today am going to present real world picture and scenario of big data and all related supportive contents along with it. Like

what is it…?
How it is created…?
How it’s going to change the world...?
Effects…?
Necessity…?
   and lots more things.

What is BIG-DATA?

In simple words we can define big data as huge/massive amount or collection of data which can be of almost any-type, any-size and variety.

Big Data | Estimated Size

According to IBM-
    “Around 2.5 quintillion bytes of data is created every day.”

Big Data | Types


There are generally 2 types of data exist in current scenario:




 - Structured Data:

 [Data that resides in a fixed field within a record or file is called structured data.]

 - Unstructured Data

    [It is type of data that includes text, audio, videos, photos, web pages, documents, email messages, word processing etc.]

According to TCS-
      “In current world almost 51% of data is structured data. 27% data is unstructured data while rest 21% is called semi-structured data. ”

Big Data | Generated Jobs

According to GARTNER-
        “There are as much as 4.4 million IT jobs will be created globally to support big data by 2015. The technology will generate 1.9 million IT jobs in the USA alone and rest all will get divided in the whole world. ”

Big Data | Talent Required

According to McKinsey-
        “The USA alone could face a talent shortage of around 140K – 190K peoples by 2018. Further this shortage can get exceeded. According to their estimation the shortage can reach upto 1.5 million, which will include managers, analysts etc. to make effective decisions on big data. ”

Big Data | Re-Planning

According to TEK Systems-
        “Around 81% of IT leader and 77% of IT professionals believe there is a considerable shortage of talent that could make best use of their organization’s data assets.”

Big Data | Utilization/Requirement

According to TEK Systems-
         “Around 66% of IT leader and 53% of IT professionals believe their organizations need to build new platforms, structures to make use of their vast mammoth data management needs, thereby getting rid of the current systems.”

Big Data | Business Values

Tata Consultancy Services has highlighted 3 major challenges for companies:
  - Making business share information across organizational lines
  - Dealing with 3 V’s of big data


  - Determining which data could be best used under different conditions.

 Big Data | Quality

According to TEK Systems-
          “Around 57% of IT leaders and 52% of IT professionals claim that they don’t know always who is the owner of data, meaning quality more or less lies on the back burner. Ensuring the accuracy and quality of data will be critical in the times to come in an ever expanding universe of big data. ”

Big Data | Data Management

According to COMPTIA-
          “Nearly eight in 10 data executives believe that harnessing all of their enterprise data would result in a stronger business.”

Big Data | Business Driver

According to EMA and 9Sight Consulting-
          the 3 big data business drivers include:

  - Speeding time for operational or analytical workloads
     [around 39%]
  - Increasing competitive advantage with flexibility of data used in business solutions
     [around 34%]
  - Business requirements for higher levels of advanced analytics
     [around 31%]

Big Data | Implementation

According to EMA and 9Sight Consulting-
          “Big data implementations in production rose from 27% in 2012 to 34.3% in 2013.”



Big Data | Tools

According to Giga Space-
          “Nearly 80% people in IT are either using or planning to use dedicated big data tools to manage massive amounts of data in their organizations.”

Big Data | Expenditures

According to TCS-
          “Around 15% of the companies surveyed had spent at least $100 million each on big data in 2012, while 7% had invested at least $500 millions.”

Big Data | Expenditures based on Sectors

According to TCS-
          “Travel related, high tech, share and banking industries have been the biggest spenders while industries related to life science, retails and energy have spent the least.”



Applications through C++



Hello C++ lovers, today am going to make you all familiar with some useful trade offs / applications of C++. These applications are



You can simply implement all these functionalities through these methods:


Concurrent Waiting

Concurrent waiting can be drawn on the basis of these three mechanisms

Concurrent Waiting | .get

size_t
file_sizes( string file1, string file2 )
   {

   task<file> f1 = open(file1),
              f2 = open(file2);
   return f1.get().size() +
          f2.get().size();

}

Concurrent Waiting | .then

task<size_t>
file_sizes( string file1, string file2 )

    {
   task<file> f1 = open(file1),
              f2 = open(file2);
   return when_all(f1,f2)
      .then([=](tuple<file,file> fs)
       {
         return get<1>(fs).size() +
                get<2>(fs).size();

      });
}

Concurrent Waiting | .then + await

task<size_t>
file_sizes( string file1, string file2 ) __async
    {

   task<file> f1 = open(file1),
              f2 = open(file2);
   return (__await f1).size() +
          (__await f2).size();

}

Real Payoffs | Branches & Loops

Branches & Loops | .get

string
read( string file, string suffix )
   {

   istream fi = open(file).get();
   string ret, chunk;
   while( (chunk = fi.read().get()).size() )
      ret += chunk + suffix;
   return ret;

}

Branches & Loops | .then

task<string>
read( string file, string suffix )
  {

   return open(file)
   .then([=](istream fi)
     {
      auto ret = make_shared<string>();
      auto next =
         make_shared<function<task<string>()>>(
      [=]
     {
         fi.read()
         .then([=](string chunk)
                {
            if( chunk.size() )
                 {
               *ret += chunk + suffix;
               return (*next)();
            }
            return *ret;
         });
      });
      return (*next)();
   });

}

Branches & Loops | .then + await

task<string>
read( string file, string suffix ) __async
{

   istream fi = __await open(file);
   string ret, chunk;
   while( (chunk = __await fi.read()).size() )
      ret += chunk + suffix;
   return ret;

}