Java Packages

24blognews
2 min readNov 16, 2023

In general, we store multiple extension files like audio, text, media in a specific location inside a folder into our PC’s. The same happens here in java, numerous predefined methods, classes and framework are stored in a specific bag called packages in java and like our folders have unique names for distinguishments purposes, same here happens in java too, every inbuilt package got its own unique names.

Like we create folders on our own, in java too we can create own packages.

So, in java programming, we can have built in or user defined, these two types of packages.

In Java Api which comes with the Java Development Environment, built in packages comes which are brought or impoted inside a java code as per requirement.

Here is the syntax for calling a package

import package.name.Class;

now we can either import a single class of package or just can call the whole package.

import package.name.*;

Example below demonstrates the use of scanner class nextLinne() method from a package java.util. Method nextLine() functions is to recites the complete line along with user’s input.

Copy the code below and run it

import java.util.Scanner;

class narayan {

public static void main(String[] args) {

Scanner myObjectMahadev = new Scanner(System.in);

System.out.println(“Enter the messiah name “);

String messiah_name = myObjectMahadev.nextLine();

System.out.println(“messiah name is: “ + messiah_name);

}

}

After successful compilation following output shows up into console, here first user input is asked, and then scanner class next() method reads the whole user input data and prints up onto console.

Enter the messiah name

narayan haree

messiah name is: narayan haree

keep coding and visit below for more practice tutorials

https://www.roseindia.net/java/ #javapackages #javacoding #package

--

--