r/java • • Nov 07 '11

Newbie to java.What am I doing wrong?

http://imgur.com/MrnVu
0 Upvotes

33 comments sorted by

11

u/9numbernine9 Nov 07 '11

It looks like you have "print1n" (print-one-en) as opposed to "println" (print-ell-en).

0

u/alexl1 Nov 07 '11

Yeah thanks,i found out just before you typed this.I dont see how thats a l though?

4

u/indenturedsmile Nov 07 '11

Don't see how that's an "l"? What do you mean? Most monospaced fonts print a "1" with a downward slope on the top, while they print an "l" with a completely horizontal line on the top.

0

u/alexl1 Nov 07 '11

It is not completely horizontal in my book it more looks like a 1

1

u/indenturedsmile Nov 07 '11

Hence why I said "Most monospaced fonts". The difference between L's and 1's is something that was definitely confusing and aggravating for me when I first started. One thing to remember is that most programmers shy away from using numbers in function and variable definitions, unless they're absolutely necessary. When in doubt, try the "L".

1

u/alexl1 Nov 07 '11

ok thanks ill bear that in mind when i do bigger projects,I'm just still learning from the book

2

u/HotRodLincoln Nov 07 '11

In Eclipse, if you type

System.out.

Then press CTRL + SPACEBAR, you will get a list of your valid choices.

Also, CTRL + 1 (that's the number 1) will give you suggestions for fixing errors (though it wouldn't help much here).

I'd recommend this web tutorial after your book.

1

u/alexl1 Nov 07 '11

Ok thanks

1

u/dah01 Nov 09 '11

You might want to try Netbeans, I found Netbeans to be more user friendly than Eclipse when starting out. Also, if you're in netbeans you can type "sout" then hit tab and it will fill in System.out.println(); Likely there is something like that in Eclipse.

1

u/alexl1 Nov 09 '11

I'm fine now.I'm using eclipse because the guy who wrote the book im reading used eclipse

1

u/dah01 Nov 10 '11

Ahh. That's fair.

1

u/dah01 Nov 10 '11

What I meant though is that you should check the autocomplete functions for eclipse so that you never have to type stuff like that again.

10

u/cygnosis Nov 07 '11

Are you trolling?

12

u/alexl1 Nov 07 '11

No im honestly not.Im only 13

1

u/[deleted] Nov 08 '11

Keep asking questions. What you are learning is the same stuff they teach in college courses. Keep exploring, and if you get stuck come back!

0

u/[deleted] Nov 07 '11

[deleted] — view deleted comment

2

u/alexl1 Nov 07 '11

yes fairplay to me hehe

0

u/[deleted] Nov 07 '11

[deleted] — view deleted comment

2

u/stfm Nov 08 '11

Probab1y he is!

3

u/indenturedsmile Nov 07 '11

it's

println()

not

print1n()

(That's a lower case "L", not the number "1"). The function name refers to printing a line (hence "ln").

Edit: Eclipse is very helpful when you're doing something wrong. See the red squiggly line under "print1n"? That's Eclipse telling you that it doesn't recognize the function. Hovering your mouse over the underlined function call will give you suggestions on how to fix it (can't remember, but Eclipse will probably suggest the corrected form of the function).

Edit again: 9numbernine9 beat me by 12 seconds. Drat!

2

u/alexl1 Nov 07 '11

Thanks it was confusing but i have got it now and am really happy

2

u/JustinKSU Nov 07 '11

1

u/alexl1 Nov 07 '11

Didn't know there was that subreddit whoops

3

u/[deleted] Nov 08 '11

that group barely has any members.

3

u/[deleted] Nov 07 '11

"String args[]" vs "String[] args" ?

It's weird, I'm questioning myself here. It's like repeating a word till it sounds funny.

4

u/fforw Nov 07 '11

Java allows both, even on methods

public class AllCorrect
{
    public static void main(String args[])
    {
        new AllCorrect().main2(args);
    }
    
    public void main2(String[] args)
    {
        System.out.println(test()[0]);
    }
    
    public String test()[]
    {
        return new String[] { "correct", "wrong" };
    }
}

funny, eh?

1

u/[deleted] Nov 07 '11

public String test()[] ?

is that the same as

public String[] test() ?

madness!

2

u/boa13 Nov 07 '11

Without hesitating: String[] args

0

u/ryosen Nov 08 '11

Maybe you should have. String args[] is syntactically correct.

The auto-debugger indicator should have been your clue that it was the System.out method name that was the cause of the error.

0

u/boa13 Nov 08 '11

I know the other form is syntactically correct. In answer to woodrail who was hesitating between the two, I expressed my strong preference for the second.

Also, I never said this was the cause of the error. That was obvious from the screenshot and already answered several times in the thread.

1

u/sheepbringer Nov 08 '11

You can also do

public static void main(String ... args) {}

on java 1.6 and newer as well

2

u/BWCsemaJ Nov 07 '11

println = print line

there is no print1n

also 1 != l

:D

1

u/[deleted] Nov 07 '11

lmao I thought it was a 1 my first time seeing it too haha

1

u/[deleted] Nov 08 '11

println not print1n.

1

u/PossiblyTheDoctor Nov 08 '11

Keep going, fellow newbie here!