r/learnjava • • Jun 21 '21

Why learn Java when there's C#?

I am genuinely curious, as it seems C# has superseded Java in many regards. The only reason I can think of using Java is backward compatibility.

EDIT: To clarify, the main selling point of Java was cross-platform, but nowadays most frameworks and toolsets are to some degree cross-platform, including .NET Core, which is the new main framework of C#.

0 Upvotes

36 comments sorted by

View all comments

Show parent comments

5

u/desrtfx Jun 21 '21

enums

Java's enums are superior to C#'s implementation by lengths.

Java has had generics for quite some time already.

Java has had streams and lambdas since version 8 - we are currently at 16 with 17 round the corner.

You cannot talk Java if your sole experience is Android and your sole backing is an article that is talking close to 10 versions behind current.

Android is a subset of a fairly old Java framework.

-1

u/kres0345 Jun 21 '21

Can you elaborate on enums.

C# has also evolved over the years, it's not like C# has remained static while Java has evolved.

Making an app isn't my "sole" experience, just the most recent. I've made minecraft mods and plugins as well. And I've also dabbled in Java before I became acquainted with C#

2

u/desrtfx Jun 21 '21

Java enums are full fledged final classes with fields, with methods.

Please, google "Oracle Java Enum tutorial" and see for yourself. I'm on mobile and linking from here is difficult.

Sure, C# has evolved over time, but so and to an even greater degree did Java.

Again, I stick to what I said before: you don't have real Java experience and you never have properly learnt Java and therefore are not qualified and informed enoughtfor the statements/claims you make.

LINQ is on one hand highly praised but even more cursed in professional development since it is fairly slow and a huge memory hog.

0

u/kres0345 Jun 21 '21

I just read this page https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Honestly, I still prefer the elegant C# way. In C# an enum is simple, it's just an identifier optionally paired with a primitive-type. If I were to implement the planet example, I would probably just use objects with inheritance to make it even more extensible, though I get that it's unlikely for another planet to appear within our solar system. That way the system would be open for extension and closed for modification (in case I suddenly need to specify a new parameter for a planet, like day duration).

Another way would be having a static helper class of methods taking an enums as input and outputting a wide range of information of the given planet.

Also, as I stated originally I don't know much about Java (that's why I made the post).

3

u/[deleted] Jun 21 '21

I think you’ve missed the point with Enums. C# enums have their place, especially with the ability to make them flag fields.

But the Java enums allow you to have effectively a finite list, of immutable classes of static data. They can be very useful.

C# enums are much closer to C style enums, where as Java enums are more abstract.

Neither is necessary stater, just different.