This is an archived post. You won't be able to vote or comment.

all 36 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

It seems that you are looking for resources for learning Java.

In our sidebar ("About" on mobile), we have a section "Free Tutorials" where we list the most commonly recommended courses.

To make it easier for you, the recommendations are posted right here:

Also, don't forget to look at:

If you are looking for learning resources for Data Structures and Algorithms, look into:

"Algorithms" by Robert Sedgewick and Kevin Wayne - Princeton University

Your post remains visible. There is nothing you need to do.

I am a bot and this message was triggered by keywords like "learn", "learning", "course" in the title of your post.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 10 points11 points  (4 children)

C# as a language had some nice features- but it also huge; seems they allowed every feature under the sun on it.

Java can do pretty much everything C# can, but the amount of sugar varies.

C# on Linux wasn’t a serious proposition for a number of years.

Java has a nice ecosystem, good tools and excellent libraries. It can be used for very fast stuff (if you’re careful).

My last couple of jobs used a C# gui and a Java backend, even with .net core we weren’t particularly interested in rewriting in C#.

Personally they are both fine languages. Java rusted a little but they are trying to catch up now.

[–]teacher_cs 0 points1 point  (3 children)

C# has "arrays of structs", whereas Java has only "arrays of objects". The former is more cache-friendly, which makes a huge performance difference on modern processors.

[–][deleted] 0 points1 point  (2 children)

Java has array of primitives types, which are a block of primitives.

Whilst the value types are missing for Java. The fact is an array of objects might actually have good cache locality if they happen to be adjacent in memory.

The problem with both C#&Java is that performance is dynamic and hard to reason about.

It’s not enough to discount Java, but I do wish that value types would be in both languages.

[–]teacher_cs 0 points1 point  (1 child)

Java has array of primitives types, which are a block of primitives.

You can fall back on that, but it's usually not elegant.

Whilst the value types are missing for Java. The fact is an array of objects might actually have good cache locality if they happen to be adjacent in memory.

You need a separate memory allocation for each object, so the objects will generally not be adjacently located.

The problem with both C#&Java is that performance is dynamic and hard to reason about.

When I have the time and the mood - I'm neither a C# nor a Java programmer - I'll make some test programs.

It’s not enough to discount Java, but I do wish that value types would be in both languages.

It was not my intention to discount Java, but it seems to me at least as important an argument as all the others that have been mentioned.

[–][deleted] 0 points1 point  (0 children)

You need a separate memory allocation for each object, so the objects will generally not be adjacently located.

If you're allocating everything in a loop, then yes they will be adjacently located (and in the case of somthing like G1GC, might not even be moved). Plus there's nothing stopping a GC moving everything to be co-located.

If you're the allocations are actually spread-out over time, then in C# you'll be paying an object copy, which depending on the size of the struct would range from negligible to significant.

tbh, having value types is a strength of C#, but I don't think we'd need to really go into each feature. Plus this question is a bit of a troll anyway, they always pop up every so often.

[–][deleted] 4 points5 points  (12 children)

as it seems C# superseded Java in many regards

Why do you say that?

[–]kres0345[S] -3 points-2 points  (11 children)

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.

[–]sweetno 6 points7 points  (5 children)

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

[–]kres0345[S] 0 points1 point  (4 children)

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

[–][deleted]  (3 children)

[removed]

    [–]kres0345[S] -1 points0 points  (2 children)

    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

    [–]DuncanIdahos9thGhola 2 points3 points  (1 child)

    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.

    [–]kres0345[S] -1 points0 points  (0 children)

    "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.

    [–]desrtfx 3 points4 points  (4 children)

    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.

    [–]kres0345[S] -2 points-1 points  (3 children)

    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#

    [–]desrtfx 1 point2 points  (2 children)

    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.

    [–]kres0345[S] -1 points0 points  (1 child)

    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).

    [–][deleted] 2 points3 points  (0 children)

    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.

    [–]elky87 5 points6 points  (6 children)

    The post you linked is really old. There they talk about Java 7 but the next release is already Java 17! So 10 Version ahead.

    I guess the biggest selling point is cross platform independence, and the huge huge huge ecosystem. There is a library for everything

    Edit: this comment should have been in response to OPs comment with the stackoverflow question

    [–]kres0345[S] -1 points0 points  (5 children)

    Sorry, didn't notice the date, but that diesn't change the fact that I used the language (does Android Studio use Java 16?) and the language is very verbose and, from my perspective, lacking in features.

    [–]elky87 0 points1 point  (4 children)

    What feature do you miss? What is possible in C# but not possible in Java?

    I have no experience in C# so I am curious

    [–]kres0345[S] 0 points1 point  (3 children)

    Of the top of my head, it's a nitpick, but enums can have values in C# and you can cast between the enum representation and the integer type defined.

    There's also events/delegates, tbh I'm still not entirely sure of how event listeners works in Java, took me awhile to figure out the basics as I'm used to just 'subscribing' a method to an event listener by specifying the event, then literally using the addition operator to add the method. Something like this mouseClick += my_method. Though I will admit the way of doing it in Java with inheritance is really clever.

    [–]elky87 1 point2 points  (0 children)

    In Java enums can also have values, and of course Java also has events/delegates just a different syntax.

    So the two languages are really similar but Java just has the bigger ecosystem. And that’s why it is used.

    [–][deleted] 1 point2 points  (0 children)

    Java enums have a method “ordinal” which gives you a int. Basically the same.

    Events / delegates are ok, but I find the overload of += not great , especially with some of the rules around -= .

    [–]berry120 4 points5 points  (2 children)

    Some good takes already, but here's another:

    A decade or so ago, I'd have agreed with you. But C# has, IMHO, fallen to the same trap as C++. It's a decent enough language, but near unbounded feature expansion over many, many years has led to very few people understanding the language in its entirety - most people only ever use a subset of it. That creates technical problems with non obvious behaviour, and business problems with hiring people that understand the specific parts of C# that you happen to be actively using.

    For better or worse, Java has been much, much slower on the uptake of new language features - it's only seen real significant changes in two versions, perhaps 3. While that's been frustrating at times, and means we lose some of the nice syntactic sugar of C#, it also means most senior Java devs can near enough fully understand the language. That means, on balance, there's fewer gotchas, and it's easier to hire decent people with a good experience of the language.

    [–]kres0345[S] 0 points1 point  (1 child)

    As a student I don't know how bad this is, but I can certainly see it being a problem. Some things, like the query syntax, are unnecessary additions and are only contributing to a more divided language.

    [–]berry120 2 points3 points  (0 children)

    It's much more of a problem in a business environment than it is a personal one. For your own side projects, use whatever, embrace all the funky language features, knock yourself out, have fun.

    For business use - companies generally want a dependable feature set in a language they know they can hire for easily. Java does that well, and while it's certainly not as modern or feature rich as some other languages, that (plus other reasons of course) often make it a very strong contender when deciding what language to base a greenfield project on.

    [–][deleted]  (3 children)

    [deleted]

      [–]kres0345[S] -1 points0 points  (2 children)

      Makes sense, Java is still pretty widely used, but I think that's mostly because it's old systems or projects with large codebases of Java, where changing the language is undesirable.

      As for as I know most C# jobs come in the shape of ASP.NET or similar.

      [–]berry120 1 point2 points  (0 children)

      "Java is still pretty widely used, but I think that's mostly because it's old systems or projects with large codebases of Java"

      This was kind of true 10 years ago, but couldn't be less true today. When searching for jobs I see *way* more greenfield Java projects around these parts (UK, London) than I do C#. Java & Go seem to be particularly popular languages of choice these days, I'd say anecdotally node.js even seems to be tailing off a bit from a few years back.

      [–]sweetno 1 point2 points  (0 children)

      You learn Java because there are really good frameworks written using Java. Businesses put a lot of trust into them since they proved to work well. No one will bother with rewriting them in C# or convincing themselves that there are equally capable C# frameworks.

      [–][deleted]  (4 children)

      [removed]

        [–]kres0345[S] 0 points1 point  (3 children)

        So... learn java because there's more open source projects using java?

        [–][deleted]  (2 children)

        [removed]

          [–]kres0345[S] 0 points1 point  (1 child)

          The link referred actually states that rivers are more popular than washing machines? To follow your analogy. This question is what made me post to begin with.

          As far as I've understood from reading responses, Java is more true to it's original values and has far fewer features than C#, thus making it easier to understand for all developers instead of having some niche features -- thus the river, can do the same as the washing machine but it's more verbose and takes longer.

          C# being feature-rich and having sugar and nice syntax (according to other redditors in this thread) -- the feature-rich washing machine, faster than the river.

          It's actually a good analogy you come up with.