Hacker News new | ask | show | jobs
by galdosdi 1057 days ago
Yeah, I'm sure it's hard, if you try to do it from memory and haven't done it in years. You could just take 5 min to refresh your memory by looking at the first 3 pages of any Java book though. Or stack overflow for goodness sake. "Hello world in Java"

This is an example of making things harder on yourself for no reason and then complaining about your tools instead of your own artificial restrictions. There's no shame in looking some syntax up if you haven't done it in many years.

You said there were 20 things in there but I only count two unique values that aren't just boilerplate you could look up in a minute-- the package name and class name.

I just get tired of these kinds of superficial complaints about java "lol hello world takes 4 lines instead of 1" -- that barely affects any program that's more than 20 lines long. I just think you're part of the generation that grew up making fun of Java and it's just reflexive at this point. But, it's unfair.

Compare to a language like ruby -- hello world is one line but I have to learn a bunch of weird symbols

Lol, that said, the latest Java edition now has a way to avoid the public class business so your hello world can just be 3 lines, one of which is the closing brace. They did it to shut up these kinds of trivial complaints.

2 comments

` package foo;

public class Hello {

public static void main(String[] args){

System.out.println("hi world"); } } `

#As for the build and run,

javac foo/Hello.java

java foo.Hello

---

Structure

You need: a package*, a class*, and a main method*

3

Code

The package needs to match the folder* : 1

The class needs to be public* and match* the file name; Main method needs public* and static* and take an array of String args*; you need to remember the call to output to console* : 6

Build and Run

Have to remember javac* and java* : 2

javac and java have to be available when you call them

0 - 10 [10 if you have corporate IT managed machine] (I'll call this 1)

Remember where to put the package for each call : 2

---

So I only got 15. I could have probably got more if I tried. Just because each of those 15 things is trivial by itself, does not mean you can ignore them.

I got to do 'the algorithm game' with middle-schoolers. I was the "Peanut Butter and Jelly Sandwich Robot". I took their instructions literally. It was a hoot. It's less fun when the computer isn't trying to help you.

Agreed. Modern Java is nice to work in. And to your point, I wouldn't know how to write even the single Ruby or Python line without looking it up since I don't use those every day. Though, I could cycle through print, println, printf, etc...