The line between desktop development and web-based applications has been all but obliterated in the last few years. With the advent of smartphones, especially Google’s Java-based Android operating system, developers are scrambling to jump onto the newest technology, while fearing that the skills they have cultivated over the years may become obsolete.

Many former C++ and C# programmers are migrating their way to Java applications. While the languages are remarkably similar (as Java was built around the C and C++ structures in the 1990s), a few subtle differences can trip up even the most experienced developers.

#1: Unsigned Integers

C#: Supports 8-bit, 16-bit, 32-bit, and 64-bit unsigned integers.
Java: Supports 16-bit unsigned integers only
James Gosling, the creator of the Java programming language, decided against including arithmetic for unsigned integers in the initial design. In a 2001 interview with Java World magazine, he stressed that simplicity was the key to developing a robust programming language.

“One of the little experiments I tried was asking people about the rules for unsigned arithmetic in C. It turns out nobody understands how unsigned arithmetic in C works. There are a few obvious things that people understand, but many people don’t understand it.”

#2: Complex Numbers

C#: Supports complex numbers
Java: No support for complex numbers
Complex numbers are written in the form of “a + bi”, where “a” and “b” are integers and “i” is the square root of -1. Complex numbers are used in a wide range of applications, from electrical engineering to fluid dynamics.

#3: Value Types

C#: Supports user-defined value types
Java: Supports only primitive value types
C# allows users to construct their own value types. For instance, if a user wanted to construct the C# variable type SimpleVar with multiple properties, then assign values to those properties, the code would look like this:

struct SimpleVar
{
public int Position;
public bool Exists;
public double LastValue;
}

static void Main()
{
SimpleVar s;
s.Position = 2;
s.Exists = true;
s.LastValue = 4.2;
}

#4: Tuples

C#: Supports tuples
Java: No support for tuples
The “Tuple” class in C# consists of “a data structure that has a specific number and sequence of elements”. For instance,

var zipCodes = new Tuple<string, int, int, int, int>(“Houston”, 77006, 77098, 77002, 77019);

or

var zipCodes = Tuple.Create(“Houston”, 77006, 77098, 77002, 77019);

The Tuple class has a structure similar to the standard array, but with much less flexibility; the fields in a tuple cannot be changed or manipulated.

#5: Pointers

C#: Supports pointers
Java: No support for pointers
Pointer variables “point” directly to a location within the system’s memory. In a web-based language such as Java, such pointers would be useless. Instead, the Java Native Interface (JNI) handles any such functions.

As Gosling pointed out, the key advantage that Java has over C# is its simplicity. However, that simplicity requires the sacrifice of some more complex functionality, including data types.  In the next lesson, we will examine how class structures differ between these two languages.

By Gerald Hanks
Gerald Hanks has been involved in web development applications since 1996. He has designed applications with JavaScript, ASP.NET and PHP, as well as building databases in MS SQL Server and MySQL. He lives in Houston, Texas.
  • Aneeq Tariq

    There is a very useful list of PHP standards we should use in development. This list can be found at the web address below.

    http://phphelp.co/2012/06/04/what-are-some-common-php-coding-standards/

    http://addr.pk/a704

  • MateuszBukowicz

    I suppose this was thought to be a post proving that C# is a superior languange compared to Java. Despite I believe this is true (C# is indeed a better language), I think the features showed have little practical use. If I had to choose from the examples I would choose the lack of unsigned byte in Java as the most important feature Java does not support. On the other hand Java has also some nice features that C# has not, i.e. enums that are classes (not dummy integers) as in C#, which here was not mentioned.

Home XML WordPress Web Services Web Development Web Design Underscore Uncategorized Tutorial Tools SQL Server Social Apps Snippet SEO Security RoR Responsive Design Resources Python PHP News MySQL Mobile Miscellaneous jQuery JavaScript Java J2EE HTML5 HTML Design Patterns