How to execute a Java class using the command prompt

In your role as a developer, you will use an Integrated Development Environment (IDE) to compile and run your java application. However, you must know that Java Development Kit (JDK) provides an application which compiles the java code and another application to run java applications. You can call this application from the command line.

To compile a java class from a command prompt, a developer uses : javac application. The syntax for calling this application is:

To execute a java class from a command line, a developer uses: java command followed by the name of the java class, just like in the following example:

Prior to be able to use this command line tools, you have to set your JAVA_HOME environment variable and add it to the classpath.

Add a Comment

Your email address will not be published.