Tuesday, 2 February 2010

primitives


Hello Friends and Neighbours,

Having worked in the IT for several years I find that our tools, languages and platforms keep improving . All in the name of helping I.T practitioners to manage, tackle and solve more complex business problems.

Without doubt new languages improve over old or existent languages. C++ improved over C , Java improved over C++ and C# improved over Java.

Lets see a very simple example, a "milk for babies" kind of example:

I have an integer I want to convert it to a text (or string, as we developers call it)

In Java we would something like this:

int x = 1;
String aString = Integer.toString(x);

We need to call the static toString() method of the Integer class.

In C# we would do it like this:

int x = 45;
String aString = x.ToString();

In C# We are able to get the string representation, of the integer, right from the primitive itself!

With C# we are able to get the string represantion of a double expression:
Console.WriteLine((46.4 * 24.4).ToString());





There are other way of converting integer to string in Java. However, they are not as readable as the
one above.

http://en.literateprograms.org/Convert_Integer_to_String_(Java)

No comments:

Post a Comment