Meeting Etiquette
● Please be on Mute all the time.
● Turn off Video, So that we can save bandwidth.
● There is separate Q&A Section in End Please use that, Add
questions in Google Form.
● Break at 5 min.
● Mute your microphone
● To help keep background noise to a minimum, make sure you
mute your microphone when you are not speaking.
● Be mindful of background noise
● Avoid multitasking
● All links and Slides will be shared.
TheTestingAcademy.com
{ Automation Tester } BluePrint.
Pramod Dutta
Core Java + Interview Tips
TheTestingAcademy.com
Core Java
& OOPs
TheTestingAcademy.com
Agenda
● Loops, Switch, do While, While
● Constructor
a. Non-Parameterized constructor
b. Parameterized constructor
c. Copy Constructor
● Polymorphism
a. Compile Time Polymorphism
b. Runtime Polymorphism
TheTestingAcademy.com
Agenda
● Inheritance
● Package in Java
● Access Modifiers in Java
● Encapsulation
● Abstraction
● Interfaces
● Static Keyword
● Learning Maven Project
● Maven Lifecycle & Phases , Plugins
TheTestingAcademy.com
Class
A class is a group of objects which have common
properties. A class can have some properties and
functions (called methods).
The class we have used is Main.
401
Response
When a class is created, no
memory is allocated
TheTestingAcademy.com
Objects
Object is an instance of a class. All
data members and member functions
of the class can be accessed with the
help of objects
401
Response
Objects are allocated memory
space whenever they are created.
TheTestingAcademy.com
Class & Objects
401
Response
TheTestingAcademy.com
Class
Every class in Java can be composed of the following elements:
● fields, member variables or instance variables - These are variables that hold data specific to a
particular object. For each object of a class, there is one field.
● member methods or instance methods - These perform operations on objects and are defined within
the class. 401
Response
● static or class fields - These fields are common to any object within the same class. They can only
exist once in the class irrespective of the total number of objects in the class.
● static or class methods - These methods do not affect a specific object in the class.
● inner classes - At times a class will be defined within a class if it is a subset of another class. The class
contained within another is the inner class.
TheTestingAcademy.com
OBJECT ORIENTED PROGRAMMING
Object-Oriented Programming is a methodology or paradigm to design a program using
classes and objects.
It simplifies the software development and maintenance by providing some
concepts
401
Response
Class is a user-defined data type which defines its properties and its functions
Object is a run-time entity. It is an instance of the class. An object can represent a person,
place or any other item
TheTestingAcademy.com
OBJECT ORIENTED PROGRAMMING
‘this’ keyword : ‘this’ keyword in Java that refers to the current instance of the class
In OOPS it is used to:
pass the current object as a parameter to another method
refer to the current class instance variable
401
Response
TheTestingAcademy.com
Constructor
Constructor is a special method which is invoked automatically
at the time of object creation.
It is used to initialize the data members of new objects generally.
Constructors have the same name as class or structure.
Constructors don’t have a return type. (Not even void)
Constructors are only called once, at object creation.
401
Response
There can be three types of constructors in Java.
Non-Parameterized constructor : A constructor which has no argument is
known as non-parameterized constructor(or no-argument constructor). It is
invoked at the time of creating an object. If we don’t create one then it is
created by default by Java.
TheTestingAcademy.com
Constructor
Parameterized constructor : Constructor which has parameters is called a
parameterized constructor. It is used to provide
different values to distinct objects.
Copy Constructor : A Copy constructor is an overloaded 401
Response
constructor used to declare and initialize an object from another object.
There is only a user defined copy constructor in Java(C++ has a default one
too).
TheTestingAcademy.com
Inheritance
Inheritance is a process in which one object acquires all the properties and
behaviors of its parent object automatically.
Single inheritance Hierarchical inheritance
401
Response
TheTestingAcademy.com
Polymorphism
Polymorphism is the ability of an object to take on many forms
Each of these classes will have different underlying data. Precisely, Poly means
‘many’ and morphism means ‘forms’.
when a parent class reference is used to refer to a child class object
401
Response
TheTestingAcademy.com
Polymorphism
Compile Time Polymorphism - The polymorphism which is implemented at
the compile time is known as compile-time polymorphism
Method Overloading
401
Response
Runtime Polymorphism
Runtime polymorphism is also known as dynamic polymorphism.
Function overriding is an example of runtime polymorphism.
Function overriding
TheTestingAcademy.com
Polymorphism
401
Response
TheTestingAcademy.com
Polymorphism
401
Response
TheTestingAcademy.com
Assignment
1. Create the Class of ATB
2. Create an Array of ATB Students and add toString
method.
3. Create Single, Multilevel, and Heriichca. Inteheri
4. Create both Overloading and OverRIDING Examples
TheTestingAcademy.com
Package in Java
Package is a group of similar types of classes, interfaces and sub-packages.
Packages can be built-in or user defined.
Built-in packages - java,
util, io etc.
import java.util.Scanner;
401
Response
import java.io.IOException;
TheTestingAcademy.com
Access Modifiers in Java
Private: The access level of a private modifier is only within the class. It cannot
be accessed from outside the class.
Default: The access level of a default modifier is only within the package. It
cannot be accessed from outside the package. If you do not specify any access
level, it will be the default.
401
Response
Protected: The access level of a protected modifier is within the package and
outside the package through child class. If you do not make the child class, it
cannot be accessed from outside the package.
Public: The access level of a public modifier is everywhere. It can be accessed
from within the class, outside the class, within the package and outside the
package.
TheTestingAcademy.com
Abstraction
Abstraction is the quality of dealing with ideas rather than
events.
when you consider the case of e-mail, complex details such as
what happens as soon as you send an e-mail, the protocol your
e-mail server uses are hidden from the user.
401
Response
Abstraction is achieved in 2 ways :
Abstract class
Interfaces (Pure Abstraction)
TheTestingAcademy.com
Abstraction
Demo
public abstract class Employee {
private String name;
private String address;
private int number;
401
Response
public abstract double computePay();
// Remainder of class definition
}
TheTestingAcademy.com
Abstraction
abstract class Animal {
abstract void walk();
void breathe()
public abstract class Employee {
private String name;
private String address;
Abstract Methods private int number;
401
Response
public abstract double computePay();
// Remainder of class definition
}
TheTestingAcademy.com
Abstraction
Abstract Class
An abstract class must be declared with an abstract
keyword.
It can have abstract and non-abstract methods.
It cannot be instantiated.
401
It can have constructors and static methods also. Response
It can have final methods which will force the subclass not to
change the body of the method.
TheTestingAcademy.com
Interfaces
All the fields in interfaces are public, static and final by default.
All methods are public & abstract by default.
A class that implements an interface must implement all the
methods declared in the interface.
Interfaces support the functionality of multiple inheritance.
401
Response
TheTestingAcademy.com
Static Keyword
Static can be :
● Variable (also known as a class variable)
● Method (also known as a class method)
● Block
401
● Nested class Response
TheTestingAcademy.com
Static Keyword
When a member is declared static, it can be accessed before any objects of its
class are created, and without reference to any object
### Static Block
static block that gets executed exactly once, when the class is first loaded.
401
### Static variables Response
When a variable is declared as static, then a single copy of the variable is
created and shared among all objects at the class level
TheTestingAcademy.com
Static Keyword
401
Response
TheTestingAcademy.com
Static Keyword
### Static methods
They can only directly call other static methods.
They can only directly access static data.
They cannot refer to this or super in any way.
401
Response
### When to use static variables and methods?
Use the static variable for the property that is common to all objects
### Static Classes
A class can be made static only if it is a nested class. We cannot declare a top-level
class with a static modifier but can declare nested classes as static
TheTestingAcademy.com
Wrapper Classes
A Wrapper class is a class whose object wraps or contains primitive data types.
They convert primitive data types into objects.
Data structures in the Collection framework, such as ArrayList and Vector, store
only objects (reference types) and not primitive types. 401
Response
An object is needed to support synchronization in multithreading.
TheTestingAcademy.com
Wrapper Classes
401
Response
TheTestingAcademy.com
Java - Exceptions
An exception (or exceptional event) is a problem that arises during the
execution of a program.
Following are some scenarios where an exception occurs.
A user has entered an invalid data.
A file that needs to be opened cannot be found.
401
Response
A network connection has been lost in the middle of communications or the JVM has run out of
memory.
Checked exceptions Unchecked exceptions
TheTestingAcademy.com
Java - Exceptions
Checked exceptions Unchecked exceptions
An unchecked exception is an exception
(notified) by the compiler at that occurs at the time of execution.
compilation-time, these are also called These are also called as Runtime
as compile time exceptions. Exceptions
401
Response
TheTestingAcademy.com
Java - Exceptions
Exact line with Stack Trace
401
Response
TheTestingAcademy.com
Java - Exceptions
Demo with String Null with Stack Trace
401
Response
TheTestingAcademy.com
Java - Exceptions
Exact line with Stack Trace
401
Response
TheTestingAcademy.com
Try and Catch
Exception Handling in Java is a mechanism to handle the runtime errors so that
normal flow of the application can be maintained.
It is done using 2 keywords - ‘try’ and ‘catch’.
Additional keywords like finally, throw and throws can also be used if we dive deep into this concept.
int[] marks = {98, 97, 95};
try {
System.out.println(marks[4]); 401
Response
} catch (Exception exception) {
System.out.println("An exception for caught while accessing an index the 'marks' array");
}
System.out.println("We tried to print marks & an exception must have occurred with index >=3");
TheTestingAcademy.com
Try and Catch public static void main(String args[]) {
try {
int a[] = new int[2];
try { System.out.println("Access element three :" + a[3]);
// Protected code } catch (ArrayIndexOutOfBoundsException e) {
} catch (ExceptionName e1) { System.out.println("Exception thrown :" + e);
// Catch block }
} System.out.println("Out of the block");
}
Catching Multiple Type of Exceptions
try { 401
Response
// Protected code Since Java 7, you can handle more than one exception using
} catch (ExceptionType1 e1) { a single catch block, this feature simplifies the code. Here is
// Catch block how you would do it −
} catch (ExceptionType2 e2) {
// Catch block
} catch (ExceptionType3 e3) {
catch (IOException | FileNotFoundException ex) {
// Catch block logger.log(ex);
} throw ex;
TheTestingAcademy.com
The Throws/Throw & Finally Block
import java.io.*;
public class className {
Java throws keyword is used in the
public void withdraw(double amount) throws RemoteException, method signature to declare an exception
InsufficientFundsException { which might be thrown by the function
// Method implementation while the execution of the code.
}
// Remainder of class definition Throws is used with the method 401
Response
} signature.
public void deposit(double amount) throws
RemoteException { Java throw keyword is used throw an
// Method implementation exception explicitly in the code, inside the
throw new RemoteException(); function or the block of code.
}
throw is used within the method.
TheTestingAcademy.com
401
Response
TheTestingAcademy.com
401
Response
TheTestingAcademy.com
Finally Block & User-defined Exceptions
public static void main(String args[]) {
int a[] = new int[2];
try {
class MyException extends Exception {
System.out.println("Access element three :" + a[3]);
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Exception thrown :" + e);
}finally {
a[0] = 6; 401
System.out.println("First element value: " + a[0]); Response
System.out.println("The finally statement is executed");
}
} JVM Exceptions − These are exceptions/errors
that are exclusively or logically thrown
by the JVM. Examples: NullPointerException, ArrayIndexOutOfBoundsException,
ClassCastException.
Programmatic Exceptions − These exceptions are thrown explicitly by the application or the
API programmers. Examples: IllegalArgumentException, IllegalStateException.
TheTestingAcademy.com
Demo User-defined Exceptions
401
Response
TheTestingAcademy.com
Java - Inner classes
class Outer_Demo {
class Inner_Demo {
}
}
401
Response
Inner classes are a security mechanism in Java
TheTestingAcademy.com
Thanks, for attending Class
I hope you liked it. Say Thanks
in Comment :)
TheTestingAcademy.com