java compiler with the java package without package compilation

Transfer from: http: //www.biostatistic.net/home.php mod = space & uid = 12734 & do = blog & id = 1952?

Praising bloggers! Solve the problems of the problem for several days

 

Manner and compiled programs with the package without the java program package are different.

First, the program does not bring the package
to establish a HelloWorld.java file into C: \, as follows:
public class the HelloWorld
{
   public static void main (String args [])
   "! The HelloWorld" // write string to the screen
    {
      System.out.println ( "the HelloWorld!");
    }
}

1. Compile
      Compile command is javac
      compilation mode: files in the root directory of .java javac file name
such as: This file name: HelloWorld.java
          file path: C: \
      compilation process:    
cmd ENTER 
cd \ Enter
javac HelloWorld.java Enter 

Note: HelloWorld.class will generate a file under the \: At this point c.

2. Run

Enter java HelloWorld

Note: HelloWorld no suffix. 

Second, the program with a package of

Generally in accordance with the level pack to do with the file or use the package eclipse generated, how to run the compiled it using cmd?

Write a class, it is done in accordance with the hierarchical coding of the package, if at this time would like to compile by javac and java command to run, you need the following:

In c: the establishment of a HelloWorld.java \ \ under the net test file into C: \, as follows:
Package Penalty for net.test; // Note: This is the first line of the package is described, in which the back of the net point of fact, It is a directory of meaning.
the HelloWorld class public
{
   public static void main (String args [])
   // write the string to the screen "the HelloWorld!"
    {
      System.out.println ( "the HelloWorld!");
    }
}

1. Compile
      Compile command is javac
      compilation mode: files in the root directory of .java javac file name
such as: file name: HelloWorld.java
          file path: c: \ net \ test \ HelloWorld.java
          package name: net.test
compilation process:
Enter cmd
cd c: \ \ test Enter NET
javac HelloWorld.java Enter will generate a file of HelloWorld.class  
or can be generated by javac -d package catalog file name .java..

2. Run
run when you need to pay attention, not the root directory of the file, directory is the top-level directory of the package files - can be understood under the engineering directory, then run, you need to add the package name before the file name.
Run course:
cmd Enter
C: \ Enter to return to the root directory of the
java net.test.HelloWorld Enter   

generally have the package name of the situation mostly through IDE development!

Reproduced in: https: //www.cnblogs.com/yangyanzhe/p/4072606.html

Guess you like

Origin blog.csdn.net/weixin_34268753/article/details/93581553