How Do Packages Work In Java
Packages are used to store related classes in one folder for better code maintenance and reusability. Here are some details that you need to understand to create and use packages in Java: Why we need packages What is package hierarchy How to place class in a package and compile it How to use classes placed in other packages How to compile to place .class files separate from source files What is NoClassDefFoundError How to use classpath to link classes placed at other locations and libraries Lets see each section one by one: Why we need packages When we start learning Java, we usually place different classses in same folder but real Java applications has tens or even thousands of classes, as the project size increase, so the number of classes. Most software consists of multiple modules and each module may consists of multiple classes. If we place all classes in one folder, it become difficult to locate a particular piece of code or a class that provide a specific functio