When resources are tight companies try to limit the number of programming languages they support. Microsoft's C# and Sun's Java both have strengths, so which do you choose? Arif Mohamed reports
The programming languages C# from Microsoft and Java from Sun Microsystems were developed to make programming easier by reducing the number of coding bugs that occurred with earlier languages such as C and C++. The languages have become so successful that blue chip multinationals and companies across all vertical sectors are using them to create business-critical applications.
Among enterprise users of C# are the London Stock Exchange, Tesco, Scottish & Southern Energy, NTL and Marks & Spencer. Java users include Credit Suisse First Boston, Voca (formerly Bacs), Criminal Justice IT and mobile provider 3. In many cases, larger companies are developing applications in both C# and Java, but for smaller organisations with limited resources, it may be necessary to choose one.
The languages are used to develop business applications that store data in a relational database and present it to users via a web browser, desktop or mobile graphical interface. Both languages can be used to develop rich internet applications, with C# extending to personal digital assistants and smartphones when used with a platform called .net Compact Framework. Java is also popular with mobile phone application developers. In addition, many financial trading systems run on Java, as do online retailers and management systems in telecoms, said Sun.
Java and C# are object-oriented languages, which means they can manipulate and re-use whole chunks of code. They both have syntax rules that catch a lot of basic programming errors and require a virtual machine - software that interprets the source code into machine-specific instructions.
Earlier languages such as C and C++ have memory-specific technical problems which they cannot easily protect against. The main one is buffer overflow, where in-memory code is inadvertently overwritten with data. Memory leak is another problem, mainly with C, where the programmer can dynamically allocate memory but has to remember to "de-allocate" it manually or face problems.
Buffer overflow vulnerabilities can allow hackers to compromise web applications by dumping excessive data, or even executable code, into a dialogue box that can only hold limited data. The end of the buffer (temporary data storage area) can overwrite some of the application's code and, when the application tries to run its code, accidentally runs what is at the end of the parameter that is provided, allowing a hacker to compromise the server.
For example, in July 2000 a buffer overflow flaw was discovered in Microsoft Outlook and Outlook Express which made it possible for an attacker to compromise a PC by simply sending an e-mail message. The user did not have to open the message to enable the attack because the message header caused it, making it difficult to defend against.
Java and C# solved issues such as buffer overflow with automated memory allocation features, such as garbage collection and memory synchronisation, but above all by using a virtual machine to effectively isolate the application code. Java uses the Java Virtual Machine (JVM) and C# uses Microsoft's Common Language Runtime (CLR).
Paul Tempest-Mitchell, datacentre practice manager at Sun Microsystems, says, "The JVM is implemented on almost every environment, making all applications hardware- and operating system-independent. It also provides a 'sandbox' which isolates individual processes, ensuring all applications are secured against each other and other processes taking place within the system. It also ensures that malicious code cannot get out. There are no Java viruses."
Java and C# evolved at different times, with Java being developed by Sun during the early 1990s. It grew from a project to deliver consumer services to television set-top boxes, which featured an object-based programming methodology. This methodology became Java.
"Sun made the source code and programming models available to the IT community, which has since helped Java to become a highly productive programming environment with a developer base of more than four million programmers," says Tempest-Mitchell. It later developed Java 2 Enterprise Edition (J2EE), with extra security and stability and a larger library of business code.
C# was developed in 2000, four years after Anders Hejlsberg, designer of Turbo Pascal and the Delphi programming languages joined Microsoft from Borland. C# was designed to be used with Microsoft's CLR and .net Framework. Microsoft says, "C# has a C++-style syntax but is designed to be productive, safe, maintainable and easy to read. That does not make it better or worse than C++, it just has a different philosophy."
Bola Rotibi, senior analyst for software development strategies at analyst firm Ovum, says both languages have different strengths. "For both, relative simplicity is the strength and for Java, portability across hardware platforms."
She adds that Java is more mature and has better cross-platform compatibility, but C# benefits from being closely tied to Windows and has a number of useful technical and programming features. Both have sizable developer communities.
But Rotibi says, "Their relative simplicity is also the main weakness - they are limited to more mainstream application development. Some would argue that C# is under too much control by Microsoft, making it locked into one supplier in the long term. C# can take longer to learn."
She says Java does not include operator overloading, which makes it ill-suited for scientific programming. This is a programming term for the ability to use the same arithmetic operator (such as +, -, * and /) to perform different operations.
Tempest-Mitchell says, "Because Java is a community environment that is driven by the community, when deficiencies were found they were corrected and the language has been updated. Where weaknesses existed, the community has corrected them, strengthening it to become a mature business environment for enterprise applications."
For an firm with a limited budget, having a strong developer community is one factor in deciding which of the two to support.
There are several other considerations when assembling a development team. Rotibi says, "Much the same as any development team, they will need the standard set of skills: solution architecture and software architecture skills, process and methodology knowledge and testing, database administration and programming skills."
Salaries for Java and C# developers range from the £25,000 to £40,000 bracket up to £75,000 for a senior developer or team leader.
Tempest-Mitchell says, "One of the great things about Java is that developers are able to use their favourite development tools and their work can be shared with others. Java is supported in most environments and there is a wealth of existing libraries."
However, Rotibi says C# development can be easier than Java, because C# is simpler to code and less complex to deploy with Microsoft Visual Studio. "Visual Studio is well designed and makes many of the features easier to implement and there is only one deployment platform, which is .net," she says.
"It also depends on your skills and experience. If you have a small development team with experience in Microsoft Visual Basic, and you are targeting internet or Windows clients, then C# is the way to go."
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
An on-site view of Java
Publisher Random House and partner Infusion Development were running a website on Java products from multiple suppliers, but wanted to move to a single platform and supplier to cut costs and make site changes easier.
In July 2003, they switched to a Microsoft-based architecture and used Java Language Conversion Assistant to port the site from JSP to ASP.net, converting 80% of its Java code to C#.
"We found the Java architecture was fairly difficult to set up as a development environment for even minor modifications," says Rob McGovern, senior project manager at Infusion.
"The amount of 'tweaking' required to properly install all the different components and so on made bringing new developers up to speed a challenging process."
Most of the migration was completed in eight weeks, with another eight weeks tidying up loose ends and a further four weeks spent testing and deploying the new system, with the firms satisfied with the result.
A Java user's view of C#
Angsuman Chakraborty is chief software architect at California-based software development firm Taragana, which specialises in IT outsourcing and consulting services.
Taragana has worked with Java since 1995, but Chakraborty was challenged by a former colleague to consider some application development using C#.
"I was sceptical because I have not taken to Microsoft products in the past. In my experience they look easy, but can be awkward when used for large-scale enterprise applications," he says.
Nevertheless, Taragana tried a project in C#. "Overall, the languages are very similar. I felt the set-up was more complex with C# and overall the development and debugging were more cumbersome than Java," he says.
"Performance-wise, it looked to be slower with real-world applications. And there is always the fear of getting stuck with a single supplier. For a simple project I felt both were equivalent, but generally I would still choose Java."
Supporting C# and Java
Many companies support both C# and Java. They typically have back-end servers running J2EE for mission-critical applications, using C# and .net to build the front-end user interface, because of the dominance of Windows on the desktop, says Rikki Kirzner, research director at analyst firm IDC.
This adds to the complexity of a company's software environment and makes it expensive to maintain and expand the systems and to make them interoperable.
"As a result, companies are turning to integration tools such as Borland's Janeva, which are code compilers that can connect .net applications to back-end J2EE applications," says Kirzner. Using web services is another way to connect the systems, he adds.
How C# and Java compare
- C# is tied closely to Windows, boosting performance in operating system-specific operations such as the user interface.
- The .net framework supports a larger number of languages than Java, making for better cross-language compatibility.
- It has the edge on Java in terms of catching arithmetic exceptions and allowing numbers to be handled as an object.
- Java is already implemented on a larger number of platforms, making for better cross-platform compatibility.
- It is more mature, so a lot of problems have already been worked out, and more code is widely available.
- The language is simpler, making it easier to optimise the code when it comes to compiling it.
Source: Bola Rotibi, senior analyst, Ovum