Home> Java> javaTutorial> body text

How to compile java files using the command line

WBOY
Release: 2023-05-19 22:52:19
forward
8206 people have browsed it

Command line compile java file

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)+"."); } }
Copy after login

1. Use Notepad or Notepad to write a complete java file and save it as a .java file.

2.cmd, open the command prompt

How to compile java files using the command line

3. Enter the .java file directory and enter the command: cd location

How to compile java files using the command line

4. Type the command, javac file name.java.

How to compile java files using the command line

#The Java compiler javac can convert .java source code files into executable .class bytecode files. Successful compilation will automatically generate a .class file.

How to compile java files using the command line

#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! ! !

How to compile java files using the command line

Run successfully! ! !

javaCompile Java source code on the command line

Compile Java source code on the command line

  • ##@author jasmyn

  • Enter the javac -version command on the command line to view JDK related information and commands.

  • javac command is used to compile and convert (.java) source files into (.class) files.

  • Then use the java command to run the compiled file.

  • Find the directory where the java file is located in cmd, enter the (javac HelloWorld.java) command,

  • After automatically generating the HelloWorld.class file , continue to enter the command (java HelloWorld).

Take HelloWorld as an example:

How to compile java files using the command line

How to compile java files using the command line

I don’t know why the runtime with package always No, Baidu has solved it later.

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!