Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Packages: Understanding the Role and Importance in Java Programming, Slides of Java Programming

An introduction to java packages, their purpose, and the process of creating and importing them. Learn about package name conventions, fully qualified names, and access specifiers for class members. Understand how packages help manage unique class names, application complexity, and application organization.

Typology: Slides

2011/2012

Uploaded on 07/03/2012

aapti
aapti 🇮🇳

4.6

(28)

82 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ava-programming
An
Introduction
Java Short Course
Example
J
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Java Packages: Understanding the Role and Importance in Java Programming and more Slides Java Programming in PDF only on Docsity!

ava - programming

An Introduction

Java Short Course Example

J

Example-Packages

  • A group of related classes
  • Each class in java belong to a specific package
  • Implemented as a folder on the disk
  • Purpose

 Unique class names  Application management  Complexity handling

  • Creating a Package

 package (keyword) package name  Should be the first statement in source file

  • Package Name Conventions

 Initial part: Internet domain name in reverse order (sun specification)  Last part: Any name that reflect the classes in package

  • Example

 Com.sun.2Dgraphics

  • Package name reflects the directory structure

package cont…

  • Fully qualified name

 Package name becomes part of class identity  A class name when written with its package name is termed as its fully qualified name  Example  my2Dgraphics.Circle  bscis.semester0.xyz.Circle  Directory structure reflected by two class files will be  outputpath/my2Dgraphics/Circle.class  Outputpath/bscis/semester0/xyz/Circls.class

  • A package can be imported to any other program using import

statement

 Import statement should placed before start of a class  Example  import javax.swings.JOptionPane;  Import javax.swings.*;

Classes and Objects Revisited

  • Class

 Declaration  Body

  • Class Declaration

 Access Specifier : public private protected  Class name  Super class name (parent class )  Interface (yet to discuss)  Keywords : class extends implements  Examples:  class Box [ just class name and class keyword]  public class Box [access specifier added ]  Public class Box extends Rectangle [ example of inheritance]  Public class Box implements printable [ interface usage]

controlling access….

  • Protected Members

 The keyword protected is written to make a member protected  A protected member is accessible to other classes with in the package  Outside the package only child classes can access a protected member  Not accessible to non-inherited classes outside the package

  • Default or Package access

 When no access specifieris used before a class member the access of that member function or variable is default or package  Such members are accessible to other classes within the package  Such members are not accessible to other classes outside the package