Primitive Data Type : Number, float, Boolean etc. are called Primitive Data Type Most probably , Primitive Data Types created on stack.
STACK AND HEAP
When .NET application runs then all variables allocate in RAM / temp memory and its operating system/programming language divide it into two types of memory one is Stack and another one Heap
OR
Stack is used for Static Memory allocation and Heap for Dynamic memory allocation and both are stored in the RAM.
STACK
Stack always reserved in the Last in first out i.e. LIFO.
Variable allocated on the stack are stored directly to the memory and access to this memory is very fast.
We can use the Stack if we know exactly how much data have required to allocate before compile time. While in Heap we don't know exactly.
Insert the data item at the top of Stack is called PUSH.
Delete the data item at the top of Stack is called POP.
HEAP
Heap is a area of memory where chunk are allocated to store to certain kind of data object.
Variable allocated on the Heap have their memory allocated at run time and accessing this memory bit slower.
C# Code
staticvoidMain(string[] args)
{
//line1
inti= 10;
//line2
inty = i;
// line3
Customerx = newCustomer();
x.name = "Raushan";
// line 4
Customerz = x;
z.name = "Kumar";
Console.WriteLine("Hello World!");
}
Line 1 : It is a Primitive Data Type and runs and i=10 assigned into the stack with value and its address pointer. When memory address and value has stored at same place is termed as Value Types i.e. " Value type are those type which address and actual data stored at same place".
Line 2: When it will run then value of y=10 stored in top of stack and it will never effect the value of i and vice versa is termed as by value Type. Mostly Primitive Data type created on stack.
Line 3: AClass which is not a primitive data type its an object. And in that case its address stored into the stack and value stored into Heap its termed as reference type i.e. "Reference type are those type where in the pointer is stored on the stack but actual data stored on the Heap".
Line 4: we have assign value to z =x it means that reference of z and x is same in case of value type reference of both i & y was different. so when we change the value of x then value of z will be also change and vice-versa its also comes under reference type.
Memory Leak
Memory Leak Occurs when a programmer create a memory in heap and forget to delete it. To avoid this leak memory allocated on heap should always be freed when no longer needed.
Garbage Collector
When class object is created at runtime, certain memory space allocated to it in the Heap memory .After all action of objects are completed in the program there has no longer need of memory allocated space then Garbage Collector automatically release the memory space.
Hey Guys, I hope that you are Enjoying with my blogs writing and in previous blog we have learnt about Memory Leak , Garbage Collector and Today's we will learn Boxing and Unboxing . Let's see
Boxing ,When a value type is move to a reference type its called Boxing and vice versa for Unboxing.
For Example In this code
inti = 10;//Value type
objecto = i;//Boxing
int y=(int)o;//Unboxing
Boxing is an implicit Conversion from value type to reference type.
Here i=10 has stored in stack with address above shown in diagram its moving value i to o its a value type.
Unboxing
Unboxing is an explicit Conversion from reference type to value type.
And in heap o=10 its also moving from o to y its a reference type.
Let's see the result of boxing and Unboxing
staticvoidMain(string[] args)
{ //Line1 Warm period
Heavyloop();
Heavyloop();
//Line2
Stopwatchs1 = newStopwatch();
s1.Start();
Heavyloop();
s1.Stop();
//Line3
Console.WriteLine(s1.ElapsedTicks);
Console.WriteLine("Hello World!");
Console.ReadLine();
}
Line 1: Function will run as it is for warmup period and then actual measuring will start from Line 2.
Line2: Stopwatch measure time below of milli sec and now will start measure its ElapsedTicks.
staticvoidHeavyloop()
{
for(inti=0; i<100000;i++)
{
intz = 10;//Value Type
objectx = z;// reference type
}
}
static void Heavyloop(), in this function we written code for boxing and Unboxing how much time it will take in performance. For that we set stopwatch.
stopwatch, find function how much time taking for execution.
Now let's run this code ,sometimes give 5 digits figure or 4 digits figure
1st output ElapsedTicks:
2nd output ElapsedTicks
3rd output ElapsedTicks
It means that in non Primitive Data type, Due to Boxing and Unboxing its figure digits are different most of the time may be 4 to 5 digits.
But in case of Primitive Data type always be the same figure due to no Boxing , Unboxing occurs.
Collection
It is similar to array, it provides more flexible way to work with group of objects.
It can grow and shrink Dynamically.
// line 1
int[] salesfigures = newint[] { 1000, 2000 };
// line 2
ArrayListl = newArrayList();
l.Add(1);
l.Add("one");
Console.WriteLine("Hiii");
/line 3
List<int> Is = newList<int>();
Is.Add(1);
Line 1: It is Strongly typed and there are no Boxing/Unboxing so its performance will be faster. Its resizing is difficult. This is an Array.
Line 2: Boxing/Unboxing will be happen that's why its performance will be slower but it will be very flexible. This is the array list.
Suppose we want flexible as well as good performance for that we have to create Generic collection i.e. "A collection which has strongly typed ,flexibility as well as it improves the performance, Avoiding Boxing/Unboxing is called Generic Collection ".
List<T>, Dictionary< Tkey, Tvalue>, sortedlist<Tkey,Tvalue>, Queue<T>, Stack<T>, Hashset<T> are used in Generic Collection.
Hey Guys, I hope that you are Enjoying with my blogs writing and in previous blog we have learnt about Primitive Data Type, And then see Stack, Heap, Value Type and Reference Type and Today's we will Memory Leak , Garbage Collector
Memory Leak
Memory Leak Occurs when a programmer create a memory in heap and forget to delete it. To avoid this leak memory allocated on heap should always be freed when no longer needed.
All Primitive Data type runs on stack , after end of the scope it release the memory space automatically at a time because its memory location is Contiguous while in Heap doesn't.
Garbage Collector
When class object is created at runtime, certain memory space allocated to it in the Heap memory .After all action of objects are completed in the program there has no longer need of memory allocated space in that situation Garbage Collector automatically release the memory space.
Garbage Collector runs in the background its a background process.
It runs un-deterministically it means we doesn't know when it will come to release space.in that case application stops for naino sec.
Lets see the code garbage collector is run or not.
for(inti=0; i<100000; i++)
{
//line1
inti = 10;
inty = i;
}
Line1: In that only has primitive Data type, so garbage Collector will not come to release the memory. Because it release automatically.
let's see Click on debug -> Performance Profiler -> Memory Usage and Start
So we can see in the above snapshot there are no appear GC in primitive Data type.
C# Code , To see the Garbage Collector
for(inti=0; i<100000; i++)
{
//line1
inti1 = 10;
inty = 10;
// line2
Customerx = newCustomer();
x.name = DateTime.Now.ToString();
Thread.Sleep(50);
}
Line2: In that Case we can see the garbage collector in red-red sign randomly.
You must watch this video to more details learning.
Hey Guys, I hope that you are enjoying with my blogs writing and in previous blog we have created a project and used ngModel and Directives and today's we will see concepts of Bootstrapping Angular Cycle so let's see Introduction .
Angular is a binding framework that is used to create web application. Angular uses typescript to write our business logic and method but browser does not understand typescript. The browser understand JavaScript . so that's why Angular CLI come into picture.
Angular CLI is a command-line interface tool that use to initialize, develop, scaffold and maintain Angular application directly from a command shell. It help us to create projects easily and quickly.
Work of BootSrapping
As we know that about view , model and component.
View i.e. app.component.html
model i.e. app.model.ts
Component i.e. app.component.ts
Module i.e. app.module.ts
index.html: This is the first file which will run and this file run to main.ts and it is run to Module.
i.e. first will run index.html->it will run to main.ts-> it will run to module.
Hey Guys, I hope that you are enjoying with my blogs writing and today's we will cover some "SQL SERVER" Concepts.
Microsoft SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.
As a database server, it is a software products with primary function of storing and retrieving data as requested by other software application.
Initial Releases is April 24, 1989;
Indexes
Indexes Improves the performance of search or An index is one of the important paths to make the performance of SQL server database high.
An index is a pointer to data in a table.
It helps to speed up select queries and Where clause but it slow down data input with the Insert, Update and Delete.
They are stored in a B- tree structure (Balance search tree) that helps SQL Server users quickly and efficiently find the rows or associated with key values.
Defragmentation in SQL, It changes the physical ordering of data (as it loses contiguous allocation) and the retrieval becomes time consuming, resulting in slow database performance.
Hey Guys, I hope that you are enjoying with my blogs writing and today's we will cover some "SQL SERVER" Concepts.
Microsoft SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.
As a database server, it is a software products with primary function of storing and retrieving data as requested by other software application.
Initial Releases is April 24, 1989;
Backup: A copy of SQL server data that can be used to restore recover the data after failure.
A backup of SQL server that is created at the level of database or one or more of its file or filegroup.
Full Backup: The most basic and complete type of backup is a full backup. This type of backup makes a copy of all data to a storage device, such as disk or tape
Incremental Backup: It is a type of backup that only copies data that has been changed or created since the previous backup activity was conducted.
Differential Backup: A data backup that is based on the latest full backup of a complete or partial database.
Incremental backup, sometimes called Differential backup while Differential backup are sometimes called "Cumulative backup".
Transaction Log: It is an integral part of SQL. Every database has a transaction file that is stored within the log file that is separated from data file It records all database modification.
Steps for backup:
Connect to the server and expand database -> Right click on database
A new windows will be open then select which type of backup you want , so I have selected full backup .
Hey Guys, I hope that you are Enjoying with my blogs and in previous blog we have learned about Basic concepts of C#, Class Libraries and Reusability and Today's we will see Data type of C# .
.NET is a free, cross-platform, open source developer platform for building many different types of applications.
.NET Core is a cross-platform .NET implementation for websites, servers, and console apps on Windows, Linux, and macOS.
Data Type
Data type specifies the size and type of variable values .It is important to use the correct datatypes of corresponding variable. C# is strongly typed language.
Numeric data types in C# must used for numbers are int( whole number) and double(floating point numbers)..
inti = 10; // Now focus on integer and double.
decimaly = 10.45;
doublez = 10.23;
floatt = 10;
stringx = "shiv123";
boolb = true;
To find the the Min and Max values of int, double float etc.
To find Min and Max values of Int16(short) , Int32(int), Int64(long) etc.
Input:
staticvoidMain(string[] args)
{
// numerical
Console.WriteLine("Min & Max value of short(Int16) ");
Console.Write(short.MinValue );
Console.Write(" to ");
Console.WriteLine(short.MaxValue );
Console.Write("\n");
Console.WriteLine("Min & Max value of int(Int32) ");
Console.Write(int.MinValue);
Console.Write(" to ");
Console.WriteLine(int.MaxValue);
Console.Write("\n");
Console.WriteLine("Min & Max value of long(Int64) ");
Console.Write(long.MinValue);
Console.Write(" to ");
Console.WriteLine(long.MaxValue);
Console.Write("\n");
Console.WriteLine("Min & Max value of double");
Console.Write(double.MinValue );
Console.Write(" to ");
Console.WriteLine(double.MaxValue );
Console.Read();
}
int16 : It is called short which values lies between -32768 to 32767 or 2 raise 16/2.Which can used it for age ,weight or small use it gives two types like Signed value it can hold +ve values as well as -ve. while in unsigned only +ve value can holds.
And signed and unsigned values for all data types like double, float etc.
int32 : It is simply called int which values lies between -2147483648 to 2147483647. Which can used greater value than int16.
int64 :It is called long which values lies between -9223372036854775808 to 9223372036854775807. Which can used for long values.
Hey Guys, I hope that you are Enjoying with my blogs in previous block we studied basic of C#, Its Installation, IL code by just in time make it machine code and Today's we will study about Basic concepts of C#, Class Libraries and Reusability.
.NET is a free, cross-platform, open source developer platform for building many different types of applications.
.NET Core is a cross-platform .NET implementation for websites, servers, and console apps on Windows, Linux, and macOS.
With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT.
So lets create one console app(.NET core) project for better understanding to this concept.
It is an exe i.e executable. we can double click and execute this folder.
Build now and right click on console app open as an explorer go to bin folder and will get exe folder.
Input:(Program.cs)
usingSystem;
usingClassLibrary1;
namespaceConsoleApp2
{
classProgram
{
staticvoidMain(string[] args)
{
Class1x = newClass1();// we can call here to class1
Console.WriteLine(x.Add(10,20));
// here we giving parameter to add function
Console.WriteLine("Hello World!");
Console.Read();
}
}
}
To make DLL, Will have to create a Class library.
DLL stands for dynamic link library it is library that contains function and codes that can used by more than one program at a time. Once we have created DLL we can use in many application.
Input:(Class1.cs)
usingSystem;
namespaceClassLibrary1
{
publicclassClass1
{
publicintAdd(intnum1, intnum2)
{
returnnum1 + num2;
}
}
}
This code we can execute but can't link it.
After build it, If we want to see DLL file go to its bin folder then executable file not will show , it show dll(dynamic link library) like given below
We can't run this folder by double click because its not an executable it is Dynamic link library.so we can call to its function from another class.
For reference to console app ,go to right side-> right click on dependency -> add project reference-> class library.
Hey Guys, I hope that you are Enjoying with my blogs and Today's we will study about .NET Platform with "C#" Language basic concept.
.NET is a free, cross-platform, open source developer platform for building many different types of applications.
.NET Core is a cross-platform .NET implementation for websites, servers, and console apps on Windows, Linux, and macOS.
With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, and IoT.
whatever code write in C# ,It compiles in intermediate language code and by just in time compiler(JIT) make IL code to machine code. For Example
suppose if want to see IL code then build this program.
If we build this code then its IL code will show in bin folder
Go to solution explorer -> right click->open folder in file Explorer->binary folder(bin)->debug->
Many code folders has like dynamic link library(dll) Console application only for start to dll not run directly that's why application console first link and then run dll.
when we double click on exe then JIT start in background.
And JIT compile to single-single line make it machine code
Intermediate language disassembler (ILDSM) for showing purpose we will to go on visual command prompt
Like visual studio developer command prompt go and open then new dialogue box will open drag and drop click on console application
Expand -> static void main then IL code will be show
so we can say that C# doesn't compile directly into machine code its first compile into intermediate language then this IL code later compile by JIT into Binary code.
For Example: Flow of C# code
C# is a strongly typed language it means that language is one in which variables are bound to specific data types, and will result in type errors like.
int i = 0;
i++;
i="Raushan"
It will show error can not implicitly convert type string to int.
A strongly-typed language in which variables are bound to specific data types, and will result in type errors if types do not match up as expected in the expression — regardless of when type checking occurs.
C# Data Types: It is strongly data type language.
if condition : It is used where condition is true. otherwise else condition.