Java Overview

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Java Overview

 Oops
1. Class
2. Object
3. Abstraction
4. Encapsulation
5. Inheritance
6. Polymorphism
Class:
Class is a Blueprint of object.
Object:
Object is a Real world entity it has its own
state behavior and identity.
Abstraction:
Abstract is a process of hiding the implement
details and showing functionality to the user.
Abstraction Achieved by using
Abstract class
Interface
Abstract Class:
“Abstract” Keyword used to create Abstract class.
Abstract class Contains abstract Method and Non
Abstract Method.
Abstract Method implementation achieved
by using “extends” Keyword.
We can extends only one abstract Class.
Non abstract Method implemented within the
Abstract class.
Interface:
Interface is a fully hiding whatever methods
declaring inside interface is consider as abstract
methods only using “Implements” keyword using
more than one interface.
“Interface” Keyword used to create interface class.
What is functionality Interface?
A functional interface is an interface that
contains only one abstract method.
Syntax:
“@FunctionalInterface
interface Square
{
int calculate (int x);
}”
Encapsulation:
Binding a data. It’s achieved by using access
modifier. There are four types
1. Public
2. Private
3. Protected
4. Default
Public:
Public is a one of the access modifier used
within a project.
We are used to “Public” Keyword.
Private:
Private is also one of the access modifier used to
within a class. We are used to “Private” Keyword.
We used access Specifier most be generate “getter
and setter”.
Protected:
Protected is a one of the access modifier used
within a class and also we can used to exiting
another package.
Default:
Default is a one of the access modifier used within a
package.

Inheritance:
Inheritance is a mechanism. One class from
derived another class.
There are Five Types.
 Single
 Multilevel.
 Multiple.
 Hierarchical.
 Hybrid.
Polymorphism:
Polymorphism means many behavior. One task
make many class.
That’s called Polymorphism. That’s are two types.
Overloading, Overriding.
 Overloading:
Single Class Same Method Different
Arguments.
“Overloading” another Names
Static binding
Early binding
Compile time binding

 Overriding:
Different Class Same Method Same
Arguments.
“Overriding” another Names
Dynamic binding
Late binding
Run time binding

Exceptions
What is Exception
Exception is an abnormal condition.
Exception is an even that disrupts the normal
flow of the program. It is an object which is
thrown at runtime.
Exception Handling:
Exception Handling is a mechanism to handle
runtime errors such as ClassNotFoundException,
IOException, SQLException, RemoteException, etc.
Types of Exceptions
1. Checked Exception
2. Unchecked Exception
3. Error
Checked Exception:
The classes which directly inherit Throwable
class except Runtime Exception and Error are
known as checked exceptions e.g. IOException,
SQLException etc.
Checked exceptions are checked at compile-time
Errors.
Unchecked Exception:
The classes which inherit
RuntimeException are known as unchecked
exceptions.
Unchecked exceptions are not checked at
compile-time, but they are checked at runtime.
Error:
Error is irrecoverable. E.g. OutOfMemoryError,
VirtualMachineError, AssertionError etc.
Exception Keywords
Try ();
Catch ();
Finally (); (System.exit())
Throw ();
Throws ();

Try ( )
The "try" keyword is used to specify a block
where we should place exception code.
The try block must be followed by either catch
or finally.
Catch ( )
The "catch" block is used to handle the
exception. It must be preceded by try block which
means we can't use catch block alone.
Finally ( )
The "finally" block is used to execute the
important code of the program. It is executed
whether an exception is handled or not.
If you want to stop the Exciting the Final Block
before finally block we can to declared “System. Exit
()”
Throw ( )
The "throw" keyword is used to throw an
exception.
Throws ( )
The "throws" keyword is used to declare
exceptions. It doesn't throw an exception. It specifies
that there may occur an exception in the method. It
is always used with method signature.
Custom Exception:
If you are creating your own Exception that
is known as custom exception or user-defined
exception.
You can have your own exception and
message.
Thread
Multithreading in Java
Is a process of executing multiple threads
simultaneous.
A thread is a lightweight sub-process, the smallest
unit of processing.
Multiprocessing and multithreading, both are used to
achieve multitasking.
Advantages of Multithreading
 It doesn't block the user because threads are
independent and you can perform multiple
operations at the same time.
 You can perform many operations together,
so it saves time.
 Threads are independent, so it doesn't affect
other threads if an exception occurs in a single
thread.
Multitasking:
Multitasking is a process of executing multiple
tasks simultaneously.
Multitasking can be achieved in two ways:
o Process-based Multitasking (Multiprocessing)
o Thread-based Multitasking (Multithreading)
Process-based Multitasking (Multiprocessing)
Each process has an address in
memory. A process is heavyweight. Cost of
communication between the processes is high.
Thread-based Multitasking (Multithreading)
Threads share the same address space.
A thread is lightweight.
Cost of communication between the
thread is low.
Immutable Class
We can also create immutable class by
creating final class that have final data members.
Immutable classes like String, Boolean,
Byte, Short, Integer, Long, Float, Double etc.
The class is final so we cannot create the
subclass.
There is no setter methods. The instance
variable of the class is final.
Singleton Class
Singleton means unnecessarily restrict the
object creation. How to make a class as
singleton means. 1) Private Constructor and
Static method.

Constructors
Constructor is a block of code that initializes
the newly created object.
Constructor is a Special Method that is used to
initialize object.
The Class Name and then Constructor Name will be
same.
Syntax:
Public class Hello {
String name;
//Constructor
Hello () {
this.name = "BeginnersBook.com";
}
Public static void main (String [] args) {
Hello obj = new Hello ();
System.out.println (obj.name);
}
}
Static Method:
The static method is doesn’t create an object.
Don’t change their value.
The Static Method is used to the single Class.
Static is executed in the Runtime.

You might also like