Java Week One
It's been exactly one week since Head First Java and Core Java arrived on my doorstep. I finished reading through chapter 5 of Head First Java last night, and this morning I typed up the code for the SimpleDotComGame, compiled it, and played a quick game against the computer. I won!
Coming from Ruby, Java is a big change. I've never worked with a strongly-typed or compiled language before. It's not as scary as it looked from a distance, though. The Head First style can be a little annoying at times, but they explain concepts well, and it's been a gentle introduction to the language. To reinforce the syntax, I've been reading the code samples "out loud" (in my head) and talking myself through what the pieces do. For example:
public String checkYourself(String stringGuess) {...}
a public method that returns a String... The method is called checkYourself, and it takes a String argument called stringGuess...
It seems strange that methods don't start with the def keyword, so I have to think twice to recognize a method vs. a variable declaration. Aside from the explicit type declarations, there are a lot of similarities between the syntax of Java and JavaScript. (Duh, right?) Spending more time with JavaScript recently is making Java easier to read/type.
I have Eclipse installed, but for this first program, I just used Sublime Text and the Terminal. I learned some cool things about the compiler:
- It provides helpful error messages with specific line numbers.
- It doesn't like single quotes around strings.
- It won't compile an existing class that references another class you haven't written yet.
- When both classes exist, it compiles them at the same time.
Many thanks to my kind friends on Twitter who recommended these books and cheered me on when I asked for suggestions to help me get started. It's amazing to be surrounded by so many great people on this journey of learning and growing as a developer.