Why do we need import statement in Java?

import statement in java allows users to access classes from different packages using the class name instead of prefixing with the full package name.

For example if you are referring to java.util.Date in your class, then instead of referring to java.util.Date where ever the date class is being used, you can just to refer it by Date. So your class would look like this

import java.util.Date;



Date date = new Date();

System.out.println(“Current Date is ” + date);

In Category: Java

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 2 Comments

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.