What is java
Java is programming language .
It is independent platform witch means it runs any plat form like windows,linux ,macos
What is package ? collection of class
What is project? collection of packages.
What is class? ts collection of variable and methods .
Data-types ;
1. primitive data types byte, short ,int long,boolean.double.float,char.
2. Objective data types String
What is variable ?
Its stores value example double price=12.55; (DOUBLE=DATATYPE , PRICE
VARIBLE ,123=VALUE
Or A variable is a location in memory (storage area) to hold data.
TYPES OF VARIBLES
Instance variable Static variable Local variable
This will declare in class level By using Static keyword to f We can provide local
instance variable we can make variable inside method
static variable level
Which stored in Heep memory area Which stored in method area Which stored in stack
area
From instance variable we should We can call variable by using
create object or instance ClassName.variablename
Static int id=10
Class c=new class()
{Class reference keyword
(constructor)}
For local variablename and instance variable name is same first preference to local variable.
If you wants still call instance variable we can use this.variablename
If current class instance variablename and super class instance variable name is same we have to use
super keyword super.variablename
METHODS
1. Instance methods
2. Static methods
1 Instance method
Public String name(){
Return “ ramesh”}
Public is access modifier String is return type name is methodname return is return statement
Above method is instance method
For calling instance method we need to create instance or object
We cant override private and final methods
Static method
If you are adding the static keyword to instance method which static method
We can call static methods classname.methodname();
we cant override static method
Which stored in method area
NOTE method inside method we cant write
Java Blocks
A block is a group of statements (zero or more) that is enclosed in curly
braces {}
Multiple line comments
JAVA KEYWORD LIST
OOP stands for Object-Oriented Programming.
1. Inheritances
2. Polymorphism
3. Interface
4. Abstract
5. Encapsulation
Inheritance
To acquiring super class data into subclass.
We denotes inheritance by extends keyword
If you can create object to for subclass you can able to access all super class data
and sub class data
If you create object for super class we can able to access only super class data
only
If you create super class reference and subclass object you cant access subclass
specific methods
Final class cant extends
Class to class A extends B
Class to interface redbus Implements phoneype.
Interface to interface extends
Interface to class not possible
Sub class is HDFC
And parent class is cred
Grand parent t class is bill desk
Grand parent
Polymorphism:
Polymeans many morphism mean changes
One things in different forms
It is two types
1. compile time polymorphism (method overloading)
2. Runtime polymorphism (method overriding)
1 METHOD OVERLOADING;
Methods name is same but parameters list are different in same class
Ethier number of parametrs list are different ,or data types are diffrenrt or order of parameters are
different
OVERRIDDING
If method name is same and parameters also same in two different classes
We cant override private final and static methods
INTERFACE;
Which hides data , which is pure abstract class
By using interface we can achive multiple inheritance
We can provide implementation in childe class only
We cant create object for interface
By default method are public and abstract where you declare are not
By defaults variables are public static final
We can write only abstract methos (non -concrate)
We cant write concreate methods
We cant write constructor
We cant write instance blocks and static blocks
Abstract:
Abstract is a keyword
Showing necessary data and hideing unnecessary data
By adding abstract keyword to class we can make class as a abstract
We can provide implementation for the abstract class in child class
only
We cant create object for abstract class
It allows abstract methods and non abstract methods
Its allows instance blocks and static blocks
We can create constructor for abstract class
Encapsulation;
Encapsulation means protecting data in a class
By creation private properties and public setters and getters methods
Constructor
Constructor is for initializing the data
In object it contains constructor
Constructor should be with a classname and which dosent have any return type
Ts is two types
1 No argument constructor
2 argument constructor
By default java will provide argyument aconstructor in class the default constructor will be over
ride
If you still want zero argument constructor you have to provide manually\
Diffrence between throws throw throwable ??
With throw we can create our coustome exception
With throws we can do the declaration of the exception
Throwable is super class of all exceptions classes
Access modifiers
private -> within class
default -> within class & within package
protected -> within class & within package & outside package subclass
public -> we can access anywhere in the project
Private Default Protected Public
We cant create class We can create We can create public
We can create default class class methods and
private methods and methods and variables
variables variables
EXCDEPTIONS
It is a child class of throwable
It will disturb normal exction flow of program.
Throwable contain two chile class 1 Exception and Error.
We can declare exception by try catch block and throws keyword
One try block may contain many catch block and one try block
It
Diffrence between final. finally,finalized??
Final finally finalized
Its is a key word its is a block it’s a object class method
Final method cant override Witch we can use whether we The garbage collector before
Final class cant extends getting exemptions i or not if calling un useble object its call
Final variables cant initialize want to print some data we can finalized method
While declaration it self we provide the data inside of
have finally block
to initialize Final variable
Single ton
For multipul request it will create single object
For that we have to create private static variable it will create private constructor so that we avoid the
initialization in other class
Than we will create static final method
Then we have to apply some functionality
If object is empty then only object will create
For first time the object is null so new object will create
For second request already object is there so it wont create new object
It will return extincting object