Thursday, June 30, 2005
Typed datasets in ADO.NET
.NET SDK help states the following:
A typed DataSet is a class that derives from a DataSet. As such, it inherits all the methods, events, and properties of a DataSet. Additionally, a typed DataSet provides strongly typed methods, events, and properties. This means you can access tables and columns by name, instead of using collection-based methods. Aside from the improved readability of the code, a typed DataSet also allows the Visual Studio .NET code editor to automatically complete lines as you type.
Additionally, the strongly typed DataSet provides access to values as the correct type at compile time. With a strongly typed DataSet, type mismatch errors are caught when the code is compiled rather than at run time.
--------------------------------------------------
So I understand that one of the advantages of using typed datasets is that you will catch typos in table and column names at compile time not run time as with un-typed data sets. In fact using intellisense eliminates those typos all together..
But during the earliers states of the project. when the database may keep changing according to requirements, U would need to synch the database with the code everytime !!!...Anyway, my personal belief is that all errors relating to column names etc. should be captured during unit-testing. (Or is this impossible in a mega-project and the overhead of manually creating dataset schemas would be justified?)
What is FCAPs in network management?
It is an acronym for Faults, Configuration, Accounting, Performance, Security, the categories into which the model breaks the various network management tasks.
Wednesday, June 29, 2005
How to display all TCP/UDP connections on Ur machine?
Also U can find out the port used on Ur PC for a service.
e.g. if U telnet to some machine U know that U are using port '23' on that machine, but what is the port on Ur machine?
Just type 'netstat -n' on the command prompt.
"Tera Term" terminal client
I desparately wanted some tool which would automate this for me...i.e. pass commands to the server thru telnet, wait for output etc.
"Tera Term" is a cool utility that allows U to write scripts using a simple language..(It took me just 5 mins to get the basic commands) The scripts have a *.ttl extension.
Cool handy tool...A must have :)
Tuesday, June 28, 2005
Shortcut to reach etc\hosts on a windows machine
I found this damn handy bcoz I often used to forget the full path where I can put DNS entries.
Diff btw 'terminal' and 'console' in Solaris/Linux ?
Monday, June 27, 2005
Circular project dependency in Java and .NET
But VS.NET can automatically take care of such circular dependencies...The trick is very simple. Just add both the projects to a common solution. And in the 'Add Reference' option, do not add the DLL directly, but add the 'Project' as a reference. (3rd Tab in Add Reference window)
The VS.NET environment automatically takes care of circular dependencies.
Similarly in Java, the javacc compiler automatically takes care of circular dependencies. :)
Thursday, June 23, 2005
File sharing btw a Java and a non-Java application
The FileLock class, which is part of the java.nio.channels package, represents a file lock. You can use a file lock to restrict access to a file from multiple processes. In addition, you have the option of restricting access to an entire file or just a small region of it. A file lock is either shared or exclusive. A shared lock supports read access from multiple processes, while an exclusive lock is typically used for writing. Because a lock is at the file level, you should not use it to restrict access to a file from multiple threads in a single process. If you use a file lock in multiple threads, none of the threads would be restricted from accessing the file. Only external processes are restricted.
http://java.sun.com/developer/JDCTechTips/2002/tt0924.html
Themes in pluggable Look & Feel Swing
The abstract javax.swing.plaf.metal.MetalTheme class offers about fifty settings that let you customize the fonts and colors of the Swing components. By creating different subclasses, you can swap many of the properties at once when you change the look and feel.
MetalTheme theme = new MyCustomTheme();
MetalLookAndFeel.setCurrentTheme(theme);
UIManager.setLookAndFeel(new MetalLookAndFeel());
For an example of theme usage, try out the Metalworks demonstration that comes with the Java 2 SDK distribution. Simply change the current directory to the demo/jfc/Metalworks directory, and run the demonstration with the following command:
java -jar Metalworks.jar
Wednesday, June 22, 2005
What is a MAC address?
Basically the MAC address is used in the Data-link layer and the IP address is used in the Network layer. For e.g. Ethernet uses MAC address to find other hosts.
The ARP protocol does the mapping btw the MAC address and the IP address.
Tutorials for networking concepts
http://www.learntosubnet.com/
http://www.learntcpip.com/TCPIP/default.htm
Friday, June 17, 2005
Simple way to wait in a program or stop a program from exiting.
For Console applications, we can just block with a Console.Read() method.
For other applications, we tend to write a infinite loop like -- while(true){}
But the above statement keeps on wasting a lot of computational cycles.
A much cleaner and cool approach would be :--
java.lang.Object sync = new java.lang.Object();
synchronized (sync) { sync.wait(); }
Why wait() and notify() should be inside a synchronized block?
This is required by the language, and ensures that wait and notify are properly serialized. In practical terms, this eliminates race conditions that could cause the "suspended" thread to miss a notify and remain suspended indefinitely.
Wednesday, June 15, 2005
XSD.exe -- A cool tool in .NET SDK
In the .NET SDK, there is a cool tool called XSD.exe that can take a sample XML file and automatically generate a schema-definition file for it.
The following command generates an XML schema from myFile.xml and saves it to the specified
directory.
xsd myFile.xml /outputdir:myOutputDir
Monday, June 13, 2005
What is a race condition? How is it different from a dead-lock?
In Java, the Object class provides a collection of methods — wait, notify, and notifyAll — to help threads wait for a condition and notify other threads when that condition changes.
Asynchronous programming in .NET
U can make a async call to any method and what amazed me was the simplicity !!!
We just have to make use of the magic of delegates...
Define a delegate with the same signature as the method you want to call; the common language runtime automatically defines BeginInvoke and EndInvoke methods for this delegate, with the appropriate signatures.
The BeginInvoke method is used to initiate the asynchronous call. It has the same parameters as the method you want to execute asynchronously, plus two additional parameters that will be described later. BeginInvoke returns immediately and does not wait for the asynchronous call to complete. BeginInvoke returns an IasyncResult, which can be used to monitor the progress of the call.
The EndInvoke method is used to retrieve the results of the asynchronous call. It can be called any time after BeginInvoke; if the asynchronous call has not completed, EndInvoke will block until it completes. The parameters of EndInvoke include the out and ref parameters (
So after making a Async call, we have the following options:
- Do something and then block till the call completes.
- Poll continously to see it call is complete
- Assign a call-back delegate (AsyncCallBack)
I found this feature of .NET really really cool...especially in my threading applications.
What's the difference between the 'out' and the 'ref' parameters in .NET?
An argument passed to a ref parameter must first be initialized. Compare this to an 'out ' parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.
Now the big question is why did Microsoft go thru the pain of having both 'ref' and 'out' ?
The answer is in the snippet below:
The two parameter passing modes addressed by out and ref are subtly different, however they are both very common. The subtle difference between these modes leads to some very common programming errors.
These include:
not assigning a value to an out parameter in all control flow paths
not assigning a value to variable which is used as a ref parameter
Because the C# language assigns different definite assignment rules to these different parameter passing modes, these common coding errors are caught by the compiler as being incorrect C# code.
The crux of the decision to include both ref and out parameter passing modes was that allowing the compiler to detect these common coding errors was worth the additional complexity of having both ref and out parameter passing modes in the language.
C# delegates Vs Java Listeners
But after understanding delegates, I have realised that delegates are a bit more flexible than Java Listeners. By using a delegate, U are free to use any method of any object- just the signature of the method should match.
They allow easy binding of event handlers and other callback mechanisms, without the use of a separate class implementing a specific listener interface (which is the Java approach for callbacks).
Basically, instead passing a callback function via an object of known interface that both communicating parties agree on, delegates only need the two parties to use the same function signature
An interesting article regarding this can be found at:
http://blog.monstuff.com/archives/000037.html#more
Thursday, June 09, 2005
Can we convert a Java object into a COM component?
http://adams.patriot.net/~tvalesky/msjava.html
What's the equivalent of EJB's in Windows (.NET)
Well, the answer is YES...
COM+ offer all the same services that a EJB container does. So instead of beans, U write "serviced components".
COM+ services are available on the MTS (Microsoft Transaction Server) plaform and offer the following services:
- Transaction Management
- Object Pooling
- On-Demand (JIT) Object Activation
- Security Management etc.
Tuesday, June 07, 2005
How to debug the OnStart() method of a service in .NET?
First, the important concept is that U can have more than one service running inside a process i.e. 2 or 3 services can share the same process. (Remember thats why we have 2 classes: ServiceProcessInstaller and ServiceInstaller)
So follow the following steps:
- Make a dummy service under the same process as Ur main service
- Start the dummy service and attach the debugger to the process
- Put a break-point in the OnStart() method of Ur main service.
- Then start Ur main service... The break point will be hit ....Yahooooo.....
Monday, June 06, 2005
Tool to measure cyclomatic complexity in Java
http://www.scitools.com/uj.html
ACID rules for transactions
- Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions)
- Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t)
- Isolated (no transaction sees the intermediate results of the current transaction)
- Durable (the values persist if the data had been committed even if the system crashes right after).
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
Thursday, June 02, 2005
Events and delegates in .NET
Another imp. difference is that invoking an event can only be done from within the class that declared the event, whereas a delegate field can be invoked by whoever has access to it.
For more details check out:
http://blog.monstuff.com/archives/000040.html
List of common ports
http://www.iana.org/assignments/port-numbers
0 to 1023
1/tcp: TCP Multiplexor
7/tcp: ECHO protocol
7/udp: ECHO protocol
9/tcp: DISCARD protocol
9/udp: DISCARD protocol
13/tcp: DAYTIME protocol
17/tcp: QOTD (Quote of the Day) protocol
19/tcp: CHARGEN (Character Generator) protocol
19/udp: CHARGEN protocol
20/tcp: FTP (File Transfer Protocol) - data port
21/tcp: FTP - control (command) port
22/tcp: SSH (Secure Shell) - used for secure logins, file transfers (scp, sftp) and port forwarding
23/tcp: Telnet protocol - unencrypted text communications
25/tcp: SMTP (Simple Mail Transfer Protocol) - used for sending E-mails
53/tcp: DNS (Domain Name Server)
53/udp: DNS
67/udp: BOOTP (BootStrap Protocol) server; also used by DHCP (Dynamic Host Configuration Protocol)
68/udp: BOOTP client; also used by DHCP
69/udp: TFTP (Trivial File Transfer Protocol)
70/tcp: Gopher protocol
79/tcp: Finger protocol
80/tcp: HTTP (HyperText Transfer Protocol) - used for transferring web pages
88/tcp: Kerberos - authenticating agent
109/tcp: POP2 (Post Office Protocol version 2) - used for retrieving E-mails
110/tcp: POP3 (Post Office Protocol version 3) - used for retrieving E-mails
113/tcp: ident - old server identification system, still used by IRC servers to identify its users
119/tcp: NNTP (Network News Transfer Protocol) - used for retrieving newsgroups messages
123/udp: NTP (Network Time Protocol) - used for time synchronization
139/tcp: NetBIOS
143/tcp: IMAP4 (Internet Message Access Protocol 4) - used for retrieving E-mails
161/udp: SNMP (Simple Network Management Protocol)
179/tcp: BGP (Border Gateway Protocol)
389/tcp: LDAP (Lightweight Directory Access Protocol)
443/tcp: HTTPS - HTTP over SSL (encrypted transmission)
445/udp: Microsoft-DS SMB - used for file sharing
514/udp: syslog protocol - used for system logging
540/tcp: UUCP (Unix-to-Unix CoPy protocol)
636/tcp: LDAP over SSL (encrypted transmission)
666/tcp: id Software's DOOM multiplayer game played over TCP
993/tcp: IMAP4 over SSL (encrypted transmission)
995/tcp: POP3 over SSL (encrypted transmission)
1024 to 49151
1080/tcp: SOCKS proxy
1352/tcp: IBM Lotus Notes/Domino RCP
1433/tcp: Microsoft SQL database system
1434/tcp: Microsoft SQL Monitor
1434/udp: Microsoft SQL Monitor
1984/tcp: Big Brother - network monitoring tool
3128/tcp: HTTP used by web caches and the default port for the Squid cache
3306/tcp: MySQL database system
3389/tcp: Microsoft Terminal Server (RDP)
5190/tcp: AOL and AOL Instant Messenger
5222/tcp: XMPP/Jabber - client connection
5269/tcp: XMPP/Jabber - server connection
5432/tcp: PostgreSQL database system
6000/tcp: X11 - used for X-windows
6667/tcp: IRC (Internet Relay Chat)
8000/tcp: iRDMI - often mistakenly used instead of port 8080
8080/tcp: HTTP Alternate (http-alt) - used when running a second web server on the same machine (the other is in port 80), for web proxy and caching server, or for running a web server as a non-root user. Default port for Jakarta Tomcat.
8118/tcp: Privoxy web proxy - advertisements-filtering web proxy
49152 to 65535
Unregistered Ports
These are ports that may be in common use, but that are not formally registered with IANA. Where the use conflicts with a registered use, the notation CONFLICT is used.
1337/tcp: WASTE Encrypted File Sharing Program
1521/tcp: Oracle database default listener - CONFLICT with registered use: nCube License Manager
2082/tcp: CPanel's default port - CONFLICT with registered use: Infowave Mobility Server
2086/tcp: Web Host Manager's default port - CONFLICT with registered use: GNUnet
5000/tcp: Universal plug-and-play (UPnP) - Windows network device interoperability; CONFLICT with registered use: commplex-main
5223/tcp: XMPP/Jabber - default port for SSL Client Connection
5800/tcp: VNC remote desktop protocol - for use over HTTP
5900/tcp: VNC remote desktop protocol - regular port
6881/tcp: BitTorrent - port often used
6969/tcp: BitTorrent tracker port - CONFLICT with registered use: acmsoda
27960/udp: (through 27969) id Software's Quake 3 and Quake 3 derived games
31337/tcp: Back Orifice - remote administration tool (often Trojan horse) ("31337" is the "Leet speak" version of "Elite")
Wednesday, June 01, 2005
Use of Reflection in .NET to create classes at runtime (from scratch)
be used to construct and "emit" it. The classes found in the System
.Reflection.Emit namespace allow metadata for new types to be generated
in memory and used at runtime. In fact, you can dynamically create
an entire assembly, its classes and methods, and the IL code behind them.
The "in memory" assembly can then be used by other applications.
Good examples and articles can be found at :
http://geekswithblogs.net/johnsPerfBlog/articles/49829.aspx
http://olondono.blogspot.com/2008/02/creating-code-at-runtime.html
http://www.code-magazine.com/Article.aspx?quickid=0301051
Another cool example that reads a text file and compiles and executes the class is available at:
http://vbcity.com/blogs/jatkinson/archive/2010/04/24/dynamically-read-compile-and-run-source-code-from-a-text-file.aspx