Java Exception Hierarchy / Chapter 2/ Exception Handling

java exception hierarchyJava Exception Hierarchy



  • The Throwable class is the root class for java exception hierarchy.

  • The Throwable class defines two child classes.



  1. Exception

  2. Error


1.Exception:-


Most of the time exceptions are occurs by our java program and these are recoverable.

for example: -


In our java program, there is a requirement of reading data from a remote file which is locating at NewYork (USA). At runtime, if NewYork file is not available our program should not be terminated abnormally and we will get RunTime exception saying"FileNotFoundException". To solve this problem we have to provide some local file to continue rest of the program normally.

Introduction of Exception Handling /Chapter -1 / Exception Handling

java exception

Java Exception:-


An unexpected unwanted event that disturbs normal flow of the program, is called an exception.

The purpose of exception handling:-


The main objective of exception handling is "graceful termination " of the program. It is highly recommended to handle the exception in java program.

Explanation:-


Exception Handling doesn't mean repairing an exception. We have to provide an alternative way so that the rest of the program will execute normally, is the concept of exception handling.


for example: -

Difference between interface and abstract class / Chapter 14 / OOPs Concept

Difference between interface and abstract class

Difference between interface and abstract class



  1. In the interface, if we don't know about implementation and just we have requirement specification then we should go for an interfaceBut In the abstract class, If we are talking about partial implementation but not complete then we should go for abstract class.

  2. In the interface, every method is always public and abstract whether we are declaring or not. But  In the abstract class, every method need not be public and abstract. we can take concrete method also.

Java Interface /Chapter -13 /OOPs Concept


Java Interface



  • Any service requirement specification (SRS) is considered as an "interface".

  • Inside "interface", every method is always abstract whether we are declaring or not hence, the interface is considered as 100% pure abstract class.

  • Any contract between client and service provider is considered as an "interface".


Interface declaration and implementation



  1. For each and every method present in the interface we have to provide implementation otherwise, we have to declare the class as abstract then next level child class is responsible for providing the implementation.

  2. Every method present in an interface is always public and abstract we are declaring or not hence, whenever we are implementing an interface's for every method compulsory we should declare as public otherwise we will get Compile-Time Error.


Constructor in Java /Chapter -12 /OOPs Concept

java constructorjava constructor


Whenever we are creating an object some part of the java program(code) will be executed automatically to perform initialization of the object, this part of the program is called "Constructor".
Hence the main objective of the constructor is to perform initialization of an object. 

example 1.

class Employee

{

String name;

int eid;

Employee (String name, int eid)

{

this.name = name;

this.eid = eid;

System.out.println(name+"-----"+eid);

}

public static void main(String args[ ])

{

Employee e1 = new Employee("Dhoni",101);

Employee e2 = new Employee("Virat",102);

}

}

Output of the above program is:-

In how many ways we can create Object in JAVA?/Chapter-11/OOP's Concept

In how many ways we can create Object in JAVA?In five ways we can create Object in java.




  1. By using the new operator:-In how many ways we can create Object in JAVA?




  2. By using newInstance( ) method:- In how many ways we can create Object in JAVA?




  3. By using the clone( ) method:- 

Java- Object Type Casting / Chapter - 10 / OOP's Concept

java Object Type Casting

Now that we have learned that,


We can use parent reference to hold child object.


example:-     Object  o   =  new String ("javabychetan");


We can use interface reference to hold child object implemented class object.


example:-     Runnable      r   =  new Thread ( );


let's understand the syntax of "How to do Type-Casting".

Java Object Type Casting

Before Doing type casting we have to apply or check all these three rules otherwise, we won't able to perform type casting.


Java- Polymorphism / Chapter - 9 / OOP's Concept

Java-Polymorphism

Polymorphism


One into many forms is the concept of polymorphism.


example 1: - method name is same but we can apply for different types arguments(Overloading).

public void m1(int)                  (Overloading)

public void m1(long)               (Overloading)

public void m1(float)                (Overloading)
example 2: - method signature is same but in parent class one type of implementation and in the child class another type of implementation(Overriding).

Java- Difference Between Method Overloading & Method Overriding / Chapter - 8 / OOP's Concept

Method Overloading,Method Overriding Difference between Method Overloading and Method Overriding 



  1. Method Names: - In Overloading method name should be same, And Even In Overriding method name should be same.

  2. Argument Type: - In Overloading, argument type must be different (at least the order of arguments), But in the Overriding argument type must be same.

  3. Method Signature: - In Overloading, method signature must be different, But in the Overriding method signature must be same.

  4. Return Type: - In Overloading, there is no restriction on the return type, But in Overriding return type must be same until 1.4 v, But from 1.5v onwards co-variant return type is allowed.

Java- Method Overriding / Chapter - 7 / OOP's Concept

Method OverridingMethod Overriding in Java


1.In java, whatever method parent class has that method by default available to the child class through inheritance. If the child class is not satisfied with parent class method implementation then child class is allowed to redefine that method based on its requirement, this process is known as "Overriding".


2.The parent class method which is overridden is called overridden method and the child class method which is overriding is called the overriding method.


3.In overriding method resolution is always takes care by JVM based on the runtime object hence overriding is also known as runtime polymorphism or dynamic polymorphism.


Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com