Like other programming languages, Java also has multiple packages and classes. Packages serve as the container of the classes. Each class contains its own function. The class name will be added after the package name.
For example, if a class has a name “Example” and the package name is “java.newexample” the qualified name for this class to import it into other classes will be “java.newexample.Example”. This name will help us to use the features of one class in other classes. So that developers don’t have to add the whole code that already exists. For this corresponding purpose, the “import” keyword is used.
This write-up will describe the process of importing symbols in Java.
Syntax
The general syntax is as follows:
import "packagename.classname";
For instance:
Import java.newexample.Example;
How to Import Symbols in Java?
The import symbol feature allows programmers to utilize the features of one class in another by importing them. It will save programmers time and effort. If they import a class into another class, then it will also allow them to use it anywhere in that class instead of writing the whole code again and again or calling it manually whenever they want to use it.
Ways to Use the Imported Classes
There are two ways to use the imported classes:
- By using the “import” keyword
- By writing the path of the class
Method 1: By Using the “import” keyword
Here is a code example to understand this concept:
import java.util.Scanner;
class import_symbol_example {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
System.out.println("What is your name: ");
String name = a.nextLine();
System.out.println("The entered name is: " + name);
}
}
In this example:
- First, we import the “java.util.Scanner” library at the top of the program. It will help to take input from users.
- Now, in the “main()” method, we create an object of the “Scanner” class and ask the user for the name.
- Then, use the “System.out.println()” method to print the name of the user.
Output

Method 2: By Writing the Path of the Class
If users don’t want to import the class or library at the top of the program, then they can mention the class along with the package name which means mentioning the full path/hierarchy of the class every time to use it.
Let’s have a look at the provided example:
class import_symbol_example {
public static void main(String[] args) {
java.util.Scanner a = new java.util.Scanner(System.in);
System.out.println("What is your name: ");
String name = a.nextLine();
System.out.println("The entered name is: " + name);
}
}
Here, we take the previously discussed example, just use the full path of the class at the time of creating its object.
It can be seen that the output is similar to the previously executed code:

That’s all! We have discussed the purposes and usage of the “import” symbol in Java.
Conclusion
The Java “import” symbol allows users to import classes and libraries to use inside the program. It saves their time and effort by importing the classes or libraries. They can use their features in their code just by creating the object. There are two ways for using the imported classes, such as by using the “import” keyword and by writing the path of the class. We have illustrated the “import” symbol in Java.