Home >Java >javaTutorial >How to compile java files using the command line
import java.util.*; public class shuchu{ public static void main(String[] args) { Scanner in=new Scanner(System.in); System.out.print("what is your name?"); String name =in.nextLine(); System.out.print("How old are you?"); int age=in.nextInt(); System.out.print("Holle,"+name+".Next year,you'll be "+(age+1)+"."); } }
1. Use Notepad or Notepad to write a complete java file and save it as a .java file.
2.cmd, open the command prompt
3. Enter the .java file directory and enter the command: cd location
4. Type the command, javac file name.java.
#The Java compiler javac can convert .java source code files into executable .class bytecode files. Successful compilation will automatically generate a .class file.
#5. Type the command, java file name. Note that it must also be in the .class file directory at this time. If not, repeat the third step. And there is no need to add the .class suffix after the file name in this step! ! !
Run successfully! ! !
Compile Java source code on the command line
The above is the detailed content of How to compile java files using the command line. For more information, please follow other related articles on the PHP Chinese website!