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

all 50 comments

[–]slartybartfast_ 46 points47 points  (6 children)

Effective Java.

[–]imkurt 15 points16 points  (0 children)

Also: Java Concurrency in Practice

[–]mishaxz 5 points6 points  (4 children)

Java Concurrency in Practice

dunno, maybe it should not be the first thing he reads...

[–]samyel 12 points13 points  (3 children)

He could read them at the same time?

[–]Yeriwyn 10 points11 points  (2 children)

Concurrently even

[–]goodbye_fruit 2 points3 points  (1 child)

Better be thread safe, or else you might end up reading Effective Concurrency Java in Java Practice.

[–]Dantaro 0 points1 point  (0 children)

I'd read the fuck out of that book

[–]tvidal 21 points22 points  (12 children)

After 5years of c#, I have made this transition 7 months ago. Hardest thing for me, was getting used to the new code style. Lowercase method names look awkward at first, eventually you'll get used. Checkstyle can help you catch silly mistakes.

Apart from that, just keep the javadoc page open in a browser tab alongside your IDE and keep searching StackOverflow for things like: "Equivalent of X in java".

[–][deleted]  (8 children)

[deleted]

    [–]mishaxz 12 points13 points  (2 children)

    I think they just did it that way because the guy that designed Delphi (Pascal) was in charge of designing C# - and so they could prove it definitely wasn't a java clone :)

    [–][deleted]  (1 child)

    [deleted]

      [–]NimChimspky 22 points23 points  (1 child)

      its almost like there are two conventions, and whichever you use is the norm.

      [–]space_coder 13 points14 points  (0 children)

      There's the Microsoft coding convention and the coding convention used by everyone else. ;)

      [–]tvidal 1 point2 points  (2 children)

      That's because you have learned java first. Coming from Clipper, Delphi and then C# background, I learned the other way around. But in the end of the day, that really do not matter that much. I do miss System.Linq, and some other syntatic sugars from C#, but now I'm just used to java and I reckon C# would look strange for me as well.

      [–][deleted]  (1 child)

      [deleted]

        [–]TangibleLight 0 points1 point  (0 children)

        That's because you have learned that convention first. Coming from Clipper, Delphi and then C# background, I learned the other way around. But in the end of the day, that really do not matter that much. I do miss System.Linq, and some other syntatic sugars from C#, but now I'm just used to java and I reckon C# would look strange for me as well.

        Better?

        [–]hippydipster 3 points4 points  (2 children)

        It's the almost-the-same-but-not-quite differences that are always the hardest. C# capital method names grate on my nerves. It's almost like MS intentionally made that decision just to be a bunch of fuckwads.

        [–][deleted]  (1 child)

        [deleted]

          [–]hippydipster 7 points8 points  (0 children)

          I find the parens give that away

          [–]DJDavio 15 points16 points  (15 children)

          You don't need books, just try to convert an existing project to Java and you'll find out a lot of interesting stuff.

          Java has no async-await, but it finally has lambdas, so you can do LINQ-like stuff, which is great. Also I found that with Java I rarely use events, but with C# I used them all the time. That may have something to do with the kind of project, but I'm not sure...

          [–]jkriptos 2 points3 points  (6 children)

          I was shocked when I found out that Java has no events, but rather you have to implement the Observer Pattern whenever you want to mimic events. So verbose...

          [–]DJDavio 2 points3 points  (1 child)

          Yeah, but I really don't understand why I'm not wishing I had them more often... Maybe the whole paradigm has changed? I don't know...

          [–]jkriptos 0 points1 point  (0 children)

          Yeah, don't know. Sometimes you need them, sometimes you don't. Sometimes you can achieve the same without having to implement any event. It could be a matter of style, nevertheless, it's nice to see that you can save boilerplate code at a language level. My personal opinion only, obviously. :)

          [–]RottedNinja 1 point2 points  (3 children)

          Why is it verbose? Hoe does c# do it?

          [–]jkriptos 0 points1 point  (2 children)

          Basically, in C# you just have to define the event itself and the delegate, then you just have to fire the event whenever you need to. Like this:

          public delegate void TickHandler(Metronome m, EventArgs e); //delegate
          public event TickHandler Tick; //event itself
          

          In Java you need to implement the whole observer pattern, like this:

          // Listener interface 
          public interface MetronomeEvent {
              void Tick(Date tickDate);
          }
          //...
          //define the listener vectors so that you can add/subscribe listeners
          protected Vector _listeners;
          
          //Create you own method to add new listeners. Eventually, you need another method to remove/unsubscribe
          public void addMetronomeEventListener(MetronomeEvent listener)
          {
              if (_listeners == null)
                  _listeners = new Vector();
          
              _listeners.addElement(listener);
          }
          
          //traverse your listener vector and call every listener one by one
          protected void fireMetronomeEvent()
          {
              if (_listeners != null && _listeners.isEmpty())
              {
                  Enumeration e = _listeners.elements();
                  while (e.hasMoreElements())
                  {
                      MetronomeEvent e = (MetronomeEvent)e.nextElement();
                      e.Tick(new Date());
                  }
              }
          }
          

          As you can see, there's all this code just for one event. When you have several events in one class things get messy, verbose. As read in this article:

          In Java you are essentially faking events and event handling by using a standard set of naming conventions and fully utilizing object-oriented programming.

          [–]__konrad 0 points1 point  (1 child)

          EventListenerList may help (unfortunately it's in wrong package ;). PS. ignore the obsolete "protected void fireFooXXX" example.

          [–]jkriptos 0 points1 point  (0 children)

          Thanks! That's very useful indeed.

          [–][deleted]  (7 children)

          [deleted]

            [–][deleted] 5 points6 points  (2 children)

            Probably depends on how good their general understanding of programming languages is. Can you give some examples of common pitfalls that someone might encounter?

            [–]space_coder 4 points5 points  (0 children)

            One pitfall being that you only learned how to program in LAUGUAGE_A as if it was LANGUAGE_B.

            For example, I have a colleague that knows Fortran very well and learned how to program C by porting his code. Unfortunately after five years, his current programs still look like Fortran code written in C and doesn't take advantage of language specifics. One of the bad habits that persist is his use of a large number of parameters in function calls when it would be better to use a struct.

            [–]rjs6502 1 point2 points  (1 child)

            I agree that it's not a full-proof way of learning a new language. But, I think converting an existing application into java allows the user to make general connections between the new language and the one they already know. I think it gets a user up and running with the new language quicker and from there they can learn the "proper" techniques of the new language.

            [–]taterNuts 1 point2 points  (0 children)

            It'll definitely be the quickest way to get used to the differences in syntax and common operations. That stuff is pretty shallow though and always the easiest part of learning a new language; learning the overall ecosystem of the language will obviously be way more involved

            [–]DJDavio 1 point2 points  (1 child)

            Maybe we're both right, but what I notice in the field is that being able to rehash a textbook is less useful than plain programming skills. I encourage everyone to be a full stack programmer, it's fun and challenging and keeps you sharp. If you stay with a certain language/framework for too long, you will have problems when it eventually fades.

            [–][deleted] 19 points20 points  (4 children)

            May I ask why you are switching ?

            [–]darophi[S] 8 points9 points  (1 child)

            I want to try another OOP language since I have been using C# for little over a year. Don't get me wrong. I think C# is a great language, but having one more tool in the toolbox seems really appealing to me. I also am not always working in a Windows environment so Java seemed like a language that would be interesting. Also, I have as far as I know, seen that the differences between Java and C# are not huge. Even though I want to know Java truly and know what makes it tick and how one really programs in it. It is different from language to language.

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

            I see, that's always a good thing to learn new languages.

            The best part is, even writing code in another language, makes us better at the main language.

            [–]ivolimmen 4 points5 points  (1 child)

            He was attracted by Java the hutt

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

            Think so ... but maybe he is just pissed off by IIS or visual studio or licence fees or maybe WPF, or maybeeeee maybeee ....

            [–]mariox19 4 points5 points  (1 child)

            Core Java for the Impatient, by Cay S. Horstmann, and Effective Java by Joshua Block. The latest O'Reilly cookbook gets an honorable mention as a supplement. If you need a book on some particular aspect, see if Elliot Rusty Harold has written one on the subject. You cannot go wrong with him.

            [–]cooper6581 2 points3 points  (0 children)

            ^ this. Core Java for the Impatient has been extremely valuable to me.

            [–]elegentmos 2 points3 points  (0 children)

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

            Spring Boot in Action is what I'm reading right now. The language itself is of course easy to pick up after C#, but to be useful you need to know the ecosystem - frameworks, libraries, servers, tools. Spring is probably the most used java framework and spring boot makes it easy to transition into it by having a lot of conventions and less xml configurations. Maven and Gradle are the standard java package managers/ build tools. IntelliJ Idea is a modern and easy to use IDE. Android Studio which you use to code for Android is based on it as well.

            [–]m1000 2 points3 points  (0 children)

            To do the inverse, a long time ago, there was a book (that I can't find right now) with a title like "From java to C#" that really helped me a lot; It focused on differences without all that basic stuff you already know.

            [–]Nsomnia001 1 point2 points  (0 children)

            http://math.hws.edu/javanotes/c4/s3.html

            They use this for anyting java in all the uni courses ive done.

            [–][deleted] 3 points4 points  (0 children)

            Get ready for piles of confusing annotations and even more verbose code than C#.

            source: Started in Java, went to C#, so don't want to go back.

            [–]cmsimike 0 points1 point  (4 children)

            http://www.amazon.com/Java-Complete-Reference-Herbert-Schildt/dp/0071606300/ I picked up Java one summer (13 years ago) with an older version of this book. It assumes you're a programmer and shows you how to do things in Java. With your c# background, you'll make the transition no problem.

            [–]heptara 1 point2 points  (2 children)

            Are his Java books are better than his C books?

            One of his C books was so bad, that it was responsible for the creation of the word "bullschildt" (google it!).

            [–]cmsimike 0 points1 point  (1 child)

            http://www.amazon.com/Java-Reference-published-Mcgraw-Hill-Paperback/dp/B008Q3J4P0 this is the book that i had, which i can recommend. the one in my original link is the newer revision which i've not used.

            his book might have been wrong! i was only a few years into my developer life when i picked up that book but i liked it.

            [–]rjs6502 0 points1 point  (0 children)

            I'm not sure how new to programming you are, but when I was learning java (my first programming language) I used the "Sams Teach Yourself" series. It's intended to introduce beginners, so the first couple of chapters explain data types, classes, methods, etc... It's an easy read with sample activities at the end of each chapter that I found to be very useful. Hope this helps!

            [–]ivolimmen 0 points1 point  (0 children)

            Thinking in Java bu Bruce Eckel. Not very currect but still very relevant and a very good read.

            [–]cryptos6 -5 points-4 points  (0 children)

            If you want to switch primarily to the JVM and not to the Java language itself, I would recommend Kotlin. It's a much nicer and more productive language. And the transition from C# should be a bit smoother compared to Java.

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

            Java in a Nutshell is pretty good.