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.
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.
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)?
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.
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.
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.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.