Page 1 of 1

Running .java files

Posted: Tue Sep 26, 2006 11:40 pm
by travelerkgd
I am having difficulty running.java files following their compilation. What is typically done for a file to run properly? Thanks!

Posted: Wed Sep 27, 2006 8:18 pm
by talleyrand
You don't run .java files.
You compile (javac) .java files which creates .class files aka byte code.
You then java the .class file without the extension.
e.g.

Code: Select all

C:\foo>javac FrequentlyAskedQuestion.java
C:\foo>dir *
 Volume in drive C has no label.
 Volume Serial Number is 1F86-DC58

 Directory of C:\tmp

09/27/2006  02:53 PM              1423 FrequentlyAskedQuestion.java
09/27/2006  02:55 PM               576 FrequentlyAskedQuestion.class
               2 File(s)          1,999 bytes
               0 Dir(s)  10,255,163,392 bytes free
C:\foo>java FrequentlyAskedQuestion
This is the expeced result of running "FrequentlyAskedQuestion"

Running .class files

Posted: Wed Sep 27, 2006 10:30 pm
by travelerkgd
Yes, I know this... however I am unable to get those to run (the compiled file).... is tehre a setting or path I need to set up? I did this successfuly during a training program last year and am able to run them (they were created on anotehr machine); but I am unable to run any new files created on my local machine.