What is the purpose of a package in Java?
A package groups related classes and interfaces together to organize code, manage namespaces, and control access.
What is a package in Java?
A package is a namespace that organizes classes and interfaces into a hierarchical structure.
Why are packages important?
They improve code organization, prevent naming conflicts, and provide access control.
How do packages prevent naming conflicts?
By allowing classes with the same name to exist in different packages.
Example of package naming conflict prevention?
java.util.Date and java.sql.Date can coexist.
What keyword is used to declare a package?
package.
Example package declaration?
package com.example.util;
How do packages support access control?
Using access modifiers like public, protected, default, and private across package boundaries.
What is the default package?
The package used when no package statement is declared.
Is using the default package recommended?
No. It is discouraged for production code.
Can packages contain subpackages?
Yes. Packages can be hierarchical, like com.company.project.module.
What is the naming convention for packages?
Lowercase names, often reversed domain names like com.company.app.
How do you use classes from another package?
By importing them using import statement.
Example import statement?
import java.util.List;
What is the difference between package and folder?
A package is a logical namespace; a folder is a physical directory.
Why are packages useful in large projects?
They improve maintainability, readability, and modular design.
Key rule to remember?
Package = namespace + organization + access control.
What is the java.lang package?
java.lang is a core package that contains fundamental classes required by the Java language and is automatically imported.
Why is java.lang important?
It provides essential classes needed for basic programming functionality.
Do you need to import java.lang explicitly?
No. It is imported automatically by the compiler.
What is the most important class in java.lang?
Object because it is the root superclass of all classes.
What common classes are in java.lang?
String, System, Object, Math, Thread, Throwable, Class.
What wrapper classes exist in java.lang?
Integer, Boolean, Character, Double, Float, Long, Short, Byte.
What does the System class provide?
Standard input/output streams and utility methods.