PDA

View Full Version : Urgent help with Java needed.



HOOTERS
04-09-2003, 04:34 PM
Ok, I know this is stupid but I have installed Java and I can't figure out where the hell I run it from. I've looked everywhere. I have a Java assignment due in a few days so if anybody could help that would be great.

crono_logical
04-09-2003, 06:03 PM
The bin for binaries subfolder under where you told it to install :p Alternatively add that path to the system path variable so you can run it from anywhere on the command line :p

HOOTERS
04-10-2003, 01:27 AM
I clicked on the java one in the bin folder but it just brought up a window, did stuff and then closed. Which file in that folder runs it?

crono_logical
04-10-2003, 10:15 AM
You want to run it from the command line, and it takes arguments too - the location of the compiled java program you want to run, plus any arguments that program itself requires. Running java on it's own just gives you it's usage instructions and nothing else. If you're trying to compile something, then it's javac you want, again from the command line and telling it what to compile. If your assignment requires this sort of stuff, I kind of expect them to at least tell you how to do this somewhere :p

HOOTERS
04-10-2003, 01:32 PM
They probably told me but I probably forgot.

Command line? What's that and how do I access it?

I might be asking the wrong thing. I want to open up whatever so I can start writing the code. I don't want to run any java programs, I just want to start programming in Java. Is it xcoral or something I need to run?

crono_logical
04-10-2003, 01:47 PM
You can write java programs using any text editor you like - I use emacs on linux systems and wordpad on Windows myself :p Just tell it to save the source code as a .java file when you need to save so it doesn't save a a .txt file or something. And make sure you save as plain text too :D

Command line is the DOS interface in Windows (convenient started by running "command" or "cmd" from the run box depending on Windows version), or the regular of shell or terminal in linux.

HOOTERS
04-10-2003, 02:27 PM
Ok, I think I get it now, so I just use wordpad to write the code, and java just runs/compiles it?

Once I write the code, how do I compile it? By clicking on javac?

I still don't get that command line thing but I'll try to work it out, is it where I could type: javac *.java. Or something like that to compile all java files, and is that what you mean by accessing it from anywhere?

BTW is xcoral just a text editor like wordpad?

Thanks a lot for your help, as you can see I really need it.

crono_logical
04-10-2003, 03:12 PM
Dunno what xcoral is, sounds like one for linux though.

Yes, you need to use javac *.java to compile all the java files, and then use java (blah goes here) to run the one you need to run.

chadmonkey
04-10-2003, 03:28 PM
Make sure that you name the java file itself the same that you name you java file, i.e. "HelloWorld.java" and "public class HelloWorld" etc...(and this is case sensitive). After you write your java file, open a command prompt and navigate to the folder that you saved the java file in, i.e. "C:\My Homework\Java\". Then when you're in the same folder as your java file, compile it with "javac", i.e. "javac HelloWorld.java". This will create a class file in the same folder for you, i.e. "HelloWorld.class". Then all you have to do is call the file with the "java" command, i.e. "java HelloWorld"(no file extensions on this one). That's about it, hope this helps.

p.s. Depending on how you set up your classpaths, if the command prompt says that it doesn't recognize the "javac" command, you might have to implicitly say where the "javac" command lives. That's why most people set up their classpaths so that they can call the "java" and "javac" commands from anywhere.

HOOTERS
04-10-2003, 03:48 PM
Thanks again for your help, now all I have to do is write the program. *dies*
I think my main trouble was that the computers at Uni use Linux, and that confused the hell out of me, but I have used some of those commands you mentioned before, just not in windows.


Originally posted by chadmonkey
p.s. Depending on how you set up your classpaths, if the command prompt says that it doesn't recognize the "javac" command, you might have to implicitly say where the "javac" command lives. That's why most people set up their classpaths so that they can call the "java" and "javac" commands from anywhere.

Yeah I think I did that. There was installation instructions the lecturer typed which included something about adding lines to an autoexec.bak file so you could run the commands from anywhere though I don't know if it worked or not.

chadmonkey
04-10-2003, 04:19 PM
Originally posted by Hootenanny
Yeah I think I did that. There was installation instructions the lecturer typed which included something about adding lines to an autoexec.bak file so you could run the commands from anywhere though I don't know if it worked or not.

Yep, that's what I was talking about. Of course the fun part is you won't find out if you set it up right until you try to compile it. :) I would suggest writing as simple a program as you can, with one line of hard-coded output, then try to get the program to compile and run, before you get too much more in your code. It's much easier that way.

HOOTERS
04-10-2003, 04:54 PM
Yeah I was going to make a simple program to see if it would work first. I hope you or crono_logical are online in about 12 hours so I can ask questions when it all goes horribly wrong. :D

Samuraid
04-10-2003, 08:34 PM
Using notepad is the coolio hardcore method, but using an IDE (like Textpad) is a lot easier and more efficient. You can edit code and then compile/run it directly from the editor.

http://www.textpad.com (try it out)

There are also a lot of other good editors on Linux...like Emacs (CL already mentioned that though) but they can be pretty hardcore.

crono_logical
04-10-2003, 08:35 PM
Originally posted by chadmonkey
Yep, that's what I was talking about. Of course the fun part is you won't find out if you set it up right until you try to compile it. :) That's why you try and run java and javac with no parameters as soon as you set the classpaths - if it's set up right, you'll get some garbage like how you're meant to use the program or its version or something :p