- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Where and how is import statement used in Java programs?
Wan import statement in Java is used to −
Import user defined classes/Interfaces
Whenever you need to access a class which is not in the current package of the program you need to import that particular class using the import statement.
Example
In the following example we are using the Math class to find the square root of a number therefore, first of all w should import this class using the import statement.
import java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(Math.sqrt(169)); } }
Output
13.0
In case of static imports
static import allows to access the static members of a class without class qualifications. For Example, to access the static methods you need to call the using class name &minsu;
Math.sqrt(169);
But, using static import you can access the static methods directly.
Example
import static java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(sqrt(169)); } }
Output
13.0
- Related Articles
- Finding where-used list of SAP standard programs
- Is there a need to import Java.lang package while running Java programs?
- Why do we use import statement in Java? Where it should be included in the class?
- Where is Java Used in the Real World?
- Can we define a package after the import statement in Java?
- What is the use of import statement in Python?
- What is the use of "from...import" Statement in Python?
- What is the use of "from...import *" Statement in Python?
- How to use multiple modules with Python import Statement?
- What is static import in Java?
- What are the differences between import and static import statements in Java?
- What are native methods in Java and where are they used?
- Difference between import and package in Java?
- How to import java.lang.String class in Java?
- How to import all classes in Java?

Advertisements