What is a class and package in Java ? Explain difference between them
In object-oriented programming, a class is a programming language construct that is used to group related instance variables and methods. Each class expresses structural and behavioral design decisions made by the programmer to indicate what types of objects can exist when the program is executed.
A class is a cohesive container that consists of a particular kind of compile-time metadata. It describes the rules by which objects behave; these objects are referred to as "instances" of that class. A class specifies the structure of data which each instance contains as well as the methods (functions) which manipulate the data of the object and perform tasks; such methods are sometimes described as "behavior". A method is a function with a special property that it has access to data stored in an object. A class is the most specific type of an object in relation to a specific layer. A class may also have a representation at run-time, which provides run-time support for manipulating the class-related metadata.
Package is a mechanism for organizing Java classes into namespaces. Java packages can be stored in compressed files called JAR files, allowing classes to download faster as a group rather than one at a time. Programmers also typically use packages to organize classes belonging to the same category or providing similar functionality.
Java source files can include a package statement at the top of the file to designate the package for the classes the source file defines.
• A package provides a unique namespace for the types it contains.• Classes in the same package can access each other's protected members. • A package can contain the following kinds of types. o Classes o Interfaces o Enumerated types o Annotations
