Beginner cmd Compile run Java file, partial path to case-sensitive

Source: Internet
Author: User

① preparatory work

First write Helloworld.java to G:\Javaspace path with Notepad

 Public class helloworld{publicstaticvoid  main (String []args) {System.out.println ( "Hello World");}}

because I want to compile the Java file on the G-Disk, in the cmd window input

G:

Go to the G-Tray directory (online Although CMD is not case-sensitive, but this letter is to be capitalized!) )

And then enter

CD Javaspace

The CD is the cmd directory command (change directory), at which time the CMD directory is transferred to the directory where we Helloworld.java.

② compiling

The next step is to tell the cmd helloworld.java and Java compiler (i.e., Javac) where

There are two ways to set the Java compiler path

One is the set path command with CMD (this is a once and for all method, only set once)

SET Path=c:\program files\java\jdk1.8.0_20\bin;%path%

(The path after the drive letter is case-free)

The second way to set the compiler path is to specify it at compile time, because we have already moved to the G:\Javespace directory, so enter directly

"C:\programs Files\java\jdk1.8.0_20\bin\javac" Helloworld.java

(Helloworld.java file names are case-sensitive)

If there is no error prompt after pressing ENTER, the Helloworld.class file should have been generated under G:javaspace, indicating that the compilation has succeeded

③ Run

If CMD is not exited at this time, the cmd directory is still G:\Javaspace and the input

Java HelloWorld

Java excites the JVM and runs Helloworld.class, and the HelloWorld here does not have to be suffixed. class

If you are prompted to "cannot find or load the main class", then the CLASSPATH path set when installing the JDK is not G:\Javaspace and can be reset in "My Computer-Properties ...--Environment variables"

You can also temporarily modify the classpath path in cmd and enter

JAVA-CP G:\javaspace HelloWorld

This line command means to start the JVM and set Classpath, and then run Helloworld.class

Beginner cmd Compile run Java file, partial path to case-sensitive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.