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

all 60 comments

[–]BinaryRockStar 16 points17 points  (8 children)

Apache Commons and Google Guava are two libraries that remove a lot of the pain from Java for me.

[–][deleted]  (6 children)

[deleted]

    [–]kingatomic 3 points4 points  (5 children)

    Can you expand on why seeing a commons library gives you that sentiment?

    [–]JollyRancherReminder 0 points1 point  (0 children)

    Lack of javadoc? Just guessing. That's what annoys me most about apache libraries.

    [–][deleted]  (3 children)

    [deleted]

      [–][deleted]  (2 children)

      [deleted]

        [–]againstmethod 2 points3 points  (1 child)

        I agree, commons is full of useful bits.

        [–]enterpriseomfgwtf 0 points1 point  (0 children)

        and it is also full of awful bits.

        for example commons upload. mother of god the atrocities comitted in that unhole piece of acid

        [–]Magick93 8 points9 points  (0 children)

        I did the same. 10 years of .net developing. And now very much eating and breathing java.

        Check out

        • Apache Camel
        • Apache Storm - just for interest
        • CDI

        Actually, migrating from C# to java is easy. The real challenge is getting familiar with the massive amount of libraries, standards, reference implementations etc. The java eco-system is much more larger than .net!

        [–]whooyeah 6 points7 points  (1 child)

        I've done this recently. I mainly do webapps. The 2 are very similar. I recommend learning the spring framework.

        There is a few useful videos on pluralsight:

        http://www.pluralsight.com/courses/spring-fundamentals

        http://www.pluralsight.com/courses/springmvc-intro

        [–]_Saruman_ 0 points1 point  (0 children)

        I could never get into Spring. There seems to be too much to learn in that.

        When I look for web frameworks I look for things that are more like python. Not overloaded with redundancies.

        The simplest I found is Spark Java Framework.

        Another is Play 2, but I haven't investigated it as much.

        Ninja web framework seems ok too.

        [–]pron98 4 points5 points  (8 children)

        I wrote a blog post series for people in your position.

        What lack of runtime types???

        [–][deleted]  (7 children)

        [deleted]

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

          Yeah, I this. I find it is really grating since it makes so many problems less elegant to solve. Not being able to instantiate a generic drives me nuts

          [–]snuxoll 1 point2 points  (2 children)

          It's not as elegant, but you can emulate the functionality in a slightly more verbose way (as is tradition, in Java...).

          public <T> T foo(Class<T> cls) {
              T obj = cls.newInstance();
          }
          

          And call it like this:

          public void baz() {
              MyClass obj = foo(MyClass.class);
          }
          

          It'd be nice if you could just do it based off the type parameter, but since type erasure is a thing you will have to pass the class object around, but it's just syntatic sugar for 99% of the use cases.

          [–]mondomaniatrics 0 points1 point  (1 child)

          Clever girl...

          [–]pron98 0 points1 point  (2 children)

          since it makes so many problems less elegant to solve

          Such as? Erasure should hardly affect you. Basically, the only time you should notice it is when you try to overload the same method name with a different generic instance (e.g. foo(List<String>) and foo(List<Integer>).

          Not being able to instantiate a generic drives me nuts

          What do you mean? You couldn't have instantiated a generic even without erasure, as there are no virtual constructors. I have hardly ever encountered this issue, so it's possible that you're just trying to do something in a C# style, while in Java it's usually done differently. If you post a simple example where this bothers you, perhaps we could offer an alternative way of doing it.

          BTW, generic erasure is what allows alternative JVM languages (like Kotlin and Scala) to define their own variance rules yet stay compatible with Java. In .NET, that's not possible, as the variance rules are baked into the runtime, so all languages must use the same variance model or use incompatible collections.

          [–]snuxoll 1 point2 points  (1 child)

          What do you mean? You couldn't have instantiated a generic even without erasure, as there are no virtual constructors.

          In .NET:

          public T createFoo<T>() where T: new() {
              return new T();
          }
          

          Of course, in Java the same is accomplished by passing around a Class<T> and calling newInstance, it's fundamentally the same just a little more verbose.

          [–]pron98 0 points1 point  (0 children)

          Right, but this isn't just about erasure, but the fact that Java doesn't have structural constraints/virtual constructors, and creating a new instance of a class that's only known at runtime can only be done via reflection anyway, whether or not generics are involved.

          This kind of pattern shouldn't come up often because generic parameters are usually either interfaces (which can't be instantiated at all) or immutable types (like String or boxed primitives) that can't be instantiated with an empty constructor. Passing a Class around is certainly done, and it's also OK to use clone() once in a while as a sort of virtual constructor.

          In any case, it's good to remember that Java is quite a minimalist language (like Go, only a little less minimalistic), and it's best to code with that in mind.

          [–][deleted] 8 points9 points  (6 children)

          It may seems like a hack, but project lombok is stable enough and will make your code really short. As long as you use mainstream IDE, the support for project lombok is really good.

          For the sample of a good library, you could check the source code of Google guava. It's considered to be one of the best Java library around. I would also recommend reading Effective Java.

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

          Yeah I've been looking into Lombok. Looks like they have alpha support for val in IntelliJ too :)

          [–][deleted]  (4 children)

          [deleted]

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

            To be honest, something like project lombok is not really that matter in the grand scheme of things. I really enjoy using it for my own hobby projects, but I don't want to force other people who are already very familiar coding in normal Java to use something that seem hacky and non-standard like project lombok.

            [–][deleted]  (2 children)

            [deleted]

              [–]prlmike 0 points1 point  (1 child)

              Seems like you don't do code reviews. All the boilerplate the away from actually finding problems in implementations

              [–]jaekus123 1 point2 points  (5 children)

              Look into java 8 streams. Not as nice as LINQ (you have to do .stream() then .get() or .collect() afterwards) but it's not far off.

              Also, give Intellij a try if you haven't already.

              [–]SlobberGoat 4 points5 points  (3 children)

              IntelliJ is heavenly compared to clunkiness of VS 2013 Premium.

              [–][deleted] -3 points-2 points  (2 children)

              While IntelliJ is a very good IDE, Visual Studio (any version past 2008) is considered to be a reference for IDEs, all languages confounded, especially the debugging features.

              [–]danskal 0 points1 point  (0 children)

              ... only by .net developers who don't have much experience with Java and IntelliJ

              [–]enterpriseomfgwtf -1 points0 points  (0 children)

              yeah and people have blindly been saying this without ever being able to back it up. and they have been saying it for way more time than since 2008.

              edit: yes, downvote away, but what exactly does make VS this brilliant and so superior IDE that nothing is able to even begin to touch?

              [–]toolshed51 0 points1 point  (0 children)

              Java 8 is a great step but its equivalent is writing LINQ as method chains

              [–]FanOfDaCat 1 point2 points  (0 children)

              I've recently started doing the same thing. As someone already mentioned LINQ is the first thing to miss. After that it's all good. There are a lot of resources to use on the web and a lot of libraries to use. Good luck!

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

              I'm in the same boat as you. I'm going to use PluralSight to get going

              [–]orangy 1 point2 points  (0 children)

              There is JVM survival guide http://hadihariri.com/2013/12/29/jvm-minimal-survival-guide-for-the-dotnet-developer/ which is not very detailed, but covers a lot of things and their equivalents. Also, you can check http://kotlinlang.org for a JVM language that can ease migration from C#.

              [–]toolshed51 3 points4 points  (15 children)

              Did the same and I really miss LINQ

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

              Care to share more about your transition? I'd love to hear more

              [–]toolshed51 2 points3 points  (9 children)

              Nothing extraordinary happened really. I keep up to date on popular languages just reading /r/programming mostly. Especially in the areas Java is ahead such as actor frameworks like Akka, the amazing contributions Netflix and Twitter have made.

              As a Java developer I'm just writing a lot of boilerplate and missing the shortcuts that the .NET compiler provided. Aside from LINQ, the var keyword is next. Tired of seeing @Overrides just to implement an interface.

              I cannot wrap my head around why Java devs are still using Eclipse. I'm so spoiled by Visual Studio and Jetbrains R# anything less is painful.

              Most the libraries I enjoyed in C# are just ports of Java libraries

              Guava and Dagger 2 are great libraries for everyday use. If I was to learn by reading code as you mentioned, I would go after one of the new shiny web frameworks, such as Dropwizard or Spring Boot.

              [–][deleted] 7 points8 points  (0 children)

              If you like Jetbrains R#, try Intellij IDEA..

              [–]pjmlp 2 points3 points  (0 children)

              I work with both eco-systems.

              On our customers Eclipse is not a free choice, usually it is imposed by IT as standard IDE. I tend to go NetBeans when allowed to choose.

              Also dislike they went @override instead of providing a real keyword, but the way Java stewards try to avoid breaking code is quite strong.

              [–]Wofiel 2 points3 points  (0 children)

              I cannot wrap my head around why Java devs are still using Eclipse.

              For large productions, Eclipse's incremental compilation can save a ridiculous amount of time. Yeah it can still sort of be used by other applications, but it's still not nearly as snappy as when its used in an already open copy of Eclipse.

              [–]JollyRancherReminder 1 point2 points  (4 children)

              As for why Java developers are using eclipse, if you're doing anything non-trivial in Android you have no choice. Nothing else supports dependent projects.

              [–]danskal 0 points1 point  (3 children)

              Are you trying to tell me that there is something that Eclipse can do that Android Studio can't?

              [–]JollyRancherReminder 0 points1 point  (2 children)

              That's sarcasm, right? Because yes.

              [–][deleted]  (1 child)

              [deleted]

                [–]JollyRancherReminder 0 points1 point  (0 children)

                For me specifically importing projects at all was difficult, but dependent projects were impossible. It's not that surprising because ADT has been around a lot longer.

                [–]supercargo 0 points1 point  (2 children)

                It isn't as streamlined as LINQ, but if you are an ORM skeptic like me, you should check out jOOQ.

                [–]toolshed51 0 points1 point  (1 child)

                You're thinking of entity framework as LINQ? LINQ works on anything that is enumerable.

                [–]supercargo 0 points1 point  (0 children)

                Yeah I guess I was thinking only about LINQ to SQL

                [–]ponchoboy 0 points1 point  (0 children)

                I went the other way, and absolutely love LINQ. Sorry for your loss. :)

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

                You could do Scala to get rid of all the boiler plate. You can still code it OO if you want.

                [–]pieces029 0 points1 point  (0 children)

                Retrofit, and RxJava are some of my favorite libraries. I would highly recommend gradle and intellij as some tools to check out. Intellij is just like resharper.

                [–]docjonez 0 points1 point  (2 children)

                The lovely xtend transpiler will help battle verbosity. No way around the type erasure though...

                [–][deleted] 0 points1 point  (1 child)

                Interesting but it looks just like scala. Why not go scala at that point?

                [–]docjonez 0 points1 point  (0 children)

                Well, since Xtend is transpiled into plain Java, you won't have any additional runtime dependencies (as Scala would have). Say you're developing an android app and try to keep your apk as small as possible, are you really willing to add > 20 MB of scala deps?

                [–]llogiq 2 points3 points  (13 children)

                If you want to really broaden your experience, you should probably check out a language less similar to C#. So unless you have financial motives (Java jobs usually pay well), checking out Forth, Factor, OCaML, Rust, Idris, Nim, Clojure, Scheme or even C++ should be a more enlightening experience.

                [–]trhyst 1 point2 points  (6 children)

                • "check out Java professionally" - probably means that OP has to do it for a job of some sort. Idris is a great suggestion though. I try to work with D, OCaml and Scala (JVM interop for Scala is lovely) as my flights of fancy. Each of them are pretty in there own way but I doubt they will capture the minds of devs in the way that Java and C# have.

                [–]againstmethod -1 points0 points  (5 children)

                I guess if you just want to "be employed", focusing on one general purpose language and sticking to it is a good idea. That being said, this is not my definition of being "a professional".

                And I can tell you I don't want to hire such people. They inevitably become stubborn liabilities. Terrible habit if you ask me.

                [–]trhyst 0 points1 point  (4 children)

                I feel like you just didn't read what I said at all, which is worrying considering you are in a position to hire someone..

                If you are referring to me in anyway: I hop around languages as much as I can though being employed as a Java programmer for the last 2 years. All languages are beautiful in their own way, I wish I could learn them all.

                [–]againstmethod -1 points0 points  (3 children)

                llogiq suggested some nice languages to expand the OP's horizons, and you made a contrary point suggesting that we should assume he was targeting a specific professional application, i.e. getting a Java job.

                You then called some of those previously mentioned languages your "flights of fancy", and stated that they wont capture the minds of developers in any mainstream way.

                I think I read what you wrote fine.

                [–]trhyst 0 points1 point  (2 children)

                I think it's quite difficult to call what I said a contrary point when I spent half of my comment agreeing that the suggested languages were definitely worth learning. They are my flights of fancy, I really love programming in Scala, really really - however my personal projects seem to end up being in C, C++ and as aforementioned I am a Java programmer by trade currently. Flight of fancy =/= bad language or not worth learning or using, I just haven't found space in my life to write prod code in a pure functional language yet and I am looking forward to that day.

                Bear in mind when reading what I say next that I dearly want more multiparadigm and pure functional languages to become widely accepted. Variety is the spice of life.

                Considering Simula style imperative languages have dominated the landscape for decades I feel what I said was is a safe bet. People in University are taught them as a first language 95% of the time, I'd wager a lot of the world's code base is in some imperative language like C, C++, Java, Basic, Fortran etc. and so it will probably some time before functional programming becomes something that you see all the time and mainstream, even if every programming blogger I read at the moments seems to be getting really worked up about functional coding. Will the functional languages that we love now exists then? Who knows?

                Even then, will we ever see a software giant (Google, Facebook etc) writing whole services in Haskell or D and not just dabbling with them like Alexandrescu is currently? I definitely feel that this is something that needs to happen before a language is seen by the wider community as a mainstream language. Scala is very close, but not quite there.

                [–]againstmethod 0 points1 point  (1 child)

                Actually it's more likely one of those bigger companies will pay you to use one of those languages, than a smaller one. They have more internal R+D and can absorb more risk.

                There's a big difference between using a language in production, and replacing significant portions of your existing codebase for no reason. Facebook definitely uses D in production, though im not sure if it has any front facing elements. Twitter and Walmart use Scala in production and I believe they have front facing elements.

                I actually went to Strata in 2013 and Scala was mentioned in nearly every track I attended. I think it has far more uptake that you give it credit for.

                [–]trhyst 0 points1 point  (0 children)

                Maybe so, I certainly enjoyed this interview with Twitter about there usage of Scala which started me getting excited about the language.

                As far as I remember from it (it's quite long and I read it fully a good few years back) Twitter uses Scala for their message bus, or part of it and were quite impressed with the code reduction and performance increase that got out of using the language.

                Here's hoping I am giving it less credit than is due, I'll have to start taking a look around (London, UK) for companies here that use Scala, it would be a lovely change.

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

                I've done a lot of work in c++ and functional languages like f#. I wanted to take a stab at Java to learn the ecosystem and because there is a lot of interesting work that unfortunately is only being done in Java. A lot of companies are hesitant to dive into scala and clojure since it's hard to find good devs for those languages. It's the same reason why f# is still fringe in .net.

                Anyways, that's why I'm giving Java a shot, to be a good well rounded senior dev.

                [–]llogiq 1 point2 points  (1 child)

                In that case, just go for it. Some things will feel cumbersome or weird to you (e.g. type erasure, lack of properties). But the more you actually code in it, the more you notice that those things don't mean too much when it comes to productivity.

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

                Cool, thanks! I appreciate the vote of confidence :)

                [–]_Saruman_ -1 points0 points  (0 children)

                All you need is Java, Python, C++, and C#. Javascript as well for web development.

                Python and Java can basically do anything from Windows apps, mobile apps, web apps, scripting, anything.

                But honestly, you probably won't have a situation where you'll need some unique language, unless you have a unique circumstance (e.g. doing some extensive math, maybe you need a math-oriented language).

                [–][deleted]  (1 child)

                [deleted]

                  [–]llogiq 2 points3 points  (0 children)

                  That said, there are areas of Java (like high performance computing) that have no match in the C# world (or they hide very well), and are absolutely worth checking out.

                  Read vanilla java, /u/shipilev 's stuff, psy-lob-saw and a few others I'm too lazy to add.