Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has Java just not kept up? [closed]

Tags:

I code C# all day, but recently made a jump to Java for hobby stuff, like writing for the BlackBerry and Android platforms. All this time I assumed that as far as language features go, Java and C# were twins of each other.

Anyway, I discovered that Java is the equivalent of C# 1.1 or something like that. In Java, I have to write twice the code that I would in C#. Are features like object initializers, lambda, properties for god's sake, ever coming to Java? I tried to wade through the JSR stuff, but couldn't find anything.

Has Java simply not kept up? Or am I simply not using it as it is intended?

like image 545
AngryHacker Avatar asked Mar 14 '09 06:03

AngryHacker


People also ask

Is it necessary to close Scanner Java?

If you do not close the Scanner then Java will not garbage collect the Scanner object and you will have a memory leak in your program: void close(): closes the Scanner and allows Java to reclaim the Scanner's memory. You cannot re-use a Scanner so you should get rid of it as soon as you exhaust its input.

What is resource leak warning in Java?

@Borat - "resource leak" implies that some system resource (usually memory) is being lost or wasted needlessly. Usually this will impact you when you start getting OutOfMemoryErrors thrown during the normal operation of your program.

What can I use instead of system exit in Java?

The main alternative is Runtime. getRuntime(). halt(0) , described as "Forcibly terminates the currently running Java virtual machine". This does not call shutdown hooks or exit finalizers, it just exits.


2 Answers

I think you're right, Java does not have a lot of the convenient new features that C# has introduced. A lot of the new C# features are just compiler tricks to (properties, object intitializers, extension methods) that you can accomplish by hand in C# or Java.

The Java people probably haven't introduced these new features because they probably prefer to keep the language as simple and backwards-compatible as possible.

I do have to say I prefer writing C# these days.

like image 54
Andy White Avatar answered Oct 20 '22 22:10

Andy White


I would say, yes, Java has not kept up. Microsoft took a long hard look at Java (and C++) and figured out what annoyances they had, and what features were missing, and fixed many of those in subsequent releases of C#.

Also, the Java designers seem to try to keep their language and parsers as simple as possible, whereas the C# designers have no fear of syntactic sugar: properties, delegates, lambdas and LINQ are all examples of this. And as you already noticed, a spoonful of syntactic sugar makes the language go down much easier.

like image 39
Thomas Avatar answered Oct 20 '22 21:10

Thomas