Overall steps:
First step: Create a new Notepad and rename the file to Helloworld.java, the source file suffix name is . Java
Step Two: compile, use CMD compiles the javac command, which generates a . class file, which is a bytecode file (i.e. input: Javac Helloworld.java)
step three: Using the interpreter, using the CMD compile java command (i.e. input: Java HelloWorld)
/**************************************************************************************/
Details :
New Notepad--Change the file name (including the suffix name, instead . java)-- Write the program- - compile -- explain
Test code:
1 public class HelloWorld{
2 public static void main(String[] args){
3 System.out.println("welcome to imooc!");
4 }
5
6 }
(If you don't see the file suffix, set it to the folder option)
(It is best to save the program after the root of a disk, note the location, if it is stored in the e-packing directory, the file name is Helloworld.java)
Compile process: Open cmd, enter e:, enter, then enter e disk
Enter dirand enter, then view E Packing directory file
Enter "CD folder " (folder name) to enter folder
Input javac Helloworld.java, enter, see E disk generated helloworld.class bytecode file
Explanation Process:
On the basis of the compilation process and then enter the Java HelloWorld, enter (note that at this time HelloWorld do not add the suffix name of class )
Output Welcome to imooc!, proof of successful compilation
/******************* above is the MU Lesson Network Tutorial notes, the following is another collation of more detailed content ***********************/
source code under the same package:Routines:
1 package cn.arsene // package name all lowercase, often named after the company domain name
2
3 class HelloWorld {
4 public static void main (String [] args) {
5 System.out.println ("HelloWorld");
6}
7}
1. Active Type:
The first step : Compile command javac Helloworld.java generate Helloworld.class bytecode file (after that, if you edit Java HelloWorld directly, you will get an error: I can't find or load the main class HelloWorld)
Step Two: Create a new folder under the source code file directory: CN, and then create a new folder in CN: Arsene,
Step three: Put the Helloworld.class in the Arsene folder
Fourth Step: Compiling Java HelloWorld at this point will still report the same error because the package should run: Java cn.arsene. HelloWorld
Fifth Step: Compilation succeeded
2. Automatic type:
The first step: Compile javac-d directly. Helloworld.java (Note:-D after the dot is preceded by a space, no space will be error) compiled this step willautomaticallyGenerate the CN and Arsene folders and put the. class files in the Arsene folder
Step Two: With package compilation: Java Cn.arsene. HelloWorld
Step three: Compilation succeeded
The source code is under different packages:
The first step: Edit Two source codes: Demo.java and Test.java Demo.java:
1 package com.arsene;
2 / * Demo: Summation class * /
3 public class Demo {
4 public int sum (int a, int b) {
5 return a + b;
6}
7}
Test.java:
1 package com.sacker;
2 / * Test: test class * /
3 class Test {
4 public static void main (String [] args) {
5 com.arsene.Demo d = new com.arsene.Demo (); // Note the way to create objects
6 System.out.println ("d.sum (10,20)");
7}
8 }
Auto-Compile order:1, javac-d. Demo.java 2, javac-d. Test.java 3, Java com.sacker.Test Note the compilation sequence if Test.java instead:
1 package com.sacker;
2 import com.arsene.Demo;
3 / * Test: test class * /
4 class Test {
5 public static void main (String [] args) {
6 Demo d = new Demo (); // Note the way to create objects
7 System.out.println ("d.sum (10,20)");
8 }
9 }
The same as the compilation method, also can be executed, here is the Import guide package operation, in the creation of objects can be much simpler
3. Use Notepad to write Java programs and compile