- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What would getPackage() return for a primitive or array in unnamed package in Java?
The package for a class can be obtained using the java.lang.Class.getPackage() method with the help of the class loader of the class.
The getPackage() method returns null for a primitive or array in unnamed package. A program that demonstrates this is given as follows −
Example
public class Main { public static void main(String[] argv) throws Exception { Package pack1 = int.class.getPackage(); System.out.println(pack1); Package pack2 = int[].class.getPackage(); System.out.println(pack2); } }
Output
null null
Now let us understand the above program.
The getPackage() method is used to obtain the package for the class. However, the getPackage() method returns null for pack1 and pack2 as they are for a primitive data type and an array respectively. A code snippet which demonstrates this is as follows −
Package pack1 = int.class.getPackage(); System.out.println(pack1); Package pack2 = int[].class.getPackage(); System.out.println(pack2);
- Related Articles
- What would getPackage() return for a class in unnamed package in Java?
- Is an array a primitive type or an object in Java?
- What is an unnamed module in Java 9?
- Is array a primitive data type in Java?
- Prove that the interface for a primitive type is an empty array in Java
- What is the package for String Class in Java?
- How to Get a slice of a primitive array in Java?
- What is a predefined package in Java?
- Is String a primitive data type or an object in Java?
- How to detect duplicate values in primitive Java array?
- Program to convert Primitive Array to Stream in Java
- Check for the availability of a package in Java
- What are primitive data types in Java?
- How to convert Wrapper value array list into primitive array in Java?
- What are the default values of instance variables whether primitive or reference type in Java?

Advertisements