✏️ Explanatory Question
[Packages]
Question:
Why is the lang package termed as the default package in Java?
[Packages]
Question:
Why is the lang package termed as the default package in Java?
Answer:
The java.lang package is called the default package because
it is automatically imported into every Java program by the Java compiler.
Explanation:
Normally, packages must be imported before using their classes.
Example:
import java.util.Scanner;
But classes from java.lang can be used directly without writing
any import statement.
Examples of classes in java.lang:
Example:
String s = "Java";
System.out.println(Math.sqrt(25));
Here, no import statement is needed because these classes belong to:
java.lang
Important Concept:
java.lang is imported automatically by default
Conclusion:
Since the Java compiler automatically imports the
java.lang package in every program,
it is known as the default package.