Java and C
Written by Mike James   
Tuesday, 05 April 2011
Article Index
Java and C
C++ and C#

 

This is Part 1 of the I Programmer State of the Languages 2011 Report and it coincides with this month's poll question to discover our readers' choice of language, based on the latest TIOBE ranking. 

As you will probably already know (and if not see Language of the Year) the TIOBE index is a longstanding attempt to measure  language use and "importance". It is certainly valuable to developers to know which languages are currently important and in this part of the I Programmer survey we look at characteristics of the languages ranked 1 to 4.

The top four languages in the TIOBE survey at the start of 2011 are remarkably similar. This isn't surprising as C++ is an extension to C, Java is modelled on C++ and C# is modelled on C++ and Java. There is nothing wrong with this - as Picasso is so often quoted as saying "all art is theft" and all languages are either improvements or reactions to other existing languages.

What is surprising is that the top four languages are so narrow in their approach to syntax - all four use C's for loop construct for example - and paradigm - they are all procedural/imperative and three are object-oriented. It seems that we have voted for a single approach to the problem of creating programs and if you want real innovation you have to look further down the list.

So how do the top four compare and what are their essential characteristics?

 

Java

Java is now a middle aged language and what was once cutting edge and new is now just part of the establishment and wondering where to go next. Java also has something of a political crisis on its hands in the from of its new owner Oracle. Java has been free to use since it was first created by a team at Sun Microsystems in 1995 but its status as an open source language has long been confused. Now Oracle has control of the language and much of its infrastructure and this is not reassuring to its user base.

Java is a class-based, object-oriented language modeled on C/C++ but designed to be easier to use and safer. Another key feature is that it runs using a Virtual Machine (VM) rather than being compiled to a native machine code. This means that as long there is a Java VM for the platform all of the Java tools and code with just work. Of course in practice this isn't quite the case because machine specific considerations always find a way into the mix. Notice that Java may use a VM but it is a compiled language and it is strongly typed.

Java started out as just a language but since then it has acquired many frameworks and many variations that allow it to be used in different ways - Applets allow it to be embedded in web pages, JSP provide a way of creating web apps, It is even the main language used in many Smartphone implementations - Android, WebOS and Symbian. 

It can even be argued that Java now has so many frameworks around it that it is more than a language and has to be judged as an ecosystem. This is true but it is also one of the criticisms leveled against it - so much to learn so many conventions and legacy baggage! There is point that Java has been slow to develop. It added type safe generics in 2004 but this was the last big language feature to be introduced. The next version of Java, Java 7 will have some new language features but the long waited extras are delayed until Java 8.

Java is a good programming language but it is suffering from being middle aged. It no longer has anything new or innovative to offer but in the matter of languages stability is often more important. Overtime it has collected many additional technologies and lots of well designed support tools. Programmers may grow bored with it and play with new languages but Java has proved that it can do the job. Ironically with Oracle in charge of its direction its technical future looks good even if its credentials as an open source language are starting to look tarnished.

Key Facts

  • Imperative procedural
  • Object-Oriented
  • Class-based
  • Static strongly typed
  • Automatic memory management
  • Compiled to byte code

C

If Java is middle aged then C, developed around 1969,  should be a pensioner. However this is not the case and C still occupies an important position in the programming universe. It is also arguably the most influential of languages because most of the modern languages derive from it or are modeled on it.

C is different from the other languages described here because it has different objectives. C is best characterized as a machine independent assembler. Rather than abstracting away from the underlying machine architecture it says as close as possible without building in anything that is too machine specific.

Created in a time before objects were the standard approach to programming C is a well structured procedural language that uses functions to organise the code. It made popular the almost universal form of the for statement for(initializer,condition,incrementer) as opposed to the Fortran/Basic form For var= start To finish. It also introduced the idea of dividing code into header, i.e. definition, and main files.

As a modern language its key difference is that it is weakly typed - although not being object oriented the range of types is limited. Although compilers are designed to spot type conversion errors the programmer can override these warnings and basically treat the data as raw bits. This approach is further encouraged by the availability of a pointer type which is an explicit pointer to a memory location. That is in C pointers contain machine addresses.

These and other similar features make C ideal for writing code that is reasonably high level and yet can still work with the hardware. This ability and the fact that it creates compact and efficient programs make it a good choice for systems and embedded programming.

However C is generally considered not to be a good choice for large projects that don't interact with the hardware directly. The reasons are that lacks a good way e.g. objects, to organise code at a higher level and it doesn't protect the programmer from making errors that can bring the entire system down. 

Despite its shortcomings, and it is worth noting that many features of later languages were added as a reaction to problems in C, it is difficult not to be impressed by the simplicity and elegance of the language.

Key Facts

  • Imperative procedural
  • Not Object-Oriented
  • Function-based
  • Weakly typed
  • Manual memory management
  • Compiled to machine code


Last Updated ( Tuesday, 05 April 2011 )