World's most popular travel blog for travel bloggers.

Explain the need of package in Java. Write a java program to show how package is created

, , No Comments

 A Java package is a set of classes which are grouped together. This grouping helps to organize Java classes and interfaces classes with the same name.

  • A package provides a unique namespace for the types it contains.
  • Classes in the same package can access each other’s package-access members.

Creating package

package world;

public class HelloWorld {

  public static void main(String[] args) {

    System.out.println(“Hello World”);

  }

}

Calling package

import world.*; 

import world.moon;

PATH: maintains a list of directories. The OS searches the PATH entries for executable programs, such as Java Compiler (javac) and Java Runtime (java).

CLASSPATH: maintain a list of directories (containing many Java class files) and JAR files (a single-file archive of Java classes). The Java Compiler and Java Runtime searches the CLASSPATH entries for Java classes referenced in your program.

0 comments:

Post a Comment

Let us know your responses and feedback