making a java package in the command line

前端 未结 5 821
别跟我提以往
别跟我提以往 2021-01-05 01:00

Though it\'s probably reccomended one uses and IDE for coding advanced java projects, I personally prefer running almost entirely command-line (using gedit as a text-editor)

5条回答
  •  梦毁少年i
    2021-01-05 01:39

    // to create a new directory and a subfolder that will be your package

    $ mkdir -p parent/child 
    

    // to move into it :

    $ cd parent/child                    
    

    //to create an empty java file

    $ touch MyClass.java
    

    //to edit current file

    $ nano MyClass.java
    
    package child; 
     public class MyClass { 
    }
    

    PS: The directory structure on your computer is related to the package name. That means when you edit .java file it needs to have a package declaration(your package) otherwise you will have a default package (ex: java.util.*).

提交回复
热议问题