--Originally published at Hell Yeah
This is the first official day in my training as a Jedi Master Java Developer. I actually did this almost a week ago, but forgot to blog about it. First thing I learned: Java is nothing like Python. It seems closer to C#, but I have just glanced a little bit at the abyss, I haven’t stared at it enough.
The task at hand was to make a “Hello World” program. And I did it! This is the most basic of programs:
First we make the class which has the same name as the file, this is the program. Then we make the main function, which will be what is exectuted, in this case a single line of code which gives:
So, it works. But I started getting greedy. How about making a for loop? You got it boss.
Add the for, and then initialize it, set the termination expression, and then the increment. Done, done, done, and done. And now we see here the result:
But I still couldn’t get my fill. I needed more. I needed a while loop.
This one I actually found less confusing than the for loop, but I think it’s easier to screw up. I almost put the variable initialization inside, which would have given me an error, but in some cases it could make it infinite, like if it was initializated before and this function just resetted it to zero. I don’t really know. It scares me D: But it worked!
Now, I could have stopped here. Maybe pat myself on the back and go for an ice cream or something. But I just couldn’t stop. I had to try putting an user input on it. I thought it would be simpler than loops, in Python they would be just one extra line and one modification to another.
There’s a lot going on here that I just barely understand. What I kind of understood, was that the package java.io has the user input classes, so we import that, then create a ‘reader’ buffer for the user input to be processed. Then we use that to read the user input, store it and now we can finally use it. But that’s not all, we need to make an exception handler for whenever something get’s fucky. I used this page to get this part done, and later I will try to understand it a bit better.
The good part is that it worked.
Java is not complicated per se, it’s just that I’m not used to it. At least it is not enough to turn me to the Dark Side.