Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between class and package

Tags:

java

What is the difference between a class and a package in Java ?

like image 355
surya narayana raju g Avatar asked Aug 11 '11 05:08

surya narayana raju g


People also ask

What is class and package in Java?

A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories: Built-in Packages (packages from the Java API)

What is project package & class?

A project is an IDE-level grouping; its a set of source files, configurations, assets, ect. that make up a working application. A package, on the other hand, is a grouping of related classes/source files.

What is the difference between package and interface?

The main difference between package and interface is that a package is a collection of related classes and interfaces while an interface is a collection of fields and abstract methods. Package and interface are two main concepts in Object Oriented Programming based languages such as Java.

What are the different class packages in Java?

Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Here, we will have the detailed learning of creating and using user-defined packages.


2 Answers

A class is a declaration (and often implementation) which encapsulates the members properties and methods which instances of that type will posses. You can create instances of a class as distinct, individual objects that behave as specified.

A package is simply a namespace under which you can categorize classes, analogous to a "folder" or "path", so you can group classes with related purpose or functionality.

Don't be confused by the fact that Java has classes which represent both the concept of a Class and a Package which are useful for inspecting the structure of Java programs at runtime. They are merely models of the general concepts described above.

like image 194
maerics Avatar answered Oct 10 '22 05:10

maerics


Quite simply a java package is a namespace where classes are organized based on the same category or functionality

Java classes is an object that consists of behaviours (methods), properties (variables), constructors (if any, for object creation), etc. that exists inside a folder (package).

like image 21
Buhake Sindi Avatar answered Oct 10 '22 06:10

Buhake Sindi