wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes just starting, how to run .java files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "just starting, how to run .java files?" Watch "just starting, how to run .java files?" New topic
Author

just starting, how to run .java files?

Justin
Greenhorn

Joined: Apr 23, 2006
Posts: 2
Im just starting Java, after reading a tutorial, it says i save it as .Java and i should be able to run it... but it opens in notepad.

Im using JCreator (also tried BlueJ, Eclipse and netbeans)

Any help? Thanks.


New Java Programmer.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
You will need to compile them first...

If your tutorial says you can run them directly, get another tutorial.


42
Justin
Greenhorn

Joined: Apr 23, 2006
Posts: 2
I have compiled it. Im using the tutorial here: http://www.javacoffeebreak.com/java101/java101.html


my code looks like this:



not sure if the javac and java (last 2 lines) go there or somewhere else, but it doesnt do anything if i remove them also.
[ April 23, 2006: Message edited by: Justin ]
Jon Mattson
Greenhorn

Joined: Feb 07, 2006
Posts: 19
You are supposed to write the lines javac Helloworld.java and java Helloworld in the command line.

javac Helloworld.java compiles your .java file which has your code. It creates a .class file for you.

java Helloworld runs the class file

You must using the command line go to the bin folder in which you have java.exe and javac.exe. You should also have your Helloworld.java file here.
After that you can write those 2 commands in the command line.

You say you use JCreator, never used it but atleast the Eclipse IDE got a button with which you can run your code. Also i hope you got the HelloworldFrame class otherwise that wont compile.
[ April 23, 2006: Message edited by: Jon Mattson ]
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Originally posted by Jon Mattson:

A good idea is to have your .java file in the same directory where you have javac.exe and java.exe


Pardon, but that is a bad idea. Cluttering up /bin just makes a mess.

Store your java files elsewhere, and outside of the java directory.

Something like C:/projects is much better. Then make a folder inside projects for each individual project. Keep things tidy.


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Jon Mattson
Greenhorn

Joined: Feb 07, 2006
Posts: 19
Already edited that out
I mean that that is the simplest way to get a program running. You don't need to change any paths and stuff.

Using Eclipse now which solves all problems
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

"Justin,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names, with a first and a last name.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc

PS: Putting your own files in the bin directory is a Bad Idea. You don't want to take any chances of messing up what's there.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: just starting, how to run .java files?