0

Ok I am new to Java and was trying to run a java program from the command prompt (because Sublime compiles and runs in it's little thing but doesn't allow for user inputs and stuff).

I set the command prompt to the folder which I have my file which is called Learner.java.

C:\Users\jonat>cd C:\Users\jonat\Desktop\Projects\Java

I have set a path for my JDK bin in my environment variables and created a JAVA_HOME variable with a value to the JDK bin (which some other post suggested).

Before I go into the issue, this is my code:

class Learner {
  public static void main(String[ ] args) {
    System.out.println("Jonathan's Project");
  }
}

As you can see, it is a simple print project with "Jonathan's Project" as the output. I have already tested this in Sublime 3 and it compiles and prints.

HOWEVER, when I call upon the program in cmd prompt, it just runs for a second or so and then skips a line and starts a new command line. No "Jonathan's Project" prints which is weird because the cmd prompt shows no error and it acts like it ran the program but nothing was run...

2
  • 1
    Hint: javac invokes java compiler. Commented Aug 6, 2018 at 20:43
  • 1
    Compiling your program is not the same as running your program. Commented Aug 6, 2018 at 20:45

1 Answer 1

1

javac is to compile the program. To run the program, use thejava command. You need to compile before running the program.

Also, with javac, you need to write javac Learner.java, and with java you only need java Learner.

To learn more about compilation and execution check out this link: https://www.geeksforgeeks.org/compilation-execution-java-program/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.