0% found this document useful (0 votes)
41 views

Java Training Ppts

The document covers several Java concepts including inheritance, method overriding, abstract classes, exceptions, threads, interfaces, input/output streams, and number methods. It discusses how subclasses inherit and optionally override methods from superclasses. It also describes exception handling using try, catch, throw keywords and predefined exception classes. Threads are created by implementing Runnable or extending Thread. Interfaces define abstract methods that classes implement without determining implementation. Various input/output streams are used for byte-level and character-level reading and writing. Number classes have methods for type conversion, comparison, parsing, and string representation.

Uploaded by

Naveen Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Java Training Ppts

The document covers several Java concepts including inheritance, method overriding, abstract classes, exceptions, threads, interfaces, input/output streams, and number methods. It discusses how subclasses inherit and optionally override methods from superclasses. It also describes exception handling using try, catch, throw keywords and predefined exception classes. Threads are created by implementing Runnable or extending Thread. Interfaces define abstract methods that classes implement without determining implementation. Various input/output streams are used for byte-level and character-level reading and writing. Number classes have methods for type conversion, comparison, parsing, and string representation.

Uploaded by

Naveen Reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Metod over riding

Bi-Gems Technologies

Method overriding

Bi-Gems Technologies

Abstract Class
superclass that only defines a generalized form that will be shared by all
of its subclasses, leaving it to each subclass to fill in the details. Such a
class determines the nature of the methods that the subclasses must
implement

Bi-Gems Technologies

Using final to Prevent


Overriding

ing final to Prevent Inheritance

Bi-Gems Technologies

Exception-Handling
A Java exception is an object that describes an exceptional (that is,
error) condition
that has occurred in a piece of code
When an exceptional condition arises, an object representing that
exception is created and thrown in the method that caused the error.
That method may choose to handle the exception itself, or pass it on
Java exception handling is managed via five keywords: try, catch,
throw, throws, and
Finally
Program statements that you want to monitor for exceptions are
contained within a try block.
If an exception occurs within the try block,it is thrown. Your code
can catch this exception (using catch) and handle it in some rational
manner

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Exception types
All exception types are subclasses of the built-in class Throwable
Throwable are two subclasses that partition exceptions into two
distinct branches
One branch is headed by Exception. This class is used for exceptional
conditions that user programs should catch
Exceptions of this type are automatically defined for the programs that
you write and include things such as division by zero and invalid array
indexing.
The other branch is topped by Error, which defines exceptions that
are not expected to
be caught under normal circumstances by your program

Bi-Gems Technologies

Uncaught Exceptions

Using try and catch

Bi-Gems Technologies

Multiple try

This program will cause a division-by-zero exception if it is started with


no commandline
arguments, since a will equal zero
But it will cause an ArrayIndexOutOfBoundsException, since the int
array c has a length of 1, yet the program attempts to assign a value
to c[42].

Bi-Gems Technologies

throws

Bi-Gems Technologies

Predefind exceptions

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Multi Threading
multithreaded program contains two or more parts that can run
concurrently. Each part of such a program is called a thread, and each
thread defines a separate path of execution
When a Java program starts up, one thread begins running immediately.
This is usually
called the main thread of your program,

Bi-Gems Technologies

Creating a Thread
In the most general sense, you create a thread by instantiating an object
of type Thread.
Java defines two ways in which this can be accomplished:
You can implement the Runnable interface.
You can extend the Thread class, itself

Bi-Gems Technologies

Bi-Gems Technologies

Extend ing Thread

Bi-Gems Technologies

Interfaces
An interface is a collection of abstract methods. A class implements an interface,
thereby inheriting the abstract methods of the interface
Interfaces are syntactically similar to classes, but they lack instance variables,
and, as a general rule, their methods are declared without any body
interfaces that dont make assumptions about how they are implemented
To implement an interface, a class must provide the complete set of methods
required
by the interface
each class is free to determine the details of its own implementation.

Bi-Gems Technologies

Interfaces

Bi-Gems Technologies

I/O input and output


The java.io package contains nearly every class you might ever need to
perform input and output (I/O) in Java
All these streams represent an input source and an output destination
A stream can be defined as a sequence of data.
The InputStream is used to read data from a source and the
OutputStream is used for writing data to a destination
Java Support Byte Streams, character streem
Byte streams provide a convenient means for handling input and output
of bytes.
Byte streams are used, for example, when reading or writing binary
data.
Character streams provide a convenient means for handling input and
output of characters.

Bi-Gems Technologies

Character Streem

Bi-Gems Technologies

Byte Stream

Bi-Gems Technologies

Standard Input & Output

Bi-Gems Technologies

Bytearray Stream

Bi-Gems Technologies

File input & output


stream

Bi-Gems Technologies

Bi-Gems Technologies

Number Methods

xxxValue()
Converts the value of this Number object to the xxx data type and
returned it.
method for each primitive data type:
Byte
byteValue()
Short
shortValue()
int intValue()
long
longValue()
Float
floatValue()
double doubleValue()

Bi-Gems Technologies

compareTo()
The method compares the Number object that invoked the method to
the argument. It is possible to compare Byte,Long, Integer, etc.

Bi-Gems Technologies

equals()
The method determines whether the Number Object that invokes the
method is equal to the argument.

Bi-Gems Technologies

toString()
The method is used to get a String object representing the value of the
Number Object

parseInt()
This method is used to get the primitive data type of a certain
String.

Bi-Gems Technologies

Bi-Gems Technologies

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Inheritance

Bi-Gems Technologies

Inheritance

You might also like