CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Java · 6 min · free

Packages and Library Classes

6 min4 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

Learn what a Java package is, what java.lang and java.util give you, how import statements work, and why you should use library classes. A package is a group of related classes kept under one name, like a folder that groups files.

Follows the syllabus of: ICSE Class 9 Computer Applications, GSEB Std 12 Computer Studies

On screen in this lesson

What a package is

A package is a group of related classes
Like folders that group files
Avoids name clashes between classes
Java's ready packages form its class library

Packages you should know

PackageContainsExample
java.langcore classesString, Math
java.utilutilitiesScanner
java.ioinput, outputIOException
java.awtgraphics, windowsButton

java.lang

Imported automatically in every program
String, Math, System
Wrapper classes: Integer, Double, Character
That is why System.out.println needs no import

java.util

ClassUsed forExample
Scannerkeyboard inputnextInt()
Arrayssort, searchArrays.sort(m)
ArrayListgrowing listadd("Tea")
Randomrandom numbersnextInt(6)

import statements

import java.util.Scanner; brings one class
import java.util.*; brings all its classes
Write imports at the top, before the class
* does not include sub-packages

Why use library classes

Already tested, so fewer bugs
Saves time and lines of code
Usually faster than our own version
Everyone reads the same familiar names

Quick answers

Why does System.out.println work without an import?

It is in java.lang, which every Java program imports automatically.

What fixes the error cannot find symbol Scanner?

Add import java.util.Scanner; above the class.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. Do you need to write your own square root code in Java? No, it is already written for you. Today we learn packages, java dot lang, java dot util, import statements, and how to use library classes.

First, recall that a class is a blueprint that holds data and methods. A package is a group of related classes kept together under one name. It works like a folder on your computer that groups similar files. Two classes can share a name if they sit in different packages, so names do not clash. Java comes with many ready packages, and together they are called the Java class library.

Here are some built in packages. Java dot lang holds the core classes, such as String and Math. Java dot util holds useful tools, such as the Scanner class for input. Java dot io is for input and output, such as reading files. Java dot awt holds classes for windows and graphics. Package names are always written in small letters.

Java dot lang is special. It is imported automatically into every Java program, so you never write an import for it. It holds String, Math and System. It also holds the wrapper classes, like Integer, Double and Character, which wrap a primitive value inside an object. That is why System dot out dot println works without any import line.

Here is the Math class from java dot lang, with no import. Math dot sqrt of forty nine gives the square root, seven point zero. It prints seven point zero because sqrt always returns a double. Math dot max of four and nine gives the larger value, nine. Math dot abs of minus six gives six.

Java dot util is a toolbox package, and it is not imported automatically. Scanner reads input from the keyboard, with methods like next int. Arrays gives ready methods to sort and search arrays. ArrayList is a list that can grow and shrink. Random makes random numbers, like rolling a dice for a game.

To use a class from another package, we write an import statement. Import java dot util dot Scanner, semicolon, brings in only the Scanner class. Import java dot util dot star brings in all the classes of that package. Imports are written at the very top of the file, before the class. The star does not bring in sub packages, so java dot star does not import java dot util.

Here the import line brings in Scanner. We create a Scanner called sc that reads from System dot in, the keyboard. Next int reads a whole number. If the user types fifteen, the program prints sixteen. Without the import line, the compiler gives an error, cannot find symbol Scanner.

An import is only a shortcut. You can also write the full name of a class, called its fully qualified name. Here we write java dot util dot Scanner every time, with no import line. It works, but it is long, so programmers prefer import.

Now the real benefit of library classes. Here m holds three marks, seventy two, forty five and ninety. Instead of writing bubble sort ourselves, we call Arrays dot sort of m. It sorts the marks in ascending order. Arrays dot toString turns the array into text, stored in t. Pause and predict the output. It prints forty five, seventy two, ninety, inside square brackets.

Why should you use library classes instead of rewriting them? They are tested by millions of programmers, so they have fewer bugs. They save time, since one line replaces a whole loop. They are usually well optimised, so they often run faster. And other programmers instantly understand Arrays dot sort. In exams, still write your own logic when the question asks for it, like sorting without library methods.

You can also create your own package. The first line of the file is package, then the name, like school. The class file must sit in a folder with the same name. Other programs then use it with import school dot Student. If you write no package line, the class goes into the default package, which is what our small programs use.

Let us revise. A package is a group of related classes, like a folder. Java dot lang is imported automatically and gives String, Math and System. Java dot util needs an import and gives Scanner, Arrays and ArrayList. We import one class by name, or all classes with a star. Use library classes instead of rewriting them, unless the exam asks you to write the logic. Try Math and Arrays methods in a program of your own today.

Courses that teach this

CourseUnit
ICSE Class 9 Computer ApplicationsInput in Java
GSEB Std 12 Computer StudiesDocument Publishing and Free Tools

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →