Data Access Modifiers and Packages Flashcards
Member Access Modifiers
Control access to class members through the keywords.
Public
members declared as public are accessible from anywhere in the program when the object is referenced.
Protected
Subclasses can access protected methods/data of the parent class.
Default
such a class, method or field can be accessed by a class inside the same package only.
Private
members declared as private are accessible ONLY to methods of the class in which they are defined.
All private data are always accessible through the methods of their own class.
Java Package
A java package is a group of similar types of classes, interfaces and sub-packages.
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.
Advantage of Java Package
1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
2) Java package provides access protection.
3) Java package removes naming collision.
For example, a package allows you to create a class named List, which you can store in your own package without concern that it will collide with some other named List stored elsewhere.
java. lang
java. io
java. util
java. applet
java. awt
java. net
java. lang - contains language support classes(primitive data types, math operations). This package is automatically imported.
java. io - contains classes for supporting input/output operations.
java. util - contained utility classes that implement data structures like LinkedList, Hash Table, Dictionary, etc and support for Date/Time operations.
java. applet - contains classes for creating applets.
java. awt - contains classes for implementing the components of graphical user interface (like buttons, menus, etc.)
java. net - contains classes for supporting networking operations.