Results 1 to 5 of 5
  1. #1
    tricky is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Cannot run Java program in command window

    When I try to run a simple program, even HelloWorld.java, the java file opens in NotePad and nothing happens in the command window. Below is one of the programs I tried to run which was copied from a training book.

    /*
    * SimpleMathTest
    * Performs simple mathematical operations on integer and
    * double operands
    */

    public class SimpleMathTest {

    public static void main(String args[]) {
    int x = 10,
    y = 7;
    //be careful not to confuse math operators with string
    //operators
    System.out.println(x + " + " + y + " = " + (x + y));
    System.out.println(x + " - " + y + " = " + (x - y));
    System.out.println(x + " * " + y + " = " + (x * y));
    System.out.println(x + " / " + y + " = " + (x / y));
    System.out.println(x + " % " + y + " = " + (x % y));

    //would be more readable with explicit casting
    //i.e. double a = (double) x, b = (double) y;
    double a = x,
    b = y;
    System.out.println(a + " + " + b + " = " + (a + b));
    System.out.println(a + " - " + b + " = " + (a - b));
    System.out.println(a + " * " + b + " = " + (a * b));
    System.out.println(a + " / " + b + " = " + (a / b));
    System.out.println(a + " % " + b + " = " + (a % b));

    //emphasizes that floating point modulus ops can
    //result in real numbers
    System.out.println("1.1 % 1.0 = " + (1.1 % 1.0));
    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Cannot run Java program in command window

    What exactly do you type on the cmd?

  3. #3
    tricky is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Cannot run Java program in command window

    I type: SimpleMathTest.java, which is what it is named. But even with HelloWorld.java the same thing happens. That is after setting up the environment which now appears as:

    C:\Users\Phaeton\Documents\JAVA>SET PATH=C:\Windows\system32;C:\Windows;C:\Windows\Sys tem32\Wbem;C:\jdk1.3.1\bin

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Cannot run Java program in command window

    Try typing

    Java Code:
    java SimpleMathTest
    Also, if you are using java 3 as that path implies, I'd suggest you update your java. Java is on 7 now as opposed to the 3 you seem to be using.

  5. #5
    tricky is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Cannot run Java program in command window

    That was it. I thank you much. Take care...

Similar Threads

  1. command line window on java game
    By ki_ha1984 in forum New To Java
    Replies: 3
    Last Post: 08-15-2011, 09:39 PM
  2. Replies: 0
    Last Post: 08-11-2011, 08:17 AM
  3. Letting my program command the command prompt
    By Smokey. in forum Threads and Synchronization
    Replies: 4
    Last Post: 03-29-2011, 11:34 PM
  4. Calling a JFrame window from a command line program.
    By new_2_java in forum New To Java
    Replies: 7
    Last Post: 11-09-2008, 03:40 AM
  5. Execute a jar command from a java program
    By apremanandh in forum New To Java
    Replies: 3
    Last Post: 05-21-2008, 02:04 PM

Posting Permissions

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