Beginner problem compiling with javac

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2006
Posts: 2
Reputation: paul221 is an unknown quantity at this point 
Solved Threads: 0
paul221 paul221 is offline Offline
Newbie Poster

Beginner problem compiling with javac

 
0
  #1
Mar 7th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,850
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 754
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Beginner problem compiling with javac

 
0
  #2
Mar 7th, 2006
Can you post the code as well?
New members chased away this month: 4
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 2
Reputation: paul221 is an unknown quantity at this point 
Solved Threads: 0
paul221 paul221 is offline Offline
Newbie Poster

Re: Beginner problem compiling with javac

 
0
  #3
Mar 7th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Beginner problem compiling with javac

 
0
  #4
Mar 8th, 2006
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)?

*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Beginner problem compiling with javac

 
0
  #5
Mar 8th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 216
Reputation: hooknc is an unknown quantity at this point 
Solved Threads: 8
hooknc hooknc is offline Offline
Posting Whiz in Training

Re: Beginner problem compiling with javac

 
0
  #6
Mar 8th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Beginner problem compiling with javac

 
0
  #7
Mar 8th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Re: Beginner problem compiling with javac

 
0
  #8
Mar 9th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Beginner problem compiling with javac

 
0
  #9
Mar 10th, 2006
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".
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 82
Reputation: indianscorpion2 is an unknown quantity at this point 
Solved Threads: 1
indianscorpion2 indianscorpion2 is offline Offline
Junior Poster in Training

Re: Beginner problem compiling with javac

 
0
  #10
Mar 11th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 4675 | Replies: 11
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC