Creating a Java Class in a Package from the Command Line

  • By:SEO
  • 2024-05-08
  • 74

Creating a Java Class in a Package from the Command Line

In Java, packages are used to group related classes. Creating a Java class in a package from the command line can be a useful skill to have. To begin, open your command line interface.

$ mkdir mypackage

$ cd mypackage

$ echo ‘package mypackage; public class MyClass {}’ > MyClass.java

Once you have created the MyClass.java file, compile it using the javac command.

$ javac MyClass.java

Your Java class is now compiled. To run it, use the java command with the fully qualified class name.

$ java mypackage.MyClass

Congratulations! You have successfully created and run a Java class in a package from the command line.



CONTACT US

contact-email
contact-logo

Foshan Soonk Packaging Machine Co., Ltd.

We are always providing our customers with reliable products and considerate services.

    If you would like to keep touch with us directly, please go to contact us

    INQUIRY

      INQUIRY

        Online Service