Professional Documents
Culture Documents
Unit4 PPL One Shot Annotated
Unit4 PPL One Shot Annotated
Unit4 PPL One Shot Annotated
using Java
Inheritances: member access and inheritance, super class references, Using super, multilevel
hierarchy, constructor call sequence, method overriding, dynamic method dispatch, abstract
classes, Object class.
Packages and Interfaces: defining a package, finding packages and CLASSPATH,
access protection,importing packages, interfaces (defining, implementation, nesting, applying)
variables in interfaces,extending interfaces, instance of operator. fundamental,
exception types, uncaught exceptions, try, catch, throw, throws, finally, multiple catch clauses
nested try statements, built-in exceptions,custom exceptions (creating your own exception
sub classes).
Managing I/O: Streams, Byte Streams and Character Streams, Predefined Streams,
Reading console Input, Writing Console Output, Print Writer class
Inheritance
* Example :-
Types of inheritance
# Example:
* Abstract classes are types of classes which help in defining a global template for various
subclasses.
* We cannot instantiate an abstract class i.e. we can't create an object for it.
Packages
* A package in Java is like a folder that groups together related classes and interfaces.
* You can imagine it as a way to organise your files so that you can easily find them.
Defining a package
* To define a package we use package keyword.
* The syntax is as follows:
CLASSPATH
* a parameter that tells the Java Virtual Machine (JVM) and the Java compiler where to look for
user-defined classes and packages when running or compiling a Java program.
* An interface in Java is like a contract or a blueprint that defines a set of methods that a
class must implement.
* It is a way to specify what a class should do, without saying how it should do it.
* Key points:
-> Method declaration
-> No implementation
-> multiple implementations
Defining an interface
* To define an interface we use interface keyword.
* The syntax is as follows:
* An exception in Java is an event that occurs during the execution of a program that
disrupts the normal flow of the program's instructions.
* Java provides various keywords like try, catch, finally and throw.
* try keyword is used to mark the block of code which might create an exception.
* For example
* catch keyword as the name says is used to catch the exception and perform the necessary
operations.
* The throw keyword is used to explicitly throw an exception. You can throw either a predefined
exception or a custom exception.
* The finally block is used to execute code that must run regardless of whether an exception
was thrown or not.
Built In Exceptions
Streams
* Stream can be defined as the channel used to transfer data from the sender and
receiver.
* An input object that reads the stream of data from a file is called input stream.
* An output object that writes the stream of data to a file is called output stream.
* Byte Stream
-> They handle I/O of raw binary data.
-> InputStream: The super classes of all the input stream of bytes.
# FileInputStream : Reads input from the file
# BufferInputStream : used to read data from an underlying input stream more
efficiently.
-> OutputStream: The super classes of all the output stream of bytes.
# FileOutputStream: Writes bytes to the files.
# BufferOutputStream: used to write data to the underlying output stream more
efficiently
* Character Stream
-> Character streams handle I/O of character data. They read and write data in
characters
-> Reader : The superclass of all classes representing an input stream of characters.
# FileReader : Reads characters from the file.
# BufferedReader : Buffers input for efficient reading of characters.
-> Writer : The superclass of all classes representing an output stream of characters.
#FileWriter : Writes characters to a file.
# BufferedWriter : Buffers output for efficient writing of characters.