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

6

u/[deleted] Jun 21 '21

as it seems C# superseded Java in many regards

Why do you say that?

-2

u/kres0345 Jun 21 '21

this is the first thing I could find, https://softwareengineering.stackexchange.com/a/125718/290637

I am aware of that it only addresses the things C# beats Java in.

  • Instead of a lot of noise (EJB, private static class implementations, etc) you get elegant and friendly native constructs such as Properties and Events.

  • I am aware that it only addresses the things C# beats Java in.generics), and you can perform reflection on them.

  • It supports native resource-management idioms (the using statement). Java 7 is also going to support this, but C# has had it for a way longer time.

  • It doesn't have checked exceptions :) (debatable whether this is good or bad)

  • It's deeply integrated with Windows, if that's what you want.

  • It has Lambdas and LINQ, therefore supporting a small amount of functional programming.

  • It allows for both generic covariance and contravariance explicitly.

  • It has dynamic variables, if you want them.

  • Better enumeration support, with the yield statement.

  • It allows you to define new value (or non-reference) types.

I've only used Java for app development since I like Android Studio more than Xamarin, but in the time I've used Java I keep finding myself looking for features that are present in C# but aren't in Java, like properties (much nicer than manual getter and setter methods), enums, the simple syntax of LINQ and generics.

6

u/sweetno Jun 21 '21

Usually it comes down to the point "Deeply integrated with Windows" which doesn't play well with all these Linux servers everywhere.

1

u/kres0345 Jun 21 '21

Yea, that's the cross-platform part I mentioned in the edit of my OP. As another redditor mentioned, the post is apparently old. C# isn't deeply "integrated with windows", the original DotNet Framework has got it's last version update and is already a couple major releases behind, the new main framework is .NET Core a cross-platform alternative

1

u/[deleted] Jun 21 '21

[removed] — view removed comment

0

u/kres0345 Jun 21 '21

Well that's because the multiple codebases are built-into the language and hidden from the programmer. I'm sure you can find libraries that present cross-platform interfaces for doing things

3

u/DuncanIdahos9thGhola Jun 21 '21

Well that's because the multiple codebases are built-into the language and hidden from the programmer.

WTF does that even mean?

I'm sure you can find libraries that present cross-platform interfaces for doing things

Not really. There's not many libraries out there compared to Java out there.

0

u/kres0345 Jun 22 '21

"WTF does that even mean?"

Well, it isn't magic that communicates with the different platforms, at some level it would have to bifurcate into different "codebases" addressing the specifics of the system.

I would like to emphasize that I already don't like the parent commenters use of the word "codebase", I think it implies there's a need to write the entire codebase twice with minor differences, this is very naïve. Having an if-statement check the platform and run a line of code instead of another according to the platform is hardly called a different "codebase".

What I meant is that this is hidden away in the standard library of Java, while in C# you'd just such a library yourself to address different platform needs.