Section-Oop’s
Chapter- 01 Programming Paradigm in Java
=> Programming Paradigm :-
-> Programming paradigm is a way or an approch to solve any problem or to
achieve any task using any programming languages
-> Programming paradigm are a way to classify programming languages
based on their features
-> There are 2 classifications of programming
paradigm :-
1. Imperative Programming Paradigm
2. Declarative Programming Paradigm
=> What is difference between Imperative &
Declarative Programming Paradigm ?
1. PROGRAMMING STYLE :-
Imperative :- We have to specify step by
step every task
Declarative :- We have to define the problem to achieve the task
2. TASK :-
Imperative :- User makes the decision and command to the compiler
Declarative :- Allows compiler to make decisions
3. REAL WORLD EXAMPLE :-
-> Task (read mails; buy PC; proposal; .... )
Imperative :-
Declarative :
4. SMART :-
Imperative :- User is more smart as compared to system
Declarative :- System is more smart as compared to user
5. PROGRAMMING FOCUS :-
Imperative :- "What"
Declarative :- "How"
6. PRIMARY FLOW CONTROL :-
Imperative :- Loops, Conditional; functions/methods etc
Declarative :- Functions calls (including recursion)
7. EXAMPLE :-
Imperative :- FORTRAN, Assembly
Languages, COBOL, C, C++, Java, Python etc
Declarative :- SQL, Haskell, Prolog etc
=> Unstructured Programming Paradigm :-
1. These are the first programming language categories that was introduced
at starting point of computers
2. For examples FORTRAN, COBOL, BASIC etc
3. In these languages there was not fixed structure or way to achieve the
task or to solve the problem
4. In this type we use mnemonic codes
5. In this part flow control was achieved by "goto" statement
6. Hard to learn and difficult to achieve any task
because number of lines of code were increased
=> Structured Programming Paradigm :-
1. These were introduced after unstructured programming paradigm and
used till now
2. For examples PASCAL, C etc
3. These have fixed structure to achieve any task
4. These dont use any mnemonic codes which makes this language easier
(high level language syntax is used)
5. In this part a lot of flow control statements were introduced for example
if, else, for, while etc
6. Easier to learn and easy to achieve any task as there were improved code
-> Structured programming paradigm have a lot of issues like less
modularity, abstraction was not good, less security, less sharability, less
code reusability and because of these reasons OOP's was introduced
=> Procedure Programming Paradigm :-
1. In POP task can be divided into small parts known as functions/methods
2. In POP top to down approach is used
3. No Access Specifies
4. It deals with algorithms
5. It uses less memory
6. For example FORTRAN, PASCAL, C etc
-> In POP there were a lot of issues less security and due to this reason
OOP's were mostly adopted language by developers
=> Object Oriented Programming Paradigm :-
1. In OOP program is divided into parts i.e. Objects
2. In OOP bottom up approch is used
3. Have a lot of access modifiers or access specifiers
4. OOP deals with data
5. It needs more memory as compared to POP
6. For examples Java, C++, C#, Python etc
NOTE : One language can use multiple programming paradigm
=> What is difference between Object Oriented Programming Languages
and Object Based Programming Languages ?
-> In object oriented programming languages inheritance feature is mostly
used but in case of object based programming languages inheritance
concept is not used.
-> Object oriented programming languages are JavaObject based
programming languages are JavaScript
Chapter-OOP’s Concept in Java(Class, Methods & Objects)
OOP's :-
-> Full form is Object Oriented Programming
-> OOP is the programming paradigm based on the concept of Objects
which contains the data(fields or variables) and methods
-> It is the most popular programming paradigm used by the programmers
-> For examples : Java, Python, C++ etc
-> Features of OOP :-
1. Class, Objects & Methods
2. Meassage Passing
3. Inheritance & Composition
4. Polymorphism
5. Encapsulation
6. Abstraction
 Real World Example of Class, Methods & Objects
=> Class :-
-> A class is a user defined blueprint or prototype which is used to create an
object
-> Class is a logical entity or say its not a real world entity or class is not
physical
-> Real world example :- Animal, Birds, Vehicle, Fruits etc
-> Class represents the set of properties or methods that are common to all
the objects of one type
-> Simply we can say that a class is a group of objects having common
properties (attributes or variables), behaviour (methods), relationships &
semantics.
-> Syntax :
access-modifiers class ClassName extends
ParentClassName implements InterfaceName
{
//variables
//blocks
//constructors
//methods
//nested class, interfaces
}
> Simple syntax :
access-modifiers class ClassName
{
//variables
//methods
}
-> Simple class
class Animal
{
int age=10;
String color=black;}
=> Methods :-
-> A set of codes which perform a particular task
-> Advantages :-
1. Code reusability
2. Code optimization
-> Syntax :
access-modifiers return-type methodName(list of parameters) throws
ExceptionClassName, -, -
{
//statements
}
-> Simple Syntax :-
return-type methodName(list of parameters)
{
//statements
}
-> Example :-
void eat()
//method declaration
{
//method defination (body)
System.out.println("im eating");
}
=> Objects :-
-> Object is an instance of class
-> Object is physical entity or object is real world entity
-> An object has 3 characteristics :-
1. State (represents the data(value) of an object)
2. Behaviour (represents the functionality of an object)
3. Identity (represents the unique id of an object which is created
automatically by JVM)
-> Object is simple a memory block-> Syntax :
1. Creation of an object
ClassName object_name
(ref_variable_name) = new ClassName();
-> Animal buzo = new Animal()
2. Calling variables or methods from
 objectobject_name.variable_name; -> buzo.age;
object_name.methodName(); -> buzo.eat();
=> Points to remember :-
-> We can only use public or default access modifiers but not private or
protected with outer
class.
-> For inner class we can use all access modifiers i.e. public, protected,
default and private
Chapter-03Constructors in Java
=> Constructors :-
-> WHAT IS CONSTRUCTOR : Constructors are the special methods having
same name as that of class name and does not have any return type
-> EXAMPLE :-
class Animal
{
Animal()
{
}
}
-> USE OF CONSTRUCTOR :- Constructors are used to initialize an object but
not for object creation
-> WHEN CONSTRUCTORS ARE EXECUTED
:- Constructors are executed exactly at the time of object creation, not
before or after object creation
-> HOW CONSTRUCTORS ARE EXECUTED :-Constructors are executed
automatically when we create an object
-> SYNTAX :-
access-modifiers ClassName(list of parameters) throws Exception1,
Exception2, --
{
//initialization code
}
-> We can use any access-modifier for the constructor i.e. public, private,
protected or default. This is done to control the object creation
-> We cannot use abstract, final, static,
synchronized etc keywords with constructors
-> TYPES OF CONSTRUCTORS :- There are 3
types of constructors :-
1. Default Constructors (compiler)
2. 0-Argument Constructors (programmer)
3. Parametrized Constructors (programmer)
1. Default Constructors :-
-> Whenever we dont create any constructor in class, then compiler will
always create a constructor which is known as default constructor
-> Default constructors are used to provide the default values to the objects
like 0, null etc depending on the type.
-> Note : If programmer creates any one constructor then compiler will not
generate default constructor
-> Prototype of default constructor :-
1. Access-modifier of default constructor will be same at that of class
access-modifier
2. Access-modifier of default constructor cannot be private or protected
because outer class canot be private or protected
3. Default constructor has only one line of code i.e. super();
2. 0-Argument Constructors :-
-> These constructors are created by the programmer
class Test
{
Test()
{
}
}
3. Parametrized Constructors :-
-> These constructors are created by the programmer
class Test
{
Test(int a, int b)
{
}
}
=> What is difference between Methods & Constructors :-
1. Methods always have return typeConstructors does not have any return
type even void
2. Methods can have any valid nameConstructors always have same name
as that of class name
3. Methods are used to perform any particular task Constructors are always
used to initialize an object
4. We have to call the methods explicitly by using object name or class name
 Constructors are called automatically when we create an object
5. If we don’t create any method then compiler will not generate any
method
If we dont create any constructor then compiler will generate default
constructor
=> Topics related to constructor :-
1. Constructors with inheritance
2. Constructors overloading and overriding
3. Constructors chaining (using this keyword)
4. Use of super keyword with constructor
5. Constructors with abstract class & interface
6. Constructors with exception handling
7. Copy constructor
=> NOTE :-
-> Constructor is predefined class present in java.lang.reflect package
-> This Constructor class is used to get constructor related information
Program Flow
Chapter-Object Creation Explanation in Java
=> How Objects are created :-
---------------------------------------------
1. When We compile the program i.e. javac AnimalMain.java
 Compiler will check the syntax and if syntax is correct then it will
generate .class files (no of .class files generated depends on the no
of classes we have created)
2. When we run the program i.e. java AnimalMain
 2.1 AnimalMain.class file will be loaded in JVM
memory area i.e. in Method Area
 2.2 An object of java.lang.Class class will be created in Heap Area in
which AnimalMain class metadata will be stored
2.3 Now Main Method will execute and for this
JVM will create a new thread known as main thread
 2.4 As soon as main thread is created then JVM
will create main stack in stack area
 2.5 Now first line in main method will execute i.e.
Animal ob=new Animal(); now Animal.class file will
load in method area and a new object of
java.lang.Class class is created in heap area in
which metadata of Animal class will be stored
 2.6 Now there is new keyword so new object
creation process will start. JVM will instruct heap
manager to create an object of Animal class but
heap manager will ask for object size to JVM. Then
JVM will calculate the size of object according to the
number of instance variables that are declared in
Animal class and this size will be taken by heap
manager and heap manager will create an object in
heap area
2.7 As soon as heap manager creates an object, a
unique integer value will be assigned to the object
which is known as "hashcode"
2.8 This hascode value will be provided to the JVM
and JVM will convert this hascode vallue into
hexadecimal form and this hexadecimal value is
known as reference value
 2.9. Now this hexadecimal value will be assigned
to the variable which is known as reference variable
 2.10 Now object will be initialized that means all
instance variables will be assigned by default values
or by their original values
=> java.lang.Class :- It represents the classes and
interfaces which are used in running java application
=> java.lang.Object :- This is the parent class of all
the classes in java.When we create any class than that class will
inherit
Object class either directly or indirectly
=> java.lang.reflect.Method
=> java.lang.reflect.Constructor
Chapter-Inheritance in Java
Relationship Between Java Classes :-
=> Use of relationship between java classes :-
1. Code Reusability
2. Less Execution Time
3. Less Memory Usage
=> Types of relationships :-
1. IS-A Relationship (Inheritance)
-> IS-A relationship is one in which data members of one class is
obtained into another class through the concept of inheritance
-> Types of IS-A relationship :-
1.1 Single Inheritance
1.2 Multilevel Inheritance
1.3 Hierarchical Inheritance
1.4 Multiple Inheritance
1.5 Hybrid Inheritance
2. HAS-A Relationship (Association)
-> HAS-A relationship is one in which an
object of one class is created as a data member into another class.
-> Types of HAS-A relationship :-
2.1 Aggregation
2.2 Composition
3. USES-A Relationship (Dependence)
-> USES-A relationship is one in which a method of one class is
using an object of another class
=> Terms used for inheritance :-
1. Class
2. Sub-Class / Child Class
3. Super-Class / Parent Class
4. Reusability
=> IS-A Relationship :-
-> It is also known as "Inheritance"
-> IS-A Relationship or Inheritance is achieved by using "extends"
keyword
-> All java classes except Object class will always have one parent
class thus we can say that the total java API is implemented based
on inheritance concept
=> Use of inheritance :-
1. Code Reusability
2. For Method Overriding to achieve runtime
polymorphism
=> Syntax of inheritance :-
class Sub-Class extends Super-Class
{
//body
}
=> Types of Inheritance :-
-> Total there are 5 types of inheritance :-
1. Single Inheritance
2. Multilevel Inheritance
3. Hierarchical Inheritance
4. Multiple Inheritance
5. Hybrid Inheritance
=> Points to Remember :-
-> Default Parent Class :- By default if any java class does not inherit any
parent class then it inherits Object class
-> Parent class can only be one :- There can be only one parent class for
every class and due to this java does not support multiple inheritance
-> Which part is not inherited :-
1. Private members of parent class is not inherited in child class
2. Constructors are not inherited because
constructors are not the part of class members (class members are
onlyfields, methods, nested classes)
-> Cyclic inheritance is not possible
1. class A extends A
2. class A extends B { - }
 class B extends A { - }
-> Multiple and Hybrid inheritance is not possible in case of classes but it is
possible in case of interfaces
Interview Questions :-
1. Why java does not support multiple inheritance
2. How we can achieve Multiple and Hybrid inheritance
3. Various possible combinations for inheritance
Chapter-Association in Java
=> HAS-A Relationship (Association) :-
-> Association is relation between two separate
classes which establishes through their objects
-> Association has 4 types :-
1. One-to-One Association
2. One-to-Many Association
3. Many-to-One Association
4. Many-to-Many Association
-> Association has 2 forms :-
1. Composition
2. Aggregation
=> One-to-One Association :-
-> Real World Example :-
1. One person has one passport
2. One employee has one employee id
3. One student has one roll no
-> It is a relation between entities where one instance of an entity should be
mapped only to one instance of another entity
=> One-to-Many Association :-
-> Real World Example :-
1. One person can have multiple phone numbers
2. One student can have multiple courses
3. One person can have multiple bankaccounts
4. One machine can have multiple functionalities like tea, coffee etc
5. One customer can have multiple orders
6. One class can have multiple students
-> It is the relation between entity classes where one instance of an entity
should be mapped with multiple instance of another entity
=> Many-to-One Association :-
-> Real World Example :-
1. Many colleges can associate with single university
2. Multiple cities exist in one state
3. Many ports can exist in one extention
4. Multiple students can have one branch
-> It is a relation between entities where multiple instances of an entity
should be mapped with exactly one instance of another entity
=> Many-to-Many Association
-> Real World Example :-
1. Multiple customers can buy multiple products and multiple products can
be bought by multiple customers
2. Multiple students can associate with multiple teachers and multiple
teachers are associated with multiple students
3. Multiple students can learn multiple languages
-> It is relation between entities where multiple instances of an entity
should be mapped with multiple instances of another entity
Chapter-Dependency Injection & USES-A Relation in Java
=> Dependency Injection :-
-> DI is the concept in which objects gets the other required objects
from outside entity
-> The process of injecting or inserting dependent(contained) object
into the container object is known as Dependency Injection
-> NEED :- While programming, java classes should be as minimum
dependent as possible on each other. By this we will increase the
possibility of reusing these classes and to be able to test them
independently
-> TYPES OF DEPENDENCY INJECTION :-
1. Constructor Dependency Injection
2. Setter Method Dependency Injection
=> Circular Dependency Injection :-
-> It is the process of depending two objects in circular form i.e. first
object is dependent on second object and second object is
dependent on first object
-> Circular DI can be achieved by setter method dependency
injection but not in case of constructor dependency injection
=> USES-A Relationship (Dependence)
-> USES-A relationship is one in which a method of one class is using an
object of another class
-> For example : Transaction Uses Account to deposit() the amount
Chapter-Polymorphism (Method Overloading) in Java
=> Polymorphism :-
-> Poly (many) + Morhism (forms, structure)
-> Real world example : sound, water, many brand clothes in one
shop, person, single institute has multiple trainer etc
-> Advantage :- It provides the flexibility to develop an application
i.e. it allows us to perform a single task by different ways.
-> Types of Polymorphism :-
1. Compile Time Polymorphism
2. Runtime Polymorphism
=> Compile Time Polymorphism :-
-> It is also known as Static Polymorphism or Early Binding
-> If the polymorphism is achieved at compile time then it is compile
time polymorphism
-> Compile Time Polymorphism can be achieved by 2 ways :-
1. Method Overloading
2. Operator Overloading (is not supported in
java except + symbol)
=> Runtime Polymorphism :-
-> It is also known as Dynamic Polymorphism or Late Binding
-> If the polymorphism is existed at runtime then it is known as
Runtime Polymorphism
-> Runtime Polymorphism can be achieved by "Method Overriding"
=> Method Overloading :-
-> The process of compiler trying to resolve the method call based
on reference type is known as method overloading
-> Rules for method overloading :-
1. Same name
2. Within same class
3. Different parameters
-> No of parameters
-> Type of parameters
-> Sequence of parameters
Interview Questions :-
1. Operator Overloading is not supported in java but + operator is
overloaded
-> Operator Overloading concept is achieved only by java designers
but it cannot be achieved by developers like us.
2. What is difference between Compile Time Polymorphism &
Runtime Polymorphism
3. What is varargs
4. Can we overload main method -> Yes
5. Can we overload constructors -> Yes
Chapter-Polymorphism (Method Overriding) in Java
=> Method Overriding :-
-> The process of JVM trying to resolve the method call based on
reference type is known as method overriding
-> Overriding is the feature by which child class trying to change the
implementation of parent class method
-> Rules for method overriding :-
1. Same name
2. Within different class
3. Same parameters
-> No of parameters
-> Type of parameters
-> Sequence of parameters
4. IS-A relationship
-> Cases for method overriding :
1. If we change the return type in method overriding then it will
provide compile time error
2. We can provide child class as a return type for overriding method
and this concept is known as covarent return type
3. Child class method should have equal or higher access modifier as
compared to parent method access modifier in method overriding
4. We cannot override private, final and static methods
5. We cannot override constructors
6. We cannot override main method
=> Typecasting : The process of converting one data type into
another is known as typecasting
=> Object Typecasting :
-> The process of converting one object into another object is known
as Object Typecasting
-> Object typecasting is of 2 types :-
1. Upcasting
2. Downcasting
Interview Questions :-
1. What is difference between method overloading & method
overriding
2. What is upcasting & downcasting ?
-> Upcasting : Object typecasting in which child object is typecasted
into parent object Downcasting : Object typecasting which parent
object is typecasted into child object
-> Upcasting : Implicit upcasting is possible Downcasting : Implicit
downcasting is not possible but forcefully we can do i.e. explicit
downcasting is possible
3. What is covarent return type ?
-> Before JDK 1.5 version, covarent return type concept was not
there
Chapter-Abstraction in Java
=> Data-Hiding :-
-> Data-Hiding is the process of hiding the data
from outside users
-> It is achieved by private access-modifier
-> Example :
class Account
{
private int balance; //data hiding
//code---
}
-> To access or modify or update private variables java provide some
special methods i.e. getter and setter methods
-> It is highly recomended to declare variables (data members) as
private
=> Abstraction :-
-> Abstraction is hiding the details (hiding the implementation part)
and just highlight the main services
-> Real world example : Car (internal working of breaks, gears etc are
hidden from user), Bank (internal working of credit/debit is hided
form userand only main component i.e. textfield and button is
shown) etc
-> It is achieved by abstract class & interfaces
------------------------------------------------------------
=> Abstract class :-
-> Abstract class are those which can contain both concrete methods
and abstract methods
-> Syntax :
abstract class Test
{
//concrete methods
void sum()
{
//coding
}
//abstract methods
abstract void show();
}
=> Abstract method :-
-> For example : Devils
-> 1. Abstract methods are those whose implementation part is
hided
 2. Abstract methods are those which does not have body or
implementation part
3. Abstract methods are those which have only declaration part, not
implementation
-> Syntax :
abstract void sum();
-> To declare abstract methods we have to use "abstract" keyword
=> Points to remember :-
1. If any class contains abstract methods then that class should be
declared as abstract class
2. If we declare any abstract class, then it can contain both concrete
methods as well as abstract methods and it can contain only
concrete methods
3. We cannot create an object of abstract class or we cannot
instantiate an abstract class but we can declare reference for an
abstract class
4. If any class inherits abstract class then it should implement all the
abstract methods or that class should also be declared as abstract
5. Whenever we use abstraction concept we are using method
overriding concept also
6. Abstract class can have constructors
7. Abstract class can inherit concrete class
8. We can overload abstract methods
Interview Questions :-
1. What is difference between concrete methods and abstract
methods ?
-> Concrete Methods : which have both declaration and
implementation partAbstract Methods : which have only
declaration part
-> Concrete Methods : we dont need to use any keyword
Abstract Methods : we have to use "abstract" keyword
-> Concrete Methods : provides less shareability Abstract Methods :
provides more shareability
-> Concrete Methods : can be provided in concrete class and
abstract class
Chapter-Interfaces in Java
=> Interface
-> Interfaces are similar to abstract class which can contain variables
and methods but having all the variables as "public static final" and
methods as "public abstract"
-> In simple way we can say that all the methods in an interface are
abstract and thus methods cannot have implementation part or
body part
-> Interface is a blueprint of class which specifies what must do and
not how
-> Syntax :
access-modifier interface InterfaceName
extends InterfaceName, -, -
{
//variables (public static final)
//abstract methods (public abstract)
}
interface Vehicle
{
void start();
void changeGear();
}
-> Use of Interfaces :-
1. It is used to achieve total abstraction
2. It is used to achieve multiple inheritance
(as multiple inheritance is not supported in java incase of classes)
3. It is used to achieve loose coupling
Interview Questions :-
1. What is difference between concrete class, abstract class &
interface
-> Concrete Class : Syntax : class ClassName{}
Abstract Class : Syntax : abstract class ClassName{}
 Interface : Syntax : interface InterfaceName{}
-> Concrete Class : we can declare only concrete methods
 Abstract Class : we can declare concrete methods and abstract
methods
 Interface : we can declare only abstract methods
-> Concrete Class : we can create objects
Abstract Class : We cannot create an object but we can declare
reference variable name
 Interface : We cannot create an object but we can declare reference
variable name
-> Concrete Class : we cannot achieve abstraction
 Abstract Class : we can achieve partial abstraction
 Interface : we can achieve full abstraction
-> Concrete Class : methods & variables are same as we declare
 Abstract Class : methods & variables are same as we declare
 Interface : methods we have declared are always "public abstract"
and variables we have declared are always "public static final"
-> Concrete Class : constructors are allowed
 Abstract Class : constructors are allowed
 Interface : constructors are not allowed
-> Concrete Class : multiple inheritance is not supported
 Abstract class : multiple inheritance is not supported
 Interface : multiple inheritance is supported
=> Points to remember :
1. Interfaces cannot be private or protected but
nested interface can be anything i.e. private,
protected, default & public
2. Interface represents IS-A relationship
3. Interface new features :-
3.1 (JDK 8) We can create default methods in an interface which
have implementation part
3.2 (JDK 8) We can create static methods in an interface
3.3 (JDK 9) We can create private methods in an interface
3.4 (JDK 9) We can create private static
methods in an interface
=> What is marker interface ?
-> Any interface which does not contain any abstract method or any
variable is known as marker interface
-> It is used to provide some extra feature or abilities to the object at
runtime
-> For example :
1. Cloneable interface (java.lang)
2. Serializable interface (java.io)
3. Remote interface (java.rmi)
Chapter-Encapsulation in Java
=> Encapsulation :-
-> Encapsulation is the process by which variables and methods are
wrapped or binded into a single unit
-> Encapsulation is technically hiding the data from other classes and these
data can be accessed only through the member functions of its own class
-> Real world example : capsule, mobile
-> Technically every java class is an example of encapsulation
-> Main example of encapsulation in java is "JavaBean" classes
-> Encapsulation is achieved by declaring variables as private and public
getter and setter methods
-> For example
class Employee
{
private int salary;
public void setSalary(int salary)
{
this.salary=salary;
}
public int getSalary()
{
return salary;
}
}
-> In IDE's (eclipse and netbeans) getter and setter methods can be
generated directly so its very easy to generate encapsulation in IDE's
-> Encapsulation = data hiding + abstraction
-> Advantages of encapsulation :-
1. Data Hiding
2. Increase flexibility
3. Reusability
4. Testing code is easy
=> JavaBean Class :-
-> JavaBean class is used to encapsulate the data into single object
-> Fules for JavaBean class :-
1. Must implement Serializable interface
2. Class must contain public no-argument constructor
3. Class must have all private variables
4. Class must contain public getter and setter methods
=> Tightly Encapsulated Class :-
-> A class is tightly encapsulated class if and only if it have all the variables
as private
=> Interview Questions :-
1. What is difference between Abstraction & Encapsulation
-> Abstraction : It hides the implementation (details)
Encapsulation : It hides the data (information)
-> Abstraction : It is achieved by "abstract class" and "interface"
 Encapsulation : It is achieved by using "JavaBean" class
-> Abstraction : In case of abstraction we have to use "abstract" keyword
 Encapsulation : In case of encapsulation we have to use access modifiers
(private & public)
-> Abstraction : It resolves the issue at design level
 Encapsulation : It resolves the issue at implementation level
=> Which are 6 main pillers in OOP's
1. Classes
2. Objects & Methods
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
Chapter-“this” keyword in Java
=> this keyword :-
-> this keyword is "reference variable" that refers to the current
object
-> Use of this keyword :-
1. this keyword is used to refer the current class instance variable
-> this.instance_variable_name;
2. this keyword is used to invoke the current class method
-> this.methodName();
3. this keyword is used to invoke the current
class constructor
-> this();
-> this(-,-,-,-);
-> this keyword must be the first statement in the constructor call
4. this keyword can be used to pass as an argument in the method
-> This case is mainly used in event handling
5. this keyword can be used to pass as an argument in the constructor
6. this keyword can be used to return current class instance
Interview Questions :-
1. Write a Program to prove that this keyword also refers to current object
2. What is constructor chaining
Chapter-“super” and “final” keyword in Java
=> super keyword :
-> The super keyword is a reference variable which is used to refer
immediate parent class object
-> Use of super keyword :-
1. super keyword can be used to refer the immediate parent class
instance variable
2. super keyword can be used to invoke parent class method
3. super keyword is used to invoke parent class constructor
-> If we dont provide super() in constructor then compiler provides it
implicitly
-> super() should always be the first statement in constructor
Points to remember :-
 1. We cannot use this() and super() together => final : -> final
keyword is used to provide restrictions to the users -> final keyword
can be used with :- 1. variable (variable value cannot be changed, we
cannot re-assign final variable value)
2. method (method cannot be overrided)
3. class (class cannot be inherited)
Interview Question :-
=> What is difference between this and this()
=> What is difference between super and super()
=> What is difference between final, finally and finalize
Chapter-Static variables and static blocks in Java
=> static keyword :-
-> static keyword is non-access modifier
-> static keyword can be used with
1. variables
2. block
3. methods
4. nested class or inner class (not outer
class)
-> use of static keyword :-
1. It is used to improve share-ability
2. It is used for memory management
-> static members belong to the class, not objects
=> static variables :-
-> If we declare any variable as static, it is known as static variable
-> Static variables gets memory allocated in method area at the time of class
loading
-> Example
-> Points to remember :-
1. We cannot create static local variable because main use of static variable
is improve share-ability but local variables have limited share ability thus it
voilates the rule of static keyword
2. If we declare any variable in static method, then it will be treated as local
variable only
3. We cannot use instance variable inside static method but we can use
static variable inside instance method
=> static block :-
-> A block created using static keyword is known as static block
-> Static block is executed at the time of class loading
-> Use of static block :-
1. We can create static block to initialize static variables
2. We can create static block to load native libraries at class loading time
-> Syntax :
static
{
}
-> static blockes will be executed from top to bottom
Interview Question :
   1. Can we print hello without using main methodYes but before JDK 7
      version
     Chapter-Nested Classes in Java
     => Java Nested Class :-
     -> A class which is defined inside another class or interface is
     known as nested class
     -> Use of nested class :-
     1. Nested class enable you to logically group classes that are
     only used in on place which will increase the use of
     encapsulation
     2. Nested class creates more readable and maintainable code
     3. Nested class help to access the private members of outer
     class
     -> Types of Nested Class :-
     1. Inner class
     -> Member Inner Class
     -> Method Local Inner Class
     -> Anonymous Inner Class
     2. Static Nested class
=> Member Inner Class
-> A class created within another class but outside the method is known as
Member Inner Class
-> Syntax :
class Outer
{
class Inner
{
}
}
-> Points to remember :-
1. Inner class name will be generated as OuterClassName$InnerClassName
2. Automatically outer class reference is created inside inner class
=> Method Local Inner Class :-
-> When we create a class inside the method of another class, then it is
known as method local inner
class
-> Syntax :
class Outer
{
void methodName()
{
class Inner
{
}
}
-> Points to remember :
1. We cannot invoke inner class method from outside the method
=> Anonymous Inner Class
-> A class that have no name and its name is generated by the compiler
automatically, that class is known as anonymous inner class
-> It is used if we want to override method of class or interface
Chapter-Pre-Defined Packages in Java
=> Packages :-
-> A package is the group of similar type of classes or interfaces or sub-
packages
-> A package is a folder which contains classes or interfaces (.class) or sub-
packages
-> Advantages of packages :-
1. Packages are used to categorize the classes or interfaces which makes
them easy to maintain or access
2. Packages are used to achieve modularity in our project
3. Packages are used to achieve abstraction in java
4. Packages are used to achieve security in java
5. Packages can be used to remove nameing collision
6. Packages improve shareability because we can use same package with
different java applications
7. Packages are used to achieve reusability
-> Types of packages :-
1. Predefined Package (Built-in Package)
2. User Defined Package
-> How to import the packages :-
1. import packagename.subpackage.*;
2. import packagename.subpackage.ClassName/InterfaceName;
3. Fully Qualified ClassName/InterfaceName
=> Predefined Package (Built-in Package) :-
-> The packages which are already provided by java are known as
predefined packages
-> Important types of packages in core java :-
1. java.lang
2. java.util
3. java.io
4. java.awt
5. javax.swing
6. java.sql
7. java.applet
8. java.net
9. java.rmi
=> java.lang :-
-> java.lang package contains the basic classes used in java programs
-> Classes/Iterfaces/subpackages are :-
= Object, Class, reflect (sub-package -Method, Constructor etc) etc
= System
= Boolean, Character, Byte, Short, Integer, Long, Float, Double
= Exception, NullPointerException,
ArithmeticException,
ArrayIndexOutOfBoundException etc.
= String, StringBuffer, StringBuilder
= Thread, Runnable
= more classes and interfaces like
Comparable, Cloneable...
-> How to import this package :-
import java.lang.*;
-> java.lang package is the only package which is by default imported to
every java class file
=> java.util :-
-> java.util package contains the utility classes and data-structure related
classes
-> Classes/Iterfaces/subpackages are :-
= Scanner, Calender, Date, Locale etc
= Collection, List, Set, Queue, ArrayList,
LinkedList, Vector, TreeSet etc
= regex (subpackage) Pattern, Matcher etc
-> How to import this package :-import java.util.*
=> java.io :-
-> java.io package contains the input and output
operations related classes or interfaces
-> Classes/Iterfaces/subpackages :-
= InputStream, OutputStream,
FileInputStream, FileOutputStream etc
= Reader, Writer etc
-> How to import this package :-
import java.io.*;
=> java.awt :-
-> java.awt package contains GUI based classes and interfaces
-> Classes/Iterfaces/subpackages :
= Window, Frame, Label, Button, TextField,
CheckBox, etc
-> How to import this package :-
import java.awt.*;
=> javax.swing :-
-> javax.swing contains GUI based classes and
interfaces
-> Classes/Iterfaces/subpackages :-
= JWindow, JFrame, JTextfield, JButton etc
-> How to import this package :-
import javax.swing.*;
.
Chapter-User-Defined Packages in Java
=> User Defined Package :-
-> The package created by the user or developer according to the
project requirements is
known as User Defined Package
-> Syntax :
package package_name;
package
package_name.sub_package_name;
-> Naming Convention for Package :-
1. Same 4 rules as an identifiers
2. -> company domain in reverse order
 -> client name
 -> project name
 -> module name
 => For example :-
www.smartprogramming.in (my company domain)