943,969 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7266
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 7th, 2006
0

Beginner problem compiling with javac

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paul221 is offline Offline
2 posts
since Mar 2006
Mar 7th, 2006
0

Re: Beginner problem compiling with javac

Can you post the code as well?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Mar 7th, 2006
0

Re: Beginner problem compiling with javac

Quote originally posted by Narue ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
paul221 is offline Offline
2 posts
since Mar 2006
Mar 8th, 2006
0

Re: Beginner problem compiling with javac

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)?

Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 8th, 2006
0

Re: Beginner problem compiling with javac

Quote originally posted by paul221 ...
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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Mar 8th, 2006
0

Re: Beginner problem compiling with javac

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
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 8th, 2006
0

Re: Beginner problem compiling with javac

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 9th, 2006
0

Re: Beginner problem compiling with javac

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.
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005
Mar 10th, 2006
0

Re: Beginner problem compiling with javac

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".
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 11th, 2006
0

Re: Beginner problem compiling with javac

Quote originally posted by jwenting ...
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.
Reputation Points: 9
Solved Threads: 1
Junior Poster in Training
indianscorpion2 is offline Offline
82 posts
since May 2005

This thread is more than three months old

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.
Message:
Previous Thread in Java Forum Timeline: How do i change/get my port number?
Next Thread in Java Forum Timeline: Connecting modem via java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC