Beginner problem compiling with javac

Hi I am trying to compile a program from a tutorial I am doing.

The program is titled myprogram.java and is located in the c:\src> directory.

When I use the command c:\src>javac myprogram.java I get the following errors.

myprogram.java:1: <identifier> expected

class

^

myprogram.java:8: '>' expected

^

2 errors

and when I try

c:\src> javac src\myprogram.java

I get:

error: cannot read: src\myprogram.java

1 error

I am using windowsXP and jdk1.5.0_06

I have set Path and CLASSPATH in my enviromental variables.

I am sure this is a simple problem, but if anybody would help I would really appreciate it.

Thanks.

[739 byte] By [paul221a] at [2007-10-2 14:16:42]
# 1
To help you with the compilations errors, it would help if you could post your code.The second javac command won't work if you're in the src directory. The first command you used was correct, obviously, as javac found the file.
RichFearna at 2007-7-13 12:33:01 > top of Java-index,Java Essentials,Java Programming...
# 2
It looks to me that some identifier missing in myprogram.And needs some changes to a program and compiling again
Tamazya at 2007-7-13 12:33:01 > top of Java-index,Java Essentials,Java Programming...
# 3

From the looks of it your starting you program with class myprogram, correct? if thats the case you need an identifier such as public then class. So it would look likepublic class myprogram

I'm new to this java help stuff but I hope this helps. :)

EmBraCea at 2007-7-13 12:33:01 > top of Java-index,Java Essentials,Java Programming...
# 4
WOW THANKS. That was my problem my opening line was class myprogram {as soon as i changed it to public class myprogram {It worked great.Thank you again!
paul221a at 2007-7-13 12:33:01 > top of Java-index,Java Essentials,Java Programming...
# 5

Hi thanks for the replies. my source code was:

class myprogram {

public static void main(String[] args) {

System.out.println(

"Eureka, I can put Java on my resume.");

}

}

but as soon as i changed it to

public class myprogram {

public static void main(String[] args) {

System.out.println(

"Eureka, I can put Java on my resume.");

}

}

it worked!

Now my new problem when I type

c:\src>java myprogram

i get

Exception in thread "main" java.lang.NoClassDefFoundError: myprogram

Thanks again.

paul221a at 2007-7-13 12:33:01 > top of Java-index,Java Essentials,Java Programming...
# 6
This is caused when there is no myprogram.class file in the src directory. This file is created by java when you compile the program.
EmBraCea at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...
# 7

Hi Thanks for the reply. I got the javac command working, and it compiled the file myprogram.class

so heres what I get:

Microsoft Windows XP [Version 5.1.2600]

C:\src>dir

Volume in drive C has no label.

Volume Serial Number is EC47-7752

Directory of C:\src

03/07/2006 04:19 PM<DIR> .

03/07/2006 04:19 PM<DIR> ..

03/07/2006 04:19 PM448 myprogram.class

03/07/2006 04:13 PM157 myprogram.java

2 File(s)605 bytes

2 Dir(s) 16,599,453,696 bytes free

C:\src>java myprogram

Exception in thread "main" java.lang.NoClassDefFoundError: myprogram

Hope you can help.

Thanks again.

paul221a at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...
# 8

I use an IDE to do all my java in so when it comes to compiling through the prompt I not really sure how it works. It would be worth your time to get a program like JCreator or something to type your java into. If you feel you would like to use this program you can get it at www.jcreator.com. I also wrote a tutorial on how to get it setup correctly for my classmates I could e-mail it to you should you need help.

EmBraCea at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...
# 9
Hi. Thanks for your reply. It's very hard to learn to swim when you've been climbing trees your whole life. The tutorial on how to set up JCreator would be great. My email is pulgsmth@hotmail.com Thanks.
paul221a at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...
# 10
haii have worked both of ur problem in my system(linux) and they are working perfectly.so i doubt with ur class path settings .may be ur classpath may not contain the working dir like it should end with '.'try thisc:\> java -cp c:\src\ myprogram
sdanthuluria at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...
# 11
Thank you very much that worked awesome. Now I can do some reading on java -cp and then move on to lesson 2!!!Thanks again
paul221a at 2007-7-13 12:33:02 > top of Java-index,Java Essentials,Java Programming...