open thoughts

XML Theory…

by nikhil on Oct.02, 2009, under Theory, XML

Advantages of XML

  1. Simplifies Data Sharing: XML data is stored in plain text format. This provides a software- and hardware-independent way of storing data.
  2. Simplifies Data Transport: With XML, data can easily be exchanged between incompatible systems.
  3. Since XML is independent of hardware, software and application, XML can make your data more available and useful. Different applications can access your data, not only in HTML pages, but also from XML data sources.
  4. Here are some examples:
    • XHTML the latest version of HTML
    • WSDL for describing available web services
    • WAP and WML as markup languages for handheld devices
    • RSS languages for news feeds
    • RDF and OWL for describing resources and ontology
    • SMIL for describing multimedia for the web
  5. XML Elements are Extensible: XML elements can be extended to carry more information.

XML Syntax rules:

  1. XML Documents Must Have a Root Element
  2. All XML Elements Must Have a Closing Tag
  3. XML Tags are Case Sensitive
  4. XML Elements Must be Properly Nested
  5. XML Attribute Values Must be Quoted
  6. Entity References

    &lt;       <   less than
    &gt;      >   greater than
    &amp;   &   ampersand 
    &apos;   ‘   apostrophe
    &quot;   "   quotation mark

XML attributes:

Attributes provide additional information about elements. Disadvantages of attributes:

  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes)
  • Attributes are difficult to read and maintain.

moral of attribute story – use elements instated of attributes.

XML Namespaces and name conflicts

Name conflicts in XML can easily be avoided using a name prefix.
<h:table>
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>
<f:table>
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>

XML Namespaces provide a method to avoid element name conflicts.

  • xmlns attribute for element.
    When using prefixes in XML, a so-called namespace for the prefix must be defined.
    The namespace is defined by the xmlns attribute in the start tag of an element.
    The namespace declaration has the following syntax. xmlns:prefix="URI"
    <root>
    <h:table xmlns:h="http://www.w3.org/TR/html4/">
      <h:tr>
        <h:td>Apples</h:td>
        <h:td>Bananas</h:td>
      </h:tr>
    </h:table>
    <f:table xmlns:f="http://www.w3schools.com/furniture">
      <f:name>African Coffee Table</f:name>
      <f:width>80</f:width>
      <f:length>120</f:length>
    </f:table>
    </root>
  • Default Namespaces
    Defining a default namespace for an element saves us from using prefixes in all the child elements.
    <table xmlns="http://www.w3.org/TR/html4/">
      <tr>
        <td>Apples</td>
        <td>Bananas</td>
      </tr>
    </table>

CDATA

XML parsers normally parse all the text in an XML document. The term CDATA is used about text data that should not be parsed by the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser interprets it as the start of a new element.
"&" will generate an error because the parser interprets it as the start of an character entity.
Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA.
Everything inside a CDATA section is ignored by the parser.
A CDATA section starts with "":

<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
  {
    return 1;
  }
else
  {
    return 0;
  }
}
]]>
</script>

2 Comments :, more...

Object Oriented Programming Fundamentals…

by nikhil on Oct.01, 2009, under OOPs, Theory

Everything is OOP is grouped as self sustainable objects; hence you gain re-usability by means of four object oriented programming concepts.

Advantages of OOP
Bundling code into individual software objects provides a number of benefits, including:

  1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.
  2. Information-hiding: By interacting only with an object’s methods, the details of its internal implementation remain hidden from the outside world.
  3. Code re-use: If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement/test/debug complex, task-specific objects, which you can then trust to run in your own code.
  4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

Concepts in OOP

  1. Class
  2. Object
  3. Inheritance
  4. Encapsulation or data hiding
  5. Abstraction
  6. Polymorphism

  1. Class
    A class is the blueprint from which individual objects are created.
  2. Object
    Real-world objects share two characteristics: They all have state and behaviour. An object stores its state in fields(variables in some programming languages) and exposes its behaviour through methods (functions in some programming languages).
  3. Inheritance
    Object-oriented programming allows classes to inherit commonly used state and behaviour from other classes. Each class is allowed to have one direct superclass, and each superclass has the potential for an unlimited number of subclasses.

    Sealed Classes:
    The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. A sealed class cannot also be an abstract class.

  4. Encapsulation or data hiding
    access specifiers determine who can use the definitions that follow. public means the following definitions are available to everyone. The private keyword, on the other hand, means that no one can access those definitions except you, the creator of the type, inside member functions of that type. private is a brick wall between you and the client programmer. If someone tries to access a private member, they’ll get a compile-time error. protected acts just like private, with the exception that an inheriting class has access to protected members, but not private members.
  5. Abstraction
    As per dictionary ‘abstraction is a general idea rather than a specific example”. Putting it in other word; abstraction is an emphasis on the idea, qualities and properties rather than the particulars (a suppression of detail). The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.
    • Abstract class:
      Abstract classes, which declared with the abstract keyword, cannot be instantiated. It can only be used as a super-class for other classes that extend the abstract class. Abstract class is the concept and implementation gets completed when it is being realized by a subclass. In addition to this a class can inherit only from one abstract class (but a class may implement many interfaces) and must override all its abstract methods/ properties and may override virtual methods/ properties.
    • Interface:
      In summary the Interface separates the implementation and defines the structure, and this concept is very useful in cases where you need the implementation to be interchangeable. Apart from that an interface is very useful when the implementation changes frequently. Some say you should define all classes in terms of interfaces, but I think recommendation seems a bit extreme.

      Interface can be used to define a generic template and then one or more abstract classes to define partial implementations of the interface. Interfaces just specify the method declaration (implicitly public and abstract) and can contain properties (which are also implicitly public and abstract). Interface definition begins with the keyword interface. An interface like that of an abstract class cannot be instantiated.

      If a class that implements an interface does not define all the methods of the interface, then it must be declared abstract and the method definitions must be provided by the subclass that extends the abstract class. In addition to this an interfaces can inherit other interfaces. .Net support multiple implementations, the concept of implicit and explicit implementation provide safe way to implement methods of multiple interfaces by hiding, exposing or preserving identities of each of interface methods, even when the method signatures are the same.

      Theoretically a class emphasis the idea of encapsulation, while an interface emphasis the idea of abstraction (by suppressing the details of the implementation).
      Abstract class Interface
      Interface definition begins with a keyword interface so it is of type interface Abstract classes are declared with the abstract keyword so it is of type class
      Interface has no implementation, but they have to be implemented. Abstract class’s methods can have implementations and they have to be extended.
      Interfaces can only have method declaration (implicitly public and abstract) and fields (implicitly public static) Abstract class’s methods can’t have implementation only when declared abstract.
      Interface can inherit more than one interfaces Abstract class can implement more than one interfaces, but can inherit only one class
  6. Polymorphism
    In OOP the polymorphisms is achieved by using many different techniques named method overloading, operator overloading and method overriding.
    Assume that the Class A implements a virtual method M and classes B and C that are derived from A override the virtual method M. When B is cast to A a call to the method M from A is dispatched to B. Similarly when C is cast to A a call to M is dispatched to C. The decision on exactly which method to call is delayed until runtime.
Leave a Comment :, more...

Good reference for Object Oriented Programming

by nikhil on Sep.28, 2009, under OOPs, Theory

I found following reference for object oriented programming. This link covers all basic very nicely.

http://www.codeproject.com/KB/architecture/oop_concepts_and_manymore.aspx

Thanks to Bhushan Rane for giving me this link.

Leave a Comment :, more...

WinSock2 Client Server in VC++

by nikhil on Jul.06, 2009, under Networking, VC++, windows

I was working with OpenSSL and VC++, I found that there are very few references available which tell us how to implement OpenSSL through VC++. But real thing missing  is Working Client server in VC++ which will communicate through OpenSSL. So Writing one

Lets start with WinSock2 client server.

VC++ Code details

  1. VS2005

VC++ references required:
(From MSDN)Use the Winsock API by including the Winsock 2 header files. The Winsock2.h header file contains most of the Winsock functions, structures, and definitions. The Ws2tcpip.h header file contains definitions introduced in the WinSock 2 Protocol-Specific Annex document for TCP/IP that includes newer functions and structures used to retrieve IP addresses.

  1. Add #include <winsock2.h> and #include <ws2tcpip.h> in code
  2. Add build environment links to the Winsock Library file WS2_32.lib

Source code : click this link WinSock2-BasicClientServer

WinSock2 Server

We need to follow following steps to implement Server

  1. Initialize Winsock.
  2. Create and Bind the socket.
  3. Listen on the socket for a client.
  4. Accept a connection from a client.
  5. Receive and send data.
  6. Disconnect.

WinSock2 Client

  1. Initialize Winsock.
  2. Create a socket.
  3. Connect to the server.
  4. Send and receive data.
  5. Disconnect.

This is working fine but no fun. Lets make it working in threads.

Net will be client server communicating with each other in different threads; like read thread and write threads.

Leave a Comment :, , , , more...

sorry for not reading comments

by nikhil on Jun.24, 2009, under Announcements

I feel very sorry for not reading comments posted by people on my blog. Some bad ass software activated on blog blocked lot of comments. Thx people for your comments. I am really excited by your appreciation. Trust me new posts are on their way.

2 Comments : more...

Small command to open windows share

by nikhil on Jun.18, 2009, under system, windows

Command is “net use”. This will open the shared folder

net use \\10.70.0.177\software /user:doamin\nikhil

If this command is used with * it will map drive to shared folder.

net use * \\10.70.0.177\software /user:doamin\nikhil

1 Comment :, , more...

Crazy idea…

by nikhil on Jun.11, 2009, under C#, RFC, windows

I am getting bored while working on daily ‘shit’. nothing really drives me. In office it work i do for last 2 year; so I know how to find solutions for problems. It is not very challenging coding part. So I got and crazy idea.

I will implement RFCs one by one in C# code.

I am choosing C# as this is easy to use and I want to do some heavy coding in C#. Lets see how this work out.

I am staring on http://www.rfc-editor.org/rfcxx00.html form top to bottom.

1 Comment :, , more...

Windows 7 RC1 Review for hp nx7400 laptop

by nikhil on May.29, 2009, under Review, windows

I just installed windows 7 RC on my laptop.  This is review

Device drivers status

Hardware Working status
Display Working (Auto detected)
Dual Screens Working (Auto detected)
Sound Working (Auto detected)
LAN Broadcom 440x 10/100 Working (Auto detected)
WLAN Broadcom 110 Working (Auto detected)
Bluetooth Not Working by default.

GUI experience

GUI Very good
Speed of OS Very good
Networking Not very impressive
Backward GUI compatibility Bad

Overall rating 7.5/10

First week

1. Installed Software –Visual Studio 2008.
2. Not even single crash.
3. No lags.
4. Lot of Updates :( as this is RC this is acceptable.

1 Comment :, , more...

Building OpenSSL on Windows using Visual C++ (6.0)

by nikhil on May.13, 2009, under OpenSSL, VC++, system, windows

Hi its all about building OpenSSL on Windows using Visual C++ (6.0)

Requirement,
Visual c++ 6.0
VC Service pack 5 (not a 6)
Visual C++ 6.0 Processor Pack
Active Perl

Pre build info :
Package(general source) : http://www.openssl.org/source/
Unpack to: C:\build\openssl
Installation folder: C:\www\openssl ( use command mkdir C:\www\openssl)
openssl.cnf location : C:\www\openssl\bin

Build:
1. cd /d C:\build\openssl2
2. perl Configure enable-camellia –openssldir=C:/www/openssl VC-WIN32
3. ms\do_masm
4. nmake -f ms\ntdll.mak

Test the build:
nmake -f ms\ntdll.mak test

Install:

nmake -f ms\ntdll.mak install

Add OpenSSL to the PATH:
Set PATH under Start » Settings » Control Panel » System » Advanced » Environment Variables » System variables
Add C:\www\openssl\bin in Path verialbe

Reboot the machine (for Environment Variables):
Test installation:
1. openssl version
2. openssl s_client -connect www.openssl.org:443
3. GET / HTTP/1.0 [Enter twice]

For more info visit http://www.devside.net/guides/windows/openssl

4 Comments :, , , , , more...


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...