Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Where to save my .java files?  RSS feed

 
Dane Cook
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im working on certain programs at school and i want to take them home, so i dl the necesary crap needed for it. i can cimpile it and execute it fine, except i get an Invalid class path error... where do i need to save my files so that i can run them properly?
 
Mark Van Tuyl
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to save your programs anyplace you want to. In order to run the compiled program, use the command:

java -cp . MyProgram

The "-cp ." parameter tells Java to look in the current directory for the specified class file. In this case that would be MyProgram.class.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, my four-wheel-drive-loving friend,

Welcome to JavaRanch!

A bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Obviously fictitious names and "handles" don't cut it. You can change your display name here. Thanks!
 
Dane Cook
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error : Invalid path, \bin\javac.exe -classpath "C:" -d C: C:\Example1.java"

i tried just saving it on my C: drive. the file name is Example1.java. what line of code do i need at the beggining to get rid of this error and get my program to run?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the "invalid path" error is caused by typing "\bin\javac.exe". While this will work in a Unix-based system, it will not work under Windows. First, I am assuming that you are using the command-line and typing the command to compile this code. If this is a bad assumption, please describe how you compile your code. With that in mind, you can fix this problem by first finding where javac.exe is installed on your computer. Then you need to type the full path (which probably starts with "C:\") to the javac.exe file. Once you get it working that way, you probably want to modify your PATH variable so you don't have to type it all out every time.

If this is not clear, please let us know and someone here will be glad to help you further.

Layne
 
Mark Van Tuyl
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to enter this command to compile your program:

javac -cp . Example1.java
 
Dane Cook
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not typing any of that in, actually i didnt know where that bin/javac came from. im using JCreator to compile my code. at school i use the line import cs1*.; at the beggning of all my code, and that works, and i dont question it.

anyway, i found that file somewhere (it just said the folder "bin"... not on my C: drive, not anywhere. so i copied the file, put it on my C: drive, bvut no difference. is JCreator looking for files in that bin.javac folder or something? can i make it look in the C drive?


EDIT: mark, just saw ur reply. i tried that, heres the code:


javac -cp . Example1.java

public class Example1

public static void main(String args[])
{

int i, sum, num;


sum = 0;

for (i=1; i<=5; i++)
{
System.out.print("Enter a number : ");
num = Keyboard.readInt();

sum = sum + num;

}

System.out.println("The Sum is : " + sum);

}
}

same error message.
[ September 30, 2005: Message edited by: Dane Cook ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go to the following page and follow the steps exactly:
The Java Tutorial - Getting Started - Your First Cup of Java
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with JCreator, but my guess is pretty much what you said. It is looking for a folder called bin that contains the javac.exe file. To fix this, you need to find out which folder has javac.exe. Then you need to figure out how to tell JCreator this location. There should be an option in the menus to do this. Sorry that I cannot be of any more help. If you want to learn Java using the command-line instead of JCreator, I will be able to help you more.

Layne
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For JCreator:

Go to your configure menu (this is version 3. Higher versions may be different)
Options
JDK profiles
click on the profile there and it should show you the class path toward the bottom of the window. Clicking on edit will show you all the paths JCreator has setup. This is where JCreator gets that java runtime and Javac.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sree sowmya,
Your post was moved to a new topic.

[Edit]There was something wrong with that new topic link, which I have corrected. CR[/edit]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!