Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with compiling

 
james thompson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read through all the steps here
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html

I am trying to compile the hello world program and I keep getting these errors as seen in my attachment. What am I doing wrong here?
helpplease.jpg
[Thumbnail for helpplease.jpg]
my problem
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to add classpath.

execute the following command.

java -cp . HelloWorldApp
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15272
37
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the section Common Problems (and Their Solutions) in that same tutorial - it explains the exact error message you get and what to do about it.
 
james thompson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:James,
Welcome to the Ranch.

java HelloWorldApp will run the application. To compile, you need to run javac HelloWorldApp.java


Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.

I dont understand the cp? Where am I pointing it to?

Edit ok after further reading thanks to your guys suggestions I got it... Now here
set CLASSPATH=
Now enter java HelloWorldApp again. If the program works now, you'll have to change your CLASSPATH variable. To set this variable, consult the section in the JDK 6 installation instructions. The CLASSPATH variable is set in the same manner.

So i need to set the CLASSPATH variable somewhere else to avoid this problem in the future?
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
james thompson wrote:
Yes i have already compiled it using the javac HelloWorldApp.java and it made the .class file this is the error i get when i try to run this file.


Well your post title said help with compiling and you also said I am trying to compile the hello world program and I keep getting these errors
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CLASSPATH is set a list of directories or jar files separated by ";" (in windows).

CLASSPATH is used by JAVA Virtual machine to find the classpaths.

When you run "java HelloWorldApp", here *java* program is the virtual machine and *HelloWorlApp* is your main class.
So it will try to search for HelloWorldApp in CLASSPATH path, if it is defined.

If CLASSPATH is not defined, current directory is by default assumed as the classpath.


 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will suggest you, to go through the following link..

http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use copy-and-paste to post the error messages, not screen capture. Click the top left icon on the command window, then edit, then mark, then highlight the text with the mouse, then enter to copy to clipboard. It is much easier to read.

When you compiled the file, with
javac HelloWorldApp.java
I presume you got no error messages? If the file compiles, nothing happens; you only get error messages if something goes wrong. Try the "dir" instruction to see where the .class file is.
If it is in your current directory, try the earlier suggestion of
java -cp . HelloWorldApp
Remember the java tool doesn't require extensions.

If that doesn't work, post the code you are compiling.

You should not normally set a system classpath, but some applications eg QuickTime, set a system classpath which can b*gg*r up your normal Java settings. If that is the case add .; to the beginning of the system classpath. You can have several .s in your classpath; I have tried it, and it doesn't seem to do any harm.
 
james thompson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys for all the help now I can finally start working through my head first java book
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it working?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic