RSS Feed for ProgrammingCategory: Programming

MessagingToolkit – SMS Library Community Edition »

I just released the community edition of MessagingToolkit messagingtoolkit is a .NET C# messaging library that can be used to send and receive messages using any ETSI 07.05 compliant GSM modem or phone handset connected to the PC serial port through serial cable, infrared or bluetooth. Some of the features of the library Send SMS [...]

Concurrency Testing Tool »

CHESS is a tool for finding and reproducing Heisenbugs in concurrent programs. CHESS repeatedly runs a concurrent test ensuring that every run takes a different interleaving. If an interleaving results in an error, CHESS can reproduce the interleaving for improved debugging. CHESS is available for both managed and native programs.

Java: Predicate in Commons Collection »

Predicate in Commons Collection is very useful for logic evaluation. The available predicates should fulfills most of your logic requirements, or you can even write your own custom predicate. AllPredicate AndPredicate AnyPredicate EqualPredicate ExceptionPredicate FalsePredicate IdentityPredicate InstanceofPredicate NonePredicate NotNullPredicate NotPredicate NullIsExceptionPredicate NullIsFalsePredicate NullIsTruePredicate NullPredicate OnePredicate OrPredicate TransformedPredicate TransformerPredicate, TruePredicate UniquePredicate You can combine predicates together [...]

C#: Retrieving and Sorting COM Ports »

In .NET, it is easy to retrieve all existing COM ports and sort them accordingly string[] portNames = SerialPort.GetPortNames(); var sortedList = portNames.OrderBy(port => Convert.ToInt32(port.Replace(“COM”, string.Empty))); foreach (string port in sortedList) { Console.WriteLine(port); }

iBatis: SQLNestedException:Cannot get a connection, pool error Timeout waiting for idle object »

When this happened, and you are sure that the connection pool is actually enough to handle all the transactions, then most probably that there is a connection leakage lying within your application. E.g. the connection is not closed properly. One example in iBATIS is that you start a transaction, but does not end it. sqlMapClient.startTransaction(); [...]

.NET: Detect String Encoding »

Here is a simple way to detect if your content is ASCII or Unicode public void CheckForEncoding(string content) { int i = 0; for (i = 1; i <= content.Length; i++) { int code = Convert.ToInt32(Convert.ToChar(content.Substring(i – 1, 1))) ; if (code < 0 || code > 255) { Console.WriteLine(“Unicode”); return; } } Console.WriteLine(“ascii”); }

Java: Alter Oracle Session Information using iBATIS »

There are times that you may want to alter Oracle session information. If you are using iBATIS, this can be done the following way Create the update statement. E.g. <?xml version=”1.0″ encoding=”UTF-8″ ?> <!DOCTYPE sqlMap PUBLIC “-//ibatis.apache.org//DTD SQL Map 2.0//EN” “http://ibatis.apache.org/dtd/sql-map-2.dtd” > <sqlMap namespace=”TEST”> <update id=”update_sort_area_size” parameterClass=”int”> alter session set sort_area_size=#value# </update>   <update id=”update_sort_area_retained_size” [...]

.NET String Enumeration »

Normally you cannot use string in enum. However you can bypass using a trick, as shown below. /// <summary> /// Response expected from the gateway /// </summary> public enum Response { /// <summary> /// No respons expected, just return the result /// </summary> [StringValue("NONE")] None, /// <summary> /// Error response /// </summary> [StringValue("ERROR")] Error, /// [...]

Performance Tuning for Embedded System »

Performance tuning for embedded system is quite different from conventional programming Avoid Creating Objects Use Native Methods Prefer Virtual Over Interface Prefer Static Over Virtual Avoid Internal Getters/Setters Cache Field Lookups Declare Constants Final Use Enhanced For Loop Syntax With Caution Avoid Enums Use Package Scope with Inner Classes Avoid Float Some Sample Performance Numbers [...]

.NET: Dynamic Object Factory »

This is a dynamic way of creating different object factory for different types of gateway, which I used to connect to different kinds of servers. This is the interface, IGatewayFactory using System; using System.Collections.Generic; using System.Linq; using System.Text;   namespace MessageGateway.Core.Base { /// <summary> /// Gateway factory interface /// </summary> /// <typeparam name=”T”>Derived gateway factory</typeparam> [...]

Speeding Up Your Website »

Make Fewer HTTP Requests Use a Content Delivery Network Add an Expires or a Cache-Control Header Gzip Components Put Stylesheets at the Top Put Scripts at the Bottom Avoid CSS Expressions Make JavaScript and CSS External Reduce DNS Lookups Minify JavaScript and CSS Avoid Redirects Remove Duplicate Scripts Configure ETags Make Ajax Cacheable Flush the [...]

Java: Optimize Logging for Better Performance »

Logging is necessary for troubleshooting purpose but excessive logging impacts performance. In most application, if you need high performance, you have to reduce the amount of logging. If logging cannot be avoided, then you should try to output as much information as possible during a single logging operation, instead of logging multiple times consecutively. E.g., [...]

Configure Different Database Settings for Different JVMs in iBATIS »

I have a common class which is used to create the SqlMapClient  object to access the database. The class is used by multiple Java processes. The problem is that I want each Java process to have specific database settings, and I do not want to maintain redundant information in different SQL mapping configuration files, e.g. [...]

Web Service Basic »

REST The Representational State Transfer (REST) is a web architectural style presented by Roy Fielding back in 2000 in his doctoral thesis. The basic idea of REST is the full exploitation of the HTTP protocol, in particular:It focuses on Resources, that is, each service should be designed as an action on a resource. It takes [...]

Commons Logging Performance »

This is what I have observed when I was putting some logging code in my Java application. The performance when I was using Commons Logging with Log4j is much slower than I was using Log4j alone. This is strange as I was expecting Commons Logging as just a thin wrapper around Log4j.

A Multiplatform Programming Language »

haXe (pronounced as hex) is an open source programming language. While most of the other languages are bound to their own platform (Java to the JVM, C# to .Net, ActionScript to the Flash Player), haXe is a multiplatform language. It means that you can use haXe to target the following platforms : Javascript : You [...]

Programming Tips from Pragmatic Programmer »

This is a summary from the Pragmatic Programmer book. Care About Your CraftWhy spend your life developing software unless you care about doing it well? Think! About Your WorkTurn off the autopilot and take control. Constantly critique and appraise your work. Provide Options, Don’t Make Lame ExcusesInstead of excuses, provide options. Don’t say it can’t [...]

Programming Books 2008 »

These are the programming books that I read or am reading for year 2008, which I think is good for reading by developers. December is a long holiday. Any recommendations for good books for year 2008 which worth reading, irregardless of programming languages? Effective Java (2nd Edition) by Joshua Bloch Java Power Tools by John [...]

Java: ServiceLoader in JDK 6 »

ServiceLoader is a class available in earlier version of Java and staring JDK 6, it is available formally under java.util package. In JDK 6 – java.util.ServiceLoader Prior to JDK 6 – Refer to the document at http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific [...]

Java: Refactoring If-Then-Else using Enum »

Download the code here One thing good about object oriented language is that now we can reduce the conditional statements typically found in procedural language, which in turn can make our code more maintainable. In Java, normally if we want to refactor a long conditional statements, we use polymorphism, which results in a lot of [...]