tags:

views:

93

answers:

3

I'm new to java can someone please explain to me whats wrong with this method:

clas Hello {
public static void main (String[]arg) {
Document.write ("hello world") ; 
}}
+2  A: 
  1. You misspelled class.
  2. Where is Document coming from?
  3. The formatting is terrible.
Ignacio Vazquez-Abrams
I think they might be getting confused with JavaScript's `document.write`.
Brian McKenna
I agree with Brian
David
Did that really warrant a downvote?
Ignacio Vazquez-Abrams
+12  A: 

This is the compiler output:

Hello.java:1: 'class' or 'interface' expected
clas Hello {
^
1 error

That means, that you should either type class or interface ( In your case it should be class )

Assuming you had an error while copy/pasting it here, the problem reported by the compiler is:

Hello.java:3: cannot find symbol
symbol  : variable Document
location: class Hello
        Document.write ("hello world") ; 
        ^
1 error

That means, the compiler doesn't know anything about a class named: Document that's what cannot find symbol means in this case.

Perhaps you want to write:

 System.out.println("Hello world");

Complete running program:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}
OscarRyz
+1 for teaching him how to understand the compiler errors, so he can learn how to solve the problems himself
Greg Beech
Nice one, Oscar.
BalusC
Thank you both. I'm teaching my self Python and sometimes error messages that look "too obvious" for a mid-level programmer in a language are completely awkward for somebody new to the lang. Having this in mind I hope my answer help to understand better the problem to the OP.
OscarRyz
+4  A: 

You probably meant this:

public class Hello {
    public static void main(String[] args) {
        System.out.println("hello world");
    }
}
Yishai
Why the downvote? Downvoting with a reason is helpful to everyone. Downvoting without one is just not.
Yishai