Wednesday, January 26, 2011
Web 2.0 and Technologies: Web 2.0:An overview
Web 2.0 and Technologies: Web 2.0:An overview: "History:The term web 2.0 suggests a new version of the World Wide Web, it does not refer to an update to any technical specification, ..."
Web 2.0 and Technologies: Web 2.0:An overview
Web 2.0 and Technologies: Web 2.0:An overview: "History:The term web 2.0 suggests a new version of the World Wide Web, it does not refer to an update to any technical specification, ..."
Tuesday, January 27, 2009
Monday, January 5, 2009
Inheritance
/******************************************************************************
INHERITANCE EXAMPLE: 1
The following program simply have a parent and child class with their own constructors.
Parent class additionaly have one member function. While creating an object for a child
class we will check how it call the parent constructor and member function.
When the control comes to Child Constructor, it first call the parent constructor and
then call the child constructor because of inheritance. Again the method print is not
actually in child class, but it finds it in parent class and execute it.
******************************************************************************/
using System;
public class parent
{
public parent()
{
Console.WriteLine("Parent Constructor");
}
public void print()
{
Console.WriteLine("Member from parent class");
}
}
public class child : parent
{
public child()
{
Console.WriteLine("Child Constructor");
}
public static void Main() /* OUTPUT *****/
{
child c = new child(); // Parent Constructor
c.print();} // Child Constructor
} // Member from parent class
/*******************************************************************************
INHERITANCE EXAMPLE:2
The following program have a parent and child class with their own constructors
and member functions of same name. Parent class also have a paremeterized
constructor.
Child object always call the child constructor first but control goes to parent constructor
and then execute the child constructor.
If you want to check this just give the base keyword like public child():base()
then first it will call default parent constructor then child constructor.
In our example it first calls the parameterized constructors then child's.
The new keyword in print method for redeclaring the same function again in child class.
*******************************************************************************/
using System;
public class parent
{
string s;
public parent() { Console.WriteLine("parent constructor"); }
public parent(string s1) { s=s1; Console.WriteLine(s); }
public void print() { Console.WriteLine("Method from parent class"); }
}
public class child : parent
{
public child():base("from Child") { Console.WriteLine("Child constructor");}
public new void print() { Console.WriteLine("Method from child class");}
public static void Main()
{ // OUTPUT
child c= new child(); // from child
c.print(); // Child constructor
((parent)c).print(); // Method from child class
} // Method from parent class
}
/**************************************************************************************
INHERITANCE EXAMPLE: 3
The Parent class contains a protected string with two member functions
one for return the original string as such, another for replace some character and return
The Child class actually derived from Parent class without any member function.
Through child class object we call the first member function to print string as such, and
call the second member function to print the modified string from the parent class.
The Modified string returned by parent class again altered by the child class and print
the result
****************************************************************************************/
using System;
public class p
{
protected string s="abc@def//xyz";
public string hello()
{
return s;
}
public string m1()
{
string s1;
s1=s.Replace("@","");
return s1;
}
}
public class c : p
{
public static void Main()
{
string s; //OUTPUT
c c1 = new c();
Console.WriteLine(c1.hello()); //abc@def//xyz
s=c1.m1(); // abcdef//xyz
Console.WriteLine(s); // abcdefxyz
s=s.Replace("/","");
Console.WriteLine(s);
}
}
INHERITANCE EXAMPLE: 1
The following program simply have a parent and child class with their own constructors.
Parent class additionaly have one member function. While creating an object for a child
class we will check how it call the parent constructor and member function.
When the control comes to Child Constructor, it first call the parent constructor and
then call the child constructor because of inheritance. Again the method print is not
actually in child class, but it finds it in parent class and execute it.
******************************************************************************/
using System;
public class parent
{
public parent()
{
Console.WriteLine("Parent Constructor");
}
public void print()
{
Console.WriteLine("Member from parent class");
}
}
public class child : parent
{
public child()
{
Console.WriteLine("Child Constructor");
}
public static void Main() /* OUTPUT *****/
{
child c = new child(); // Parent Constructor
c.print();} // Child Constructor
} // Member from parent class
/*******************************************************************************
INHERITANCE EXAMPLE:2
The following program have a parent and child class with their own constructors
and member functions of same name. Parent class also have a paremeterized
constructor.
Child object always call the child constructor first but control goes to parent constructor
and then execute the child constructor.
If you want to check this just give the base keyword like public child():base()
then first it will call default parent constructor then child constructor.
In our example it first calls the parameterized constructors then child's.
The new keyword in print method for redeclaring the same function again in child class.
*******************************************************************************/
using System;
public class parent
{
string s;
public parent() { Console.WriteLine("parent constructor"); }
public parent(string s1) { s=s1; Console.WriteLine(s); }
public void print() { Console.WriteLine("Method from parent class"); }
}
public class child : parent
{
public child():base("from Child") { Console.WriteLine("Child constructor");}
public new void print() { Console.WriteLine("Method from child class");}
public static void Main()
{ // OUTPUT
child c= new child(); // from child
c.print(); // Child constructor
((parent)c).print(); // Method from child class
} // Method from parent class
}
/**************************************************************************************
INHERITANCE EXAMPLE: 3
The Parent class contains a protected string with two member functions
one for return the original string as such, another for replace some character and return
The Child class actually derived from Parent class without any member function.
Through child class object we call the first member function to print string as such, and
call the second member function to print the modified string from the parent class.
The Modified string returned by parent class again altered by the child class and print
the result
****************************************************************************************/
using System;
public class p
{
protected string s="abc@def//xyz";
public string hello()
{
return s;
}
public string m1()
{
string s1;
s1=s.Replace("@","");
return s1;
}
}
public class c : p
{
public static void Main()
{
string s; //OUTPUT
c c1 = new c();
Console.WriteLine(c1.hello()); //abc@def//xyz
s=c1.m1(); // abcdef//xyz
Console.WriteLine(s); // abcdefxyz
s=s.Replace("/","");
Console.WriteLine(s);
}
}
Tuesday, December 16, 2008
Global Assembly
//Create a Global Assembly
/*Publicly sharing functionality among different application.
*Located in Global Assembly Cache (GAC).
*Identified by globally unique name and version.
*Digital signature to ensure that it can't be tampered.
*Get smaller EXE files.
*Dynamic linking, i.e. loading on demand.
GENERATE KEY FILE: - THE STRONG NAME UTILITY (SN)
A tool is used to generate the key file incorporating a Public/Private Key pair.
We need this key pair to create a hash key for every file. The hash key is called
Public Key Token. This token allows the Common Language Runtime (CLR) to recognise
if a file has been tampered or overwritten. If the token doesn't match anymore the
file was modified.
By the time we pass the public/private key file, the private key is used to create
the public key token by encrypting the assembly name and content. The private key is
our secret and stays with us. The public key token is stored along with the public key
inside the Global Assembly's manifest. This process is called Signing the assembly.
The CLR needs the public key to decrypt the token to verify the file but not other way around.
Only with the private key we are able to create the token and nobody else can create it.
A hash token which encrypts the name and content along with the public key is called a Strong Name.
DotNet> sn -k app.snk
Version Control and Linking
The full version description consists of different parts, e.g.:
1:0:1504:18
1:0 Major and minor version
1504 Build
18 Revision
At the top of a source file we can define attributes for the key file and the version we state:
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.0")]
While introducing the sample application we have seen how to compile our assembly to HowDoYouDo.dll.
We are now going to link the DLL with the Assembly Linker (AL) to a Global Assembly incorporating
the key file and version number:
________________
program: ga.cs
________________
using System.Reflection;
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.1")]
public class test
{
public static void t1()
{
System.Console.WriteLine("global assembly");
}
}
Dotnet> csc /t:module /out:bin\ga.dll ga.cs
Dotnet> al /t:library /out:bin\myga.dll bin\ga.dll
[OR]
DotNet> al /t:library /keyfile:app.snk /v:1.0.0.0 /out:bin\myga.dll bin\ga.dll
Load into Assembly Cache - The Global Assembly Cache Utility (GACUTIL)
We load the Global Assembly into GAC by the use of the Global Assembly Cache Utility:
Dotnet>gacutil /i bin\myga.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Assembly successfully added to the cache
The /i switch installs an assembly in the global assembly cache by passing the name.
It is also possible to simply copy the file directly into the GAC folder by the use of
Windows Explorer or by a command shell. Open Windows Explorer an go to C:\WINNT\assembly
and you will find the myga entry there.
/*Publicly sharing functionality among different application.
*Located in Global Assembly Cache (GAC).
*Identified by globally unique name and version.
*Digital signature to ensure that it can't be tampered.
*Get smaller EXE files.
*Dynamic linking, i.e. loading on demand.
GENERATE KEY FILE: - THE STRONG NAME UTILITY (SN)
A tool is used to generate the key file incorporating a Public/Private Key pair.
We need this key pair to create a hash key for every file. The hash key is called
Public Key Token. This token allows the Common Language Runtime (CLR) to recognise
if a file has been tampered or overwritten. If the token doesn't match anymore the
file was modified.
By the time we pass the public/private key file, the private key is used to create
the public key token by encrypting the assembly name and content. The private key is
our secret and stays with us. The public key token is stored along with the public key
inside the Global Assembly's manifest. This process is called Signing the assembly.
The CLR needs the public key to decrypt the token to verify the file but not other way around.
Only with the private key we are able to create the token and nobody else can create it.
A hash token which encrypts the name and content along with the public key is called a Strong Name.
DotNet> sn -k app.snk
Version Control and Linking
The full version description consists of different parts, e.g.:
1:0:1504:18
1:0 Major and minor version
1504 Build
18 Revision
At the top of a source file we can define attributes for the key file and the version we state:
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.0")]
While introducing the sample application we have seen how to compile our assembly to HowDoYouDo.dll.
We are now going to link the DLL with the Assembly Linker (AL) to a Global Assembly incorporating
the key file and version number:
________________
program: ga.cs
________________
using System.Reflection;
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.1")]
public class test
{
public static void t1()
{
System.Console.WriteLine("global assembly");
}
}
Dotnet> csc /t:module /out:bin\ga.dll ga.cs
Dotnet> al /t:library /out:bin\myga.dll bin\ga.dll
[OR]
DotNet> al /t:library /keyfile:app.snk /v:1.0.0.0 /out:bin\myga.dll bin\ga.dll
Load into Assembly Cache - The Global Assembly Cache Utility (GACUTIL)
We load the Global Assembly into GAC by the use of the Global Assembly Cache Utility:
Dotnet>gacutil /i bin\myga.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Assembly successfully added to the cache
The /i switch installs an assembly in the global assembly cache by passing the name.
It is also possible to simply copy the file directly into the GAC folder by the use of
Windows Explorer or by a command shell. Open Windows Explorer an go to C:\WINNT\assembly
and you will find the myga entry there.
Friday, December 12, 2008
Source Assembly
Assemblies:
• Collection of .dll/ .exe files are called as Assembly.
• Collection of class modules as a single .DLL file.
Module: A single .dll / .exe file
Library: Collection of dll files
Assemblies are loaded on demand.
Types: Private and Global Assembly
Just a Small discussion on Why Assemblies???????
if the programming logic is splitted into different logical units say dll's
and developed in different programming languages vb.net,c#.net,vj#.net,....
you are in need to develop an application which simple want to access many dll's at runtime.
Then every dll you have to refer at runtime. Instead if we first group the necessary dll's that we want
it is easy for us to just refer that single dll file. This process is called as Assembly creation.
PRIVATE ASSEMBLY
Location is specified at compile time and probably in current directory
Identified by name and version
GLOBAL ASSEMBLY
Location is specified at compile time and in GAC. C:/windows/assembly
Identified by globally unique name and version
// some of the command line options while creating assemblies
//*************************************************************
/* /t:module -----> target: is a module file (may be a single dll file)
/t:library -----> target: is a library file (collection of dll files)
/t:exe -----> target: is a executable file
/out:bin\pa.dll --> output: file name pa.dll created in bin directory
/r:bin\pa.dll --> reference: at run time pa.dll used as reference
al --> Assembly Linker
*/////////////////////////////////////////////////////////////////////////
TO DEMONSTRATE THE ASSEMBLY CONCEPT WE ARE TRYING TO CREATE THE FOLLOWING FILES AND
THE STEPS IN BRIEF:
1. Create a class1.vb file (vb.net file)
2. Create a class2.cs file (csharp file)
3. Compile class1.vb and create class1.dll
4. Compile class2.cs and create class2.dll
5. combine class1.dll,class2.dll and create pa.dll using utility al (private assembly)
6. create an application program app.cs (csharp file)
where we are calling
class1.method1
class2.method2
7. Test your app.cs and at runtime use pa.dll as reference
steps in detail: (create a directory in c:\windows\temp\) example==> asm.
***************
1. create a class1.vb file
Public Class class1
Public Shared Sub m1() ////////////////shared means static in vb.net
System.Console.WriteLine("vbmethod")
End Sub
End Class
2. create a class2.cs file
public class class2
{
public static void m2()
{
System.Console.WriteLine("csharp method");
}
}
3. Compile class1.vb and get class1.dll as follows:
******* CREATE A BIN DIRECTORY IN C:\WINDOWS\TEMP\ASM ***********
c:\windows\temp\asm> vbc /t:module /out:bin\class1.dll class1.vb
4. Compile class2.cs and get class2.dll as follows:
c:\windows\temp\asm> csc /t:module /out:bin\class2.dll class2.cs
5. Combile two dll files and create a private assembly named pa.dll
c:\windows\temp\asm> al /t:library /out:bin\pa.dll bin\class1.dll bin\class2.dll
6. Create an application to access your private assembly (app.cs)
class test
{
public static void Main()
{
System.Console.WriteLine("Application Main");
class1.m1(); //static members can be directly accessed by class name
class2.m2(); //.....................................................
}
}
7. To compile your app.cs use pa.dll as your reference
c:\windows\temp\asm>csc /t:exe bin\pa.dll /out:bin\app.exe app.cs
8. Now your app.exe is ready in bin directory
9. you can run simply typing app at
c:\windows\temp\asm\bin> app
10. thus we have created a private assembly successfully and accessed.
Suppose if you didnt create an assembly then you have to do the following:::
>>>>>>> csc /t:exe /out:bin\app.exe /addmodule:bin\class1.dll /addmodule:bin\class2.dll app.cs
Here, you have to add all the modules individually .. which is not advisable if u have huge dll's to refer.
• Collection of .dll/ .exe files are called as Assembly.
• Collection of class modules as a single .DLL file.
Module: A single .dll / .exe file
Library: Collection of dll files
Assemblies are loaded on demand.
Types: Private and Global Assembly
Just a Small discussion on Why Assemblies???????
if the programming logic is splitted into different logical units say dll's
and developed in different programming languages vb.net,c#.net,vj#.net,....
you are in need to develop an application which simple want to access many dll's at runtime.
Then every dll you have to refer at runtime. Instead if we first group the necessary dll's that we want
it is easy for us to just refer that single dll file. This process is called as Assembly creation.
PRIVATE ASSEMBLY
Location is specified at compile time and probably in current directory
Identified by name and version
GLOBAL ASSEMBLY
Location is specified at compile time and in GAC. C:/windows/assembly
Identified by globally unique name and version
// some of the command line options while creating assemblies
//*************************************************************
/* /t:module -----> target: is a module file (may be a single dll file)
/t:library -----> target: is a library file (collection of dll files)
/t:exe -----> target: is a executable file
/out:bin\pa.dll --> output: file name pa.dll created in bin directory
/r:bin\pa.dll --> reference: at run time pa.dll used as reference
al --> Assembly Linker
*/////////////////////////////////////////////////////////////////////////
TO DEMONSTRATE THE ASSEMBLY CONCEPT WE ARE TRYING TO CREATE THE FOLLOWING FILES AND
THE STEPS IN BRIEF:
1. Create a class1.vb file (vb.net file)
2. Create a class2.cs file (csharp file)
3. Compile class1.vb and create class1.dll
4. Compile class2.cs and create class2.dll
5. combine class1.dll,class2.dll and create pa.dll using utility al (private assembly)
6. create an application program app.cs (csharp file)
where we are calling
class1.method1
class2.method2
7. Test your app.cs and at runtime use pa.dll as reference
steps in detail: (create a directory in c:\windows\temp\) example==> asm.
***************
1. create a class1.vb file
Public Class class1
Public Shared Sub m1() ////////////////shared means static in vb.net
System.Console.WriteLine("vbmethod")
End Sub
End Class
2. create a class2.cs file
public class class2
{
public static void m2()
{
System.Console.WriteLine("csharp method");
}
}
3. Compile class1.vb and get class1.dll as follows:
******* CREATE A BIN DIRECTORY IN C:\WINDOWS\TEMP\ASM ***********
c:\windows\temp\asm> vbc /t:module /out:bin\class1.dll class1.vb
4. Compile class2.cs and get class2.dll as follows:
c:\windows\temp\asm> csc /t:module /out:bin\class2.dll class2.cs
5. Combile two dll files and create a private assembly named pa.dll
c:\windows\temp\asm> al /t:library /out:bin\pa.dll bin\class1.dll bin\class2.dll
6. Create an application to access your private assembly (app.cs)
class test
{
public static void Main()
{
System.Console.WriteLine("Application Main");
class1.m1(); //static members can be directly accessed by class name
class2.m2(); //.....................................................
}
}
7. To compile your app.cs use pa.dll as your reference
c:\windows\temp\asm>csc /t:exe bin\pa.dll /out:bin\app.exe app.cs
8. Now your app.exe is ready in bin directory
9. you can run simply typing app at
c:\windows\temp\asm\bin> app
10. thus we have created a private assembly successfully and accessed.
Suppose if you didnt create an assembly then you have to do the following:::
>>>>>>> csc /t:exe /out:bin\app.exe /addmodule:bin\class1.dll /addmodule:bin\class2.dll app.cs
Here, you have to add all the modules individually .. which is not advisable if u have huge dll's to refer.
Wednesday, December 10, 2008
Assemblies
Assembly: Collection of .dll/ .exe files are called as Assembly
you can also say collection of modules as an Assembly.
Module: A single .dll / .exe file
Library: Collection of .dll/ .exe
we discussed that .net overcome the 'dll hell' problem through versioning and signature. Also provides Language Integration.
Assume that we split the program into different logical units say modules developed in different .NET languages C#,VB,VJ#,MC++,Perl.NET,Python.NET,........At runtime how to combine all modules for a particular application.
vb c# vj# PERL.NET Python.NET... SOURCE
| | | | |
.dll.dll.dll .dll .dll ... MODULE
|___|____|______|_________|
|
|
.DLL .. LIBRARY
(ASSEMBLY)
you can also say collection of modules as an Assembly.
Module: A single .dll / .exe file
Library: Collection of .dll/ .exe
we discussed that .net overcome the 'dll hell' problem through versioning and signature. Also provides Language Integration.
Assume that we split the program into different logical units say modules developed in different .NET languages C#,VB,VJ#,MC++,Perl.NET,Python.NET,........At runtime how to combine all modules for a particular application.
vb c# vj# PERL.NET Python.NET... SOURCE
| | | | |
.dll.dll.dll .dll .dll ... MODULE
|___|____|______|_________|
|
|
.DLL .. LIBRARY
(ASSEMBLY)
Subscribe to:
Posts (Atom)