what's wrong? my first simplest java program failed..  
Author Message
Alont





PostPosted: 2004-10-9 8:58:00 Top

java-programmer, what's wrong? my first simplest java program failed.. I created a test.java file in D:\j2sdk1.4.2_04\bin>
and the content:
class
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

then I compile it:

D:\j2sdk1.4.2_04\bin>javac test.java
test.java:1: <identifier> expected
class
^
test.java:8: '{' expected
^
2 errors

D:\j2sdk1.4.2_04\bin>

my book tell me it would work well, what's wrong?
--
Your fault as a Government is My failure as a Citizen.
 
Alex Potter





PostPosted: 2004-10-9 9:28:00 Top

java-programmer >> what's wrong? my first simplest java program failed.. Alont wrote:

> I created a test.java file in D:\j2sdk1.4.2_04\bin>
> and the content:
> class
> {
> public static void main(String[] args)
> {
> System.out.println("Hello World!");
> }
> }
>
> then I compile it:
>
> D:\j2sdk1.4.2_04\bin>javac test.java
> test.java:1: <identifier> expected
> class
> ^
> test.java:8: '{' expected
> ^
> 2 errors
>
> D:\j2sdk1.4.2_04\bin>
>
> my book tell me it would work well, what's wrong?

Your comprehension of what your book was telling you. You could try reading
it again.

Additionally, you could try something like

public class Test {
public static void main(String [] args){
System.out.println("Hello World");
}
}

in a file called Test.java.
-
Regards
Alex
The email address above is a spam-trap.
Use alexp@ the same domain to reply via email.
 
darrell





PostPosted: 2004-10-13 10:28:00 Top

java-programmer >> what's wrong? my first simplest java program failed.. On Sat, 9 Oct 2004, Alont wrote:

> I created a test.java file in D:\j2sdk1.4.2_04\bin>
> and the content:
> class
> {
> public static void main(String[] args)
> {
> System.out.println("Hello World!");
> }
> }
>
> then I compile it:
>
> D:\j2sdk1.4.2_04\bin>javac test.java
> test.java:1: <identifier> expected
> class
> ^
> test.java:8: '{' expected
> ^
> 2 errors
>
> D:\j2sdk1.4.2_04\bin>
>
> my book tell me it would work well, what's wrong?

1) Your book has a typographical error.
2) You need better attention to detail. That is, you mistyped what was
written in the book.

In either case, you must remember that compilers are VERY picky and will
not make assumptions. If I tell you, "You stORE go,, milk get." You
understand what I am trying to say. Computers will not put up with any
spelling mistakes, bad grammar, et cetera.

Additionally, you will need to read and understand error messages. Always
fix the first error and try again. Some times the second error is really
the compiler still hung up on the first error.

The first error is that the compiler expected an identifier after the
keyword 'class' on line 1. Solution put an identifier after the keyword
class, on line 1. I'll leave it to you to figure out what that means. If
you still cannot figure it out, ask again.

> --
> Your fault as a Government is My failure as a Citizen.
>

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to email***@***.com
 
 
George W. Cherry





PostPosted: 2004-10-13 11:47:00 Top

java-programmer >> what's wrong? my first simplest java program failed.. On Sat, 9 Oct 2004, Alont wrote:

> I created a test.java file in D:\j2sdk1.4.2_04\bin>
> and the content:
> class
> {
> public static void main(String[] args)
> {
> System.out.println("Hello World!");
> }
> }
>
> then I compile it:
>
> D:\j2sdk1.4.2_04\bin>javac test.java
> test.java:1: <identifier> expected
> class
> ^
> test.java:8: '{' expected
> ^
> 2 errors
>
> D:\j2sdk1.4.2_04\bin>
>
> my book tell me it would work well, what's wrong?

It's a good idea to indent your lines as necessary
to show the structure of a program (as I do below).
But that's not your fatal problem; your fatal problem
was to omit a class name. See the following.


class ClassNameGoesHere {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}


 
 
anwarmehdi@gmail.com





PostPosted: 2004-10-15 2:57:00 Top

java-programmer >> what's wrong? my first simplest java program failed.. You need to name the class as class Test {

}

(usually this kind of a class should be public as in public class Test
{ })

That's all you were missing.

Anwar