Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

just starting, how to run .java files?

 
Justin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to compile them first...

If your tutorial says you can run them directly, get another tutorial.
 
Justin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jon Mattson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic