February 14, 2002

Reallocating Memory Pointers

In any decent sized application, one of the most common activities is string manipulation at one level or another. One of the most common problems with string manipulation is the reallocation of memory strings depending on the size of input. The old school of memory allocation comprising of malloc and

Check the Validity of the Memory Allocated to a Calling Process

Some of the most irritating and difficult-to-trace bugs are the ones relating to uninitialized or inaccessible memory locations. This problem becomes especially severe when dealing with parameters that are pointers. If the pointers happen to be NULL or dangling, they might lead to data corruption and ultimate demise of the

Reading from a Property File

Sometimes it’s useful to get information from a text property file, especially when you want to change values inside classes without recompiling them every time. A simple (and fast) way to obtain external information from a file is: java.io.FileInputStream fis; String fileName = “config.prop”; java.util.Properties configProperties = null; try {

Run Java Applications Using the Many JARs File

You can do this without using the classpath directive at the command line. How? Easy! Just write a launcher! Here’s the code: /* Allow you to type “java QuickRunner” instead of “java -classpath foo.jar;bar.jar;. MyApp*/public class QuickRunner{ public static void main(String args[]) { try { String defaultClassPath =System.getProperty(“java.class.path”); String fileSep

Send an HTML Email Without Using the JavaMail API

Send an email without using JavaMail API, by using the Java Core packages(java.net.*;java.io.*) to pass three parameters. The first parameter is the SMTP mail server, the second parameter is the Sender Address (From address), and the third parameter is the Recipent Address (To Address). Here’s the code: import java.net.Socket;import java.io.*;public

Read NT Environment Variables from a Java Application

Start the JVM with the “-D” switch to pass properties to the application and read them with the System.getProperty() method. SET myvar = Hello world Set myothervar = nothing java -Dmyvar=”%myvar%” -Dmyothervar=”%myothervar%” myClass Then, in myClass: String myvar = System.getProperty(“myvar”); String myothervar = System.getProperty(“myothervar”); If you don’t know the name

Capture a Reference to a UserControl

Many programmers are familiar with declaring an object variable in class modules and other places to capture events from a form and handle them in a generic way: Private WithEvents m_Form As Form It might be useful to do this for user controls as well, but you need a reference

No more posts to show