Package in java
Package is to import the java class in specific folder.In java programming already to have the so many predefined package and classes.
The user also create the create package and accessing the package classes.The below the example about the how to create the package and how to accessing the package classes.
Main.java
import Folder_name.class_name; public class Main { public static void main(String[] args) { class_name obj = new class_name(); obj.display(); } }
Folder_name/class_name.java
package Folder_name; public class class_name { public void display() { System.out.print("mycrazycoding.com"); } }
Output
mycrazycoding.com
Important Notes
- If import the import java.package_folder.* like this, the * means , You can access the all the classes in that package folder.
- In java programming already to have the so many predefined package and classes. For some example , import java.util.Scanner; , import java.util.ArrayList; and etc....
Download the code