Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: how do I run a java program using javaw.exe?

  1. #1
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default how do I run a java program using javaw.exe?

    javaw.eve and java.exe are located in the C:\Program Files\Java\j2re1.4.2_04\bin directory but every time I try to run it with the code
    Code:
    public  class vm {
    
       public static void main (String[] args)   {
          System.out.println("Vending Machine");
    
    //print
    System.out.println("Hello world");
    
    
    }
    it gives me an error "Could no find main class. Program will exit."
    The file is named vm.java how do I get this to work?

  2. #2
    Join Date
    Mar 2003
    Posts
    1,700
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    You need to include the compile level libraries in the command line, along with the full path to the source code. But why are you doing it the hard way? Don't you have a Java IDE? You could just use that to run your code!

    The IDE needs to setup some environment variables that you need to run the code (when the compiler and code are not in the same directory). Outside of this, the java compiler and the code would need to be in the same directory (from my experience).

    Are you using a Java IDE? If so which one? If not, why not?

  3. #3
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    I just want to run it. Took me long enough to download, now all I want to do is run it. The files are in the same directory what " include the compile level libraries" do I need to include?

    Java IDEs tend to be slow, heavy and odd. I just want to get it running, so that I can see if the synthax is correct.

  4. #4
    Join Date
    Jun 2002
    Posts
    648
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    [quote author=owen link=board=21;threadid=4695;start=0#msg43398 date=1087778274]
    Java IDEs tend to be slow, heavy and odd.
    [/quote]

    IntelliJ IDEA ain't slow!
    Best IDE I have ever come across...packed with features

  5. #5
    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    there are two steps involved in running a java program, first you need to compile it using the javac command. then run it using the java command.
    1. cd into the directory containing u're source
    2. type javac vm.java
    3. if there are no errors, you should have a new vm.class file in the dir.
    4. java vm : this means call the main method in the vm.class file

  6. #6
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    [quote author=owen link=board=21;threadid=4695;start=0#msg43351 date=1087749116]
    javaw.eve and java.exe are located in the C:\Program Files\Java\j2re1.4.2_04\bin directory but every time I try to run it with the code
    Code:
    public  class vm {
    
       public static void main (String[] args)   {
          System.out.println("Vending Machine");
    
    //print
    System.out.println("Hello world");
    
    
    }
    it gives me an error "Could no find main class. Program will exit."
    The file is named vm.java how do I get this to work?
    [/quote]


    Remove the "public" keyword from your class declaration.

  7. #7
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    [quote author=Zeus link=board=21;threadid=4695;start=0#msg44645 date=1088488658]
    there are two steps involved in running a java program, first you need to compile it using the javac command. then run it using the java command.
    1. cd into the directory containing u're source
    2. type javac vm.java
    3. if there are no errors, you should have a new vm.class file in the dir.
    4. java vm : this means call the main method in the vm.class file
    [/quote]

    where do I get the javac.exe zues?

  8. #8
    Join Date
    Jun 2004
    Posts
    296
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    it seems to me that you downloade the wrong java distribution, a jre prefix usually means that what you have is the runtime engine, what you really want is the
    j2sdk_version_here, that is what you use for development
    with that comes the javac.exe that you need to compile java code.

    by the way when you do get the sdk, theres a bug in your code, ur missing an extra closing brace (}) at the end of the code to close the class.


    then steps to running is as easy as mentioned before
    javac <filename>.java
    you should see a <filename>.class
    then you you just call
    java <filename> (without any extensions)

    hope this helps

  9. #9
    Join Date
    Jun 2003
    Posts
    159
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    Use this link to download an IDE called 'eclipse':

    http://www.eclipse.org/downloads/index.php

    You find it to be very useful.

  10. #10
    Join Date
    Jun 2003
    Posts
    159
    Rep Power
    0

    Default Re:how do I run a java program using javaw.exe?

    public class test {

    public static void main(String[] args) {
    System.out.println("Vending Machine");

    // print
    System.out.println("Hello world");
    }
    }
    Last edited by editor; Aug 8, 2004 at 11:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •