Hacker News new | ask | show | jobs
by galdosdi 1057 days ago
Are you trolling? That's 4 lines of code any Java dev can type from memory.

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

That's it. This is covered in chapter one of any Java book.

Am I misunderstanding your point or something? It sounds like you are complaining that Java is hard to get a simple hello world running without IDE help, but I must surely be misunderstanding you, because that would only be the case if you refused to do even the most cursory reading beforehand

2 comments

Not trolling. The last time I had done this was in the Java 1.0 days.

I would invite you to re-read your code and see how many different things you need, and how they are expressed differently in different places.

"Any Java dev" - I'm not a Java dev. I'm a dev who sometimes writes Java. I am not good at remembering equivalent commands across languages. For instance, there's not much call to remember System.out.println when writing Spring Boot apps.

Different people have different skills. For instance, some people can communicate without insulting people. This is a valuable skill to grow a career.

Also, there are things not shown, like environment variables.

I love your comment as an example of "This is so simple, there are only 20 things that you have to get perfect, any idiot can do that"

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.

` 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...
Assuming you have Java installed. And it's on the path.

That may not sound like much, but it's the kind of thing that is incredibly hard to figure out if you don't know what the problem is. Command lines are kind of unforgiving. When something is missing, the errors are often unhelpful. And if your next crack at it doesn't work, you get the identical error.

Googling stackoverflow isn't going to help, either.

This isn't supposed to be a major challenge. But it can really throw off a beginner. And even an experienced developer will feel stupid to have to say, "Sure, I can program in 30 languages, but I don't know how to install the FooLang compiler."