Core Java
Core Java
If subclass (child class) has the same method as 3) Java package removes naming collision.
declared in the parent class, it is known
What are Java Excep ons?
as method overriding in Java.
In Java, Excep on is an unwanted or
In other words, If a subclass provides the
unexpected event, which occurs during the
specific implementa on of the method that has
execu on of a program, i.e. at run me, that
been declared by one of its parent class, it is
disrupts the normal flow of the program’s
known as method overriding.
instruc ons. Excep ons can be caught and
Usage of Java Method Overriding handled by the program. When an excep on
occurs within a method, it creates an object.
o Method overriding is used to provide This object is called the excep on object. It
the specific implementa on of a contains informa on about the excep on, such
method which is already provided by its as the name and descrip on of the excep on
superclass. and the state of the program when the
o Method overriding is used for run me excep on occurred.
polymorphism Major reasons why an excep on Occurs
Rules for Java Method Overriding Invalid user input
1. The method must have the same name Device failure
as in the parent class
Loss of network connec on
2. The method must have the same
parameter as in the parent class. Physical limita ons (out-of-disk
memory)
3. There must be an IS-A rela onship
(inheritance). Code errors
In Java, the Graphics class is an abstract Applet is a special type of program that
class that provides methods for drawing is embedded in the webpage to
shapes, text, and images on a generate the dynamic content. It runs
component. It is part of the Abstract inside the browser and works at client
Window Toolkit (AWT) package. side.
Input Output Java What is token in Java?
Java provides a rich set of classes and The Java compiler breaks the line of code into
interfaces in the java.io package to text (words) is called Java tokens. These are the
handle input and output smallest element of the Java program. The Java
opera ons. Here's a short note on compiler iden fied these words as tokens.
managing I/O in Java: These tokens are separated by the delimiters. It
is useful for compilers to detect errors.
Streams:
Remember that the delimiters are not part of
Founda on of Java I/O: Data is handled the Java tokens.
as a sequence of bytes or characters
Types of Tokens
known as a stream.
Java token includes the following:
Types:
o Keywords
Byte Streams: Used for reading and
wri ng raw binary data (e.g., images, o Iden fiers
audio).
o Literals
Character Streams: Used for reading
o Operators
and wri ng text data, handling
character encoding automa cally. o Separators
Direc on: o Comments
Input Streams: Read data from a source Data Types in Java
(e.g., file, keyboard).
Data types specify the different sizes and values
Output Streams: Write data to a that can be stored in the variable. There are two
des na on (e.g., file, console). types of data types in Java:
Common Classes: 1. Primi ve data types: The primi ve data
InputStream: Base class for all input types include boolean, char, byte, short,
byte streams. int, long, float and double.
OutputStream: Base class for all output 2. Non-primi ve data types: The non-
byte streams. primi ve data types
include Classes, Interfaces, and Arrays.
Reader: Base class for all input
character streams. 3. There are 8 types of primi ve da ypes: