This document provides an overview of packages, interfaces, and stream-based I/O in Java. It defines a package, discusses access protection and importing packages. Interfaces are introduced as a way to achieve multiple inheritance in Java. Key characteristics of interfaces like not allowing implementation and only containing abstract methods are described. The relationship between interfaces and abstract classes is compared. Common interfaces like Comparable are explained. Finally, stream-based I/O concepts like character streams, reading/writing files and serialization are listed as topics to be covered. Universities questions on these topics are also provided.
What Are The Drone Anti-jamming Systems Technology?
JAVA PROGRAMMING – Packages - Stream based I/O
1. JAVA PROGRAMMING –
Packages - Stream based I/O
Dr R Jegadeesan Prof-CSE
Jyothishmathi Institute of Technology and Science,
Karimnagar
2. SYLLABUS
Packages- Defining a Package, CLASSPATH, Access protection, importing
packages. Interfaces- defining an interface, implementing interfaces,
Nested interfaces, applying interfaces, variables in interfaces and extending
interfaces.
Stream based I/O (java.io) – The Stream classes-Byte streams and
Character streams, Reading console Input and Writing Console Output, File
class, Reading and writing Files, Random access file operations, The
Console class, Serialization, Enumerations, auto boxing, generics.
3. UNIT 2 : PACKAGES, INTERFACES, STREAM BASED I/O
Topic Name : Introduction to Packages, Interfaces, Stream based I/O
Topic : Introduction to Packages, Interfaces, Stream Based I/O
Aim & Objective : To make the student understand the concepts of creation of
packages, interfaces and stream classes
Application With Example :Java programs to create and access the packages and
implementing interfaces. Java program to read and write data from and to streams.
Limitations If Any :
Reference Links :
• http://javabeginnerstutorial.com/core-java/
• Java The complete reference, 9th edition, Herbert Schildt, McGraw Hill Education
(India) Pvt. Ltd.
• https://www.tutorialride.com/core-java/packages-interfaces-in-java.htm
• Video Link details
• https://www.youtube.com/watch?v=iIwyrdc3Zvw
4. Universities & Important Questions :
• Define a package. What is the necessity of packages?
• What are the packages provided by Java API?
• Discuss about packages of java language
• What is a package? How do we design a package?
• What is package? Explain the procedure to create a package with the help of example
• How do you create a package? Explain about access protection in packages.
• What is the major difference between an interface and class?
• Compare and contrast between class and an interface.
• Define abstract class and interface and what the difference between them and
explain with Suitable examples
• How to design and implement an interface? Explain with example.
• What is multiple inheritance? Explain how it can be implemented in Java with the
help of an example
• Explain how interfaces can be implemented.
• Write an interface called Shape with necessary methods. Derived classes circle,
rectangle, triangle, cone, sphere and cube with appropriate constructors and
methods for area, volume also setting and displaying.
• Java does not support multiple inheritance. Then how is the problem solved explain
with suitable example.
5. ▪ Packages
▪ Interfaces
▪ Stream based I/O
▪ Serialization
▪ Enumeration
▪ Generics
UNIT – II
CONTENTS
6. Interfaces
• In Java, only single inheritance is permitted. However, Java
provides a construct called an interface which can be
implemented by a class.
• Interfaces are similar to abstract classes (we will compare the
two soon).
• A class can implement any number of interfaces. In effect
using interfaces gives us the benefit of multiple inheritance
without many of it’s problems.
• Interfaces are compiled into bytecode just like classes.
• Interfaces cannot be instantiated.
• Can use interface as a data type for variables.
• Can also use an interface as the result of a cast operation.
• Interfaces can contain only abstract methods and constants.
7. Interfaces (cont)
• An interface is created with the following
syntax:
modifier interface interfaceID
{
//constants/method signatures
}
8. Syntax
public class Circle extends
GeometricObject implements
Comparable {
/* define class here make sure
to implement all the abstract
methods contained in the
interface(s)*/
}
9. Interfaces (cont)
• An interface can extend other interfaces with the following
syntax:
modifier interface interfaceID extends
comma-delimited-list-of-interfaces
{
//constants/method signatures
}
• Obviously, any class which implements a “sub-interface” will
have to implement each of the methods contained in it’s
“super-interfaces”
10. Interface Abstract class
Fields Only constants Constants and
variable data
Methods No implementation
allowed (no
abstract modifier
necessary)
Abstract or
concrete
Interface vs. abstract class
11. Interface vs. abstract class (cont)
Interface Abstract class
Inheritance A subclass can
implement many
interfaces
A subclass can
inherit only one
class
Can extend
numerous
interfaces
Can implement
numerous
interfaces
Cannot extend a
class
Extends one class
12. Interface vs. abstract class (cont)
Interface Abstract class
Root none Object (of all
classes)
names Adjective or
Nouns
Nouns
13. Comparable interface
• This interface imposes a total ordering on the
objects of each class that implements it. This
ordering is referred to as the class's natural
ordering, and the class's compareTo method is
referred to as its natural comparison method.
int compareTo (Object o)
Compares this object with the specified object for
order. Returns a negative integer, zero, or a
positive integer as this object is less than, equal to,
or greater than the specified object.