0

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.

8
Contributors
11
Replies
13
Views
10 Years
Discussion Span
Last Post by InNeedOfHelp
0

Can you post the code as well?

Hi thanks for the reply. 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.

0

So let me get this straight. Are you having problems with compilation and execution i.e setting it to the correct directory,or problems with the actual program (syntaxing 'n' stuff)?

:sad:

0

i get
Exception in thread "main" java.lang.NoClassDefFoundError: myprogram
Thanks again.

Did you save the file as myprogram.java ? Could be your classpath is not correctly set.

0

I think server_crash is correct that it is a classpath problem.

My guess is the following command would work for you:

java -cp . myprogram

0

probably a classic case of not adding the current directory to the classpath.
"java -cp . myprogram" should do the trick until you learn to use proper naming conventions for your classes and members.

0

by default when u install jdk, the execution path is set to jdk1.5.../bin
.try compiling and executing your java programs in that particular directory.
this should definitely work.good luck.

0

bad idea. What you're saying is "don't learn to use your tools, here's a quick hack for the terminally lazy and stupid".

0

bad idea. What you're saying is "don't learn to use your tools, here's a quick hack for the terminally lazy and stupid".

I know that my idea is a little obvious.but paul here is just a beginner and he is just concerned with compiling his first java program for god's sake.so I just gave him a simple advice to use the default directory.

0

by default when u install jdk, the execution path is set to jdk1.5.../bin
.try compiling and executing your java programs in that particular directory.
this should definitely work.good luck.

I must admit from a nubee's point of view that would appear the most intuitive way to get your programs working. I did exactly same when I was trying to jar up my work.

However, it only has a short term benefit. Eventually, he will need to learn how to do it properly. Since this is obviously a strong reason, showing him the proper way to configure his paths may prove more beneficial. Tee he he.

0

In the command prompt you can also type (once you've changed directory to the directory where the file you're trying to compile is located):
set classpath=.
Now try compiling and running again :)
Also you might consider naming any classes you write with a capital letter, that is, renaming your file to Myprogram.java and changing the first line in your code to
public class Myprogram
I believe this is the 'proper way' to name classes.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.