简体   繁体   中英

What is the syntax for running a Java program under the command line?

I'm having trouble how to run a NetBeans file right from command prompt. The program itself works just fine, but when I run it in NetBeans itself, it displays this, which I think is reasonable:

    Usage: java Calculator operand1 operator operand2

The main problem is when I try to run the java file right from the command line, I'm able to cd to the where the file is located, but I can't access the file right from command line.

    src\Chapter10Review>javac Calculator.java
    'javac' is not recognized as an internal or external command,
    operable program or batch file.

Any advice as to what the syntax is for accessing a java file from a command line?

First you have to set your JDK's bin folder to your PATH variable. Then the commands are available. for running a java you have the options: here

You need to install a JDK but also check your javac path in Environment variables eg C:\\Program Files\\Java\\jdk1.7.0_02\\bin; .

See the Java resources

Hope that helps.

Add JDK bin folder path to environment path variable of OS then run your code form the folder where FileName.java exists. javac will command will compile your java file and generate byte code in .class file then run your class by java command. but that class should have main method.

for more info go to this link or here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM