How to run java program
1. First we need a java program, a simple Hello Java as an example:
public class HelloJava{ public static void main(String[] args){ System.out.println("Hello Java"); } }
After saving the above code as a .txt document, change the suffix name to .java (recommended study: java course)
Get the file as shown in the figure: it doesn’t matter if the icons are different, the suffixes are the same.
#2. Next, we hold down the shift right key in the directory of the file at the same level and open the command line
3. We use the javac command to generate a .class file that can be executed on the command line, as shown in the figure:
(Ps: Pay attention to the suffix when entering Bring your name with you)
After execution, the display is as follows:
You can see that a .class file with the same name has been generated on our desktop:
#4. So how do we execute it? Use the java command:
#You can see the output "Hello Java" required in our code.
The above is the detailed content of How to run java program. For more information, please follow other related articles on the PHP Chinese website!