-2

Its on my desktop, if you could tell me step by step how i can run this program. I know javac compiles the program.

public class SimpleProgram {
    public static void main(String[] args){
        System.out.println("A proverb");
        String Proverb  = "Practice makes perfect!";
        System.out.println("Proverb");
        int CharacterCount = Proverb.length();
        Syetem.out.println("The Proverb has "+CharacterCount + "Characters");
    }
}
ObscureRobot
  • 7,306
  • 2
  • 27
  • 36
  • 1
    There are many pointer about how to do this, including this question http://stackoverflow.com/questions/1279542/how-to-execute-a-java-class-from-the-command-line or this one http://stackoverflow.com/questions/2864622/how-do-i-run-class-files-on-windows-from-command-line – madth3 Nov 11 '11 at 23:22

5 Answers5

1

From the command prompt you can use Java command to run your class and follow it in the exact syntax as follows.

C:> java SimpleProgram

r0ast3d
  • 2,639
  • 1
  • 14
  • 18
1

Running a Java Program from Command Prompt

hovanessyan
  • 30,580
  • 6
  • 55
  • 83
1

Your program will not compile, as you posted it. Here is the version that will:

public class SimpleProgram {

    public static void main( String[] args ) {

      System.out.println( "A proverb:" );
      String proverb  = "Practice makes perfect!";
      System.out.println( "Proverb" );
      int characterCount = proverb.length();
      System.out.println( "The Proverb has " + characterCount + " Characters" );
    }
}

You can compile it and run as:

$ javac SimpleProgram.java 
$ java SimpleProgram
A proverb:
Proverb
The Proverb has 23 Characters
tolitius
  • 22,149
  • 6
  • 70
  • 81
  • it wont run, it says $ javac SimpleProgram.java is not recognized as an external or internal command. – Stack Sack Nov 11 '11 at 23:13
  • I just ran it in the example above. What you need to do is to install java, or if it is installed, you need to set some EVN variables ( JAVA_HOME, etc.. ). Check the [installation instructions](http://www.java.com/en/download/help/download_options.xml) – tolitius Nov 11 '11 at 23:17
1

To compile do java SimpleProgram

If you dont want to do this back and forth get Textpad!

AshotN
  • 395
  • 4
  • 15
1

Follow this step by step tutorial- http://www.youtube.com/watch?v=5u8rFbpdvds

arsenal
  • 23,366
  • 85
  • 225
  • 331