Import in Java

Java Import Image

Import Keyword

Here we have discussed how to Import in JAVA. Have you noticed an “import” keyword in java program?It comes at the top of the program, at the very beginning.The java import keyword is used to access the packages and its allied classes in the java program. To directly refer to a class in another package by name, use import to access built-in and user-defined packages in your Java source file.

Import in Java :

Importing specific class​ :

If you want to import a specific class from a package in your java program then you have to use this syntax.

import packageName.className;

Importing all the classes

If you want to import all the class of a package then you will the ‘*’ symbol in your syntax.

import java.util.*;

Some of the predefined packages that we can import to our code are :

Example :

  • java.lang The language fundamentals are provided by this package.
  • java.util This package contains classes and interfaces (APIs) for data structures, events, collection frameworks, and other utility classes like date.
  • java.io Classes and interfaces for file operations as well as other input and output activities are provided by this package.
  • java.math Multiprecision arithmetic classes and interfaces are available in this package.
  • java.nio The Java Non-blocking I/O framework is provided by this package, which also includes classes and interfaces.
  • java.net This package contains classes and interfaces for networking.
  • java.security This package offers classes and interfaces for security framework components like key generation, encryption, and decryption.
  • java.sql Classes and interfaces for accessing and manipulating data stored in databases and other data sources are provided by this package.
  • java.awt This package contains classes and interfaces for creating

Run

import java.lang.Math;
public class Main {

	public static void main(String args[]) {
		double a = 75.94;
		double b = 92.23;
		System.out.println(Math.max(a, b));
	}
}

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription