devxlogo

Tip Bank

Achieve Syntax Brevity with Anonymous Classes and Instance Initializers

The first listing here, which may look more familiar, is considerably longer than the second listing, even though they’re essentially equivalent. Listing 1.List friends = new ArrayList();friends.add(“Ben”);friends.add(“Kiran”);friends.add(“….”); You can replace

Send Email Using a DNS Server

An easy way to send mail from .NET is to use the DnsMailClient class. Here’s some sample code in both C# and VB: // in C#MailMessage msg = new MailMessage();msg.From

Adding Workdays to a Date

This example adds the days of the week and the weeks separately. You never iterate over the loop more then four times regardless of the number of days being added.

Execute DOS Commands from a Java Program

Rather unintuitively, you can’t run DOS commands directly by specifying Runtime.getRuntime().exec(dosCommand) in Java. Instead, to execute a DOS command (such as DIR, or RD) from a Java program, you need