You are on page 1of 65

JAVA TOKEN-:

Java token element compiler identify


. java statements औ expressions tokens .
tokens 5 , :-

1. Keywords
2. Identifiers
3. Constants
4. Special Symbols
5. Operators
Keywords
, reserved words ए set , identifiers
.इ words „reserved words‟ „keywords‟ .

keywords define ए words . keyword


ए special perform .
– break, byte, case, boolean .
Identifiers
इ identifiers variable, functions, arrays, class, package, औ interface
ए . user define ए name . identifiers
name ए rules :-
 identifiers letter, dollar sign($) underscore ए.
 java identifiers, case-sensitive .
 identifier length .
 identifiers white space .
 ए identifier digit ( ) .
 keywords identifiers
.
Constants /Literals
constants variable . constant define
program उ modify . constant
fix value. इ literals .

special symbols
ए special symbols ए
इ ए इ ए .

[] () {}, ; * =
Brackets[] – closing औ opening brackets array element reference
ए .
Parenthesis() – इ function calls औ function parameters ए
.

braces{} – opening औ closing curly braces ए .


comma, – इ ए statements ए .
semi colon; – syntax ए part . compiler
instruction end औ instruction .
asterick * – इ pointer variable create ए .
assignment operator = – इ values assign ए .
operators
operators . :-

1. Arithmetic Operators
2. Unary
3. Assignment
4. Relational
5. Logical
6. Ternary
7. Bit-wise
8. Shift
9. instance of operator
10. precedence and associativity
JAVA SUPPORT SYSTEM-:

ए Object Oriented ए platform Independent

औ Java इ इ ई
Systems ए
Systems ए :-
(1) Internet (2) Bite code model (3) Applet (4) Serverlet (5) Html (6) Rmi (7) Jsp (8) J2EE (9)
Application server (10) J2ME
(1) Internet:- इ ए Internet Portability
| Internet उ
Applications Programs उ ए applet |

(2) Bite Code Model:- ए इ


उ Bite Code | Bite code उ
Compact | इ इ Downloading ए Use Full |

(3) Applet:- applet इ औ | applet ए


इ Animations औ Audio
applet use इ Audio play ए |

(4) Servlet:- ए Connection ए |


| उ |

(5) Html:- ए Data ए ए


उ उ इ |

(6) Rmi:- इ ए ए ए
Method Call | ए
Application इ उ |

(7) Jsp:- ए इ application


उ औ इ ई
उ उ |

(8) J2EE:- इ Application ए apis |

(9) Application server:- Application ए application


ए इ इ , base ए
transaction | उ ए :- tomcat server ,
jrun server |

(10) J2ME:- Java2 Mobile Edition Sun Micro Systems ए इ


Platform इ उ इ Operating develop | /*
इ ए उ Systems इ
उ ई इ ए Features ए
Java Program Structure-:

ई java program ए Structure (step by step).


ए java program section compulsory औ
optional .

Program ए Classes Define


ए Program ए Class main() Method
Define

Classes Data औ उ Data Perform Operations


Define Program ए
Classes औ उ Classes Combine

Java Structure-:
java Basic Structure :-

Documentation Section.

1) optional ए comment line group इ program related


document program ? program owner ?
program ?

2) इ इ |

3) इ इ :–

1) //text – compiler ignore ए इ ignore


|
2) /* text */ – group of lines multiple lines ignore |
3) /** text */ – इ ignore but syntax automatic
documentation section ए |
JVM(Java virtual mechine)-:
Java Virtual Machine JVM ए Virtual Machine
Machine Java Programming Language JVM , Java Code
Runtime Engine य Java Bytecode Machine
Language Convert

Java Application , Java Complier Java


Code Bytecode Convert इ (JVM) - Java Virtual Machine
, Bytecode Machine Code Convert , CPU इ
Extract

ए Java Code Fix , ए JVM


ए Configure , JVM ,Bytecode उ औ उ
Machine Language Convert

JAVA ENVIROMENT-:

JRE JRE ए software use software design


ए . JRE full form Java Runtime
Environment . JRE software develop एए Runtime
Environment . JRE इ class libraries, loader
class, औ and JVM . java program run
Java Runtime Environment (JRE) use .
JDK (Java Development Kit) JREऔ JVM . JDK इ
JRE इ .इ ए JRE इ
.

Why use JRE in hindi?


java application develop इ JRE use .
 JRE class libraries - इ औ file .
 इ use ava package class Math swingetc, util, lang,
awt, औ इ runtime libraries .
 applets run system JRE .
Features of JRE-:
 JRE ए Java Runtime Environment help JVM run .
 JRE ए java application development tool . deployment
technology Java Web Start Java Plug-in .
 ई java developer java source code JRE help run
. इ java code औ compile
.
 JRE functionality Java Database
Connectivity (JDBC), Java Naming and Directory Interface (JNDI) औ
Remote Method Invocation (RMI) .

How JRE Functions in hindi ?


JRE work इ .
JRE JVM instance .औ इ - , library classes
औ development tools. ए java code औ compile
, compiler इ file इ .
 Class loaders: class Loaders java program run
ए class . java JVM
class use . ,ए
औ .
 Byte code verifier: Byte code verify . interpreter
.
 Interpreter: java बए class ,औ उ
code verify , interpreter उ code इ by इ run
.
 Run-Time: run time ए technology use
coding उ period describe ए .
ई program run .
1. JRE Java Runtime Environment .
2. JRE ए software . java code run ए
environment .
3. JRE platform .
4. JRE ए JDK part .
5. JRE class libraries - इ औ file .
6. class Loaders java program run ए
class . java JVM class use
. ,ए औ

Type Casting-:
ए data type value data type type casting
. ए type value type cast .
ए data type value data type assign
type compatible ( ) . ए
compatible conversion automatically . automatic type
conversion . compatible उ cast .

java casting , :-

1:- Widening Casting (Automatic type conversion)


Widening casting data types convert .
:-

 data types ए compatible .


 data type value ए data type assign .
:-
public class Casting {
public static void main (String [] args)
{
int i = 150;
// automatic type conversion
long l = i;
// automatic type conversion
float f = l;
System.out.println ("Int value" + i);
System.out.println ("Long value" + l);
System.out.println ("Float value" + f);
}
}
इ उ :-
Int value 150
Long value 150
Float value 150.0
2:- Narrowing Casting (Explicit Conversion)
इ casting data types ए compatible
. data type value data type assign
Narrowing Casting perform .

:-
public class Explicit
{
public static void main (String [] args)
{
double d = 201.05;
// explicit type casting
long l = (long) d;
// explicit type casting
int i = (int) l;
System.out.println ("Double Data type value" + d);
// fractional part lost
System.out.println ("Long Data type value" + l);
// fractional part lost
System.out.println ("Int Data type value" + i);
}
}
इ उ :-
Double Data type value 201.05
Long Data type value 201
Int Data type value 201

Introduction to java operators-:


operators उ variables operations perform ए
data type operations perform इ ए operators

Operators unary औ binary 2 Operators


variables operand Unary operators ए operand apply
औ binary operators 2 operands apply

Java 6 type operators


1. Arithmetic operators
2. Logical operators
3. Bit wise operators
4. Relational operators
5. Assignment operators
6. Conditional operators
इ operators

Arithmetic operators
Arithmetic operators mathematical computation perform ए
Arithmetic operators 5 type इ

Operator Explanation Example

Addition operator 2 values add ए


Addition (+) a+b

Subtraction operator ए value value


Subtraction (-) a-c
subtract ए

Multiplication operators 2 variables values


Multiplication(*) a*b
multiply ए

ए variable variable
Division(/) ए division operator a/b


Modulus(%) a%b
modulus operator
Logical operators
Logical operators boolean values operations perform ए
operators 3 इ operations variables value
true false Logical operators
Operator Explanation Example

इ operators variables
Logical AND
value true result true a&&b
(&&)
false

इ operator variables
Logical OR (||) a||b
ए value true result true

ए unary operator variable


Logical NOT (!) !a
उ variable value उ

Bit-wise operators
Bit-wise operators bit by bit operations perform ए
operators variables values bits convert उ operations perform

Bit wise operators 4

Operator Explanation Example

इ operator 2 variables
Bit wise AND (&) उ common bits result variable copy a&b
इ operator 2 variables
Bit wise OR (|) उ uncommon bits result variable copy a|b

इ operator variable value


bits convert उ bits left shift
Left shift (<<) a<<b
bits variable
इ right

इ variable variable value


bits convert उ values right
Right shift (>>) a>>b
shift bits shift variable
इ right

Relational operators
Relational operators 2 variables relation ए
इ if statement इ operators 2
variables relation variables ए
औ ए

Operator Explanation Example

Equal to (==) variables equal result true a==b

Not equal variables ए equal result


a!=b
to(!=) true return

Greater left side variable right side variable


a>b
than(>) result true
left side variable right side variable
Less than(<) a<b
result true

Greater than left side variable right side variable


a>=b
equal to (>=) उ result true

Less than left side variable right side variable


a<=b
equal to (<=) उ result true

Assignment operators
Assignment process simple औ fast ए java assignment
operators provide इ

Operator Explanation Example

Simple operator right value value left


a=b;
assignment (=) variable assign

Plus operator left औ right variables


assignment value add left variable a+=b;
(+=) store

operator left side variable


Minus value right side variable
a-=b
assignment(-=) value result left side
variable store

operator left औ right side a*=b


Multiply
variables values multiply
assignment(*=) result left side variable
store

operator left side variable


Divide value right side variable
a/=b
assignment(/=) divide result left side
variable store

Conditional operator (?:)


Conditional operator java special operator if statement
इ ternary operator variables conditions according
values store ए इ operator ? ए condition
, condition true colon value colon
value variable store

Example

a=5, b=3;

c= a>b?a:b; // c a value store ए


Introduction to if-else statement in java

if statement उ condition test ए


boolean condition : true false. Java if

 if statement
 if-else statement
 if-else-if ladder
 nested if statement
Java if Statement
if statement, condition test true , if

Syntax:
if(condition){
//code to be executed
}
EX-:
//Java Program to demonstate the use of if statement.
public class IfExample {
public static void main(String[] args) {
//defining an 'age' variable
int age=20;
//checking the age
if(age>18){
System.out.print("Age is greater than 18");
}
}
}
OUTPUT-:

Age is greater than 18

Java if-else Statement

if-else statement condition condition true


if else

Syntax:
if(condition){
//code if condition is true
}else{
//code if condition is false
}
:
//A Java Program to demonstrate the use of if-else statement.
//It is a program of odd and even number.
public class IfElseExample {
public static void main(String[] args) {
//defining a variable
int number=13;
//Check if the number is divisible by 2 or not
if(number%2==0){
System.out.println("even number");
}else{
System.out.println("odd number");
}
}
}
उ :

odd number

Java if-else-if ladder Statement


if-else-if ladder statement ए condition multiple statement

syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}
Java Nested if Statement
Nested if statement ए if block (representation) ए औ if block
, inner if block condition outer
if block condition true
syntax:
if(condition){
//code to be executed
if(condition){
//code to be executed
}
}
Java Switch Statements
Use the switch statement to select one of many code blocks to be executed.

Syntax
switch(expression) {

case x:

// code block

break;

case y:

// code block

break;

default:

// code block

}
Array in Java
Array use multiple values single variable store ए |

10 employee ID store ए,

int[ ] empID = {10, 20, 30, 40,…100};

Advantage of Array in Java


1. Arrays huge number of values single variable use
represent |
2. Array declared values index position differentiate |
Note: index position 0 start |
Disadvantage of Array in Java
1. Array use उ size advance ए|
2. Array size fixed ,ए size declare उ
औ |
3. homogeneous store ए type
data store |
int type array declare ,उ
int values store , String type array declare ,उ
String store , data store compile time
error show |
Array is Indexed Collection of Fixed number of homogeneous data
element
Array data element collection ( size fixed )
उ index positions store |

Type of Arrays in Java


1. Single Dimensional arrays (or 1D arrays)
2. Multi-dimensional arrays (or 2D, 3D….nD arrays)
1. Single Dimensional arrays (or 1D arrays)
Single Dimensional arrays ए subscript [] |

Example:
#include <stdio.h>

int main() {

int arr[3] = {10, 20, 30}; //declaring and initializing one-dimensional array
in C

// After declaration, we can also initialize array as:

// arr[0] = 10; arr[1] = 20; arr[2] = 30;

for (int i = 0; i < 3; i++) {

// accessing elements of array

printf(" Value of arr[%d]: %d\n", i, arr[i]);

}
}

Output-:
Value of arr[0]: 10
Value of arr[1]: 20
Value of arr[2]: 30
2. Multi-dimensional arrays (or 2D, 3D….nD arrays)

2D arrays subscript [][] , उ 3D arrays


subscript [][] [] |इ values row औ column
index positions store |

Example:

1. #include<stdio.h>
2. int main(){
3. int i=0,j=0;
4. int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
5. //traversing 2D array
6. for(i=0;i<4;i++){
7. for(j=0;j<3;j++){
8. printf("arr[%d] [%d] = %d \n",i,j,arr[i][j]);
9. }//end of j
10. }//end of i
11. return 0;
12. }

Output-:
Arr[0][0]= 1

Arr[0][1]= 2

Arr[0][2]= 3

Arr[1][0]= 2

Arr[1][1]= 3

Arr[1][2]= 4

Arr[2][0]= 3

Arr[2][1]= 4
Arr[2][2]= 5

Arr[3][0]= 4

Arr[3][1]= 5

Arr[3][2]= 6

Introduction to Java Strings


Strings characters sequence “Java in Hindi” ए string Java strings objects

implement इ ए , strings operations perform

Operations 2 strings compare strings perform String ए class

normal string variables create औ string class object create औ

operations perform

String myString = "this is a string"; // variable

String myString = new String("This is a string"); // object

String ए variable औ ए object string object

ए object create उ ई change उ एऊ ए ए example

myString object इ text “This is a string” ई change ".

string variable उ changes

Java methods provide , string object modification

ए string object generate

Vectors-:
java.util इ इ ए java.util
इ list इ इ ए

 इ इ इ

 components contain ए इ इ ए

 arrayList insertion maintain ए


इ -
 ए , , ,
(result)

Syntax of vector class :-


pulic calss Vector<E> extends AbstractList<E> implements List<E>,
RandomAccess, Cloneable, Serializable

<E> elements

class convert primitive into object and object into primitive


ए mechanism

J2SE 5.0 , औ इ औ
इ object primitive :
औ इ

Use of Wrapper classes in Java in Hindi


ए - ए ,इ ए ई
, इ , इ , इए ,

 : call by value इ ए, ए primitive


, , primitive
,
 इ : इ ए
ए primitive value , इ Wrapper classes object's

 इ : इ
 java.util : java.util एउ
 [Collection Framework]:
( , , , ,
, , , , )

java.lang package wrapper classes in java


ई :

wrapper class in java


 Autoboxing
,
उ ए, इ इ , ,इ इ , , ,
, औ

5 , ए valueOf () उ

 example of wrapper class in java : Primitive to Wrapper

1. //Java program to convert primitive into objects

2. //Autoboxing example of int to Integer

3. public class WrapperExample1{

4. public static void main(String args[]){

5. //Converting int into Integer


6. int a=20;

7. Integer i=Integer.valueOf(a);//converting int into Integer explicitly

8. Integer j=a;//autoboxing, now compiler will write Integer.valueOf(a) internally

9.

10. System.out.println(a+" "+i+" "+j);

11. }}
OUTPUT :- 20 20 20

Unboxing for wrapper class in java in Hindi


:
5 , ए
intValue () उ

Multithreading in Java in Hindi


Java , multithreading ए threads ए
execute .इ CPU utilization (उ ) .

ए thread, औ lightweight sub-process . Thread ए


independent ( ) उ execution path .
thread ई exception ,उ threads ई
.

Multithreading उ multitasking (achieve) ए .


इ games औ animation create .

Advantage of Multithreading –
1. user block threads ए independent .
2. इ ए .
.
3. ए process threads इ resources ( – memory, data औ files
) share . threads resources allocate
.
4. CPU idle time system performance
.
What is Thread in Hindi – ?
Thread ए lightweight process . multithreaded programming
. ए multithreaded program parts contain
ए run . program part ए thread .

thread execution path .औ independent


ए thread ई exception उ threads
.

इ thread . user thread औ daemon thread.


(daemon threads use application clean औ
इ background use .)

threads ए „Thread Class‟ use .

Life Cycle of a Thread –


इ इ stages :-

image source

 New – ए इ इ new state . इ state


start() method call .
 Runnable – start() method start
runnable runnable state .
 Running – ए running state scheduler उ select .
 Waiting – ए waiting state ए task
ए task ए wait .
 Terminated – thread task terminated state
.
इ :- Thread life cycle ?

Thread Create ?
इ create :-

1. Thread class extend


2. Runnable interface implement
Thread class extend
class MultiDemo extends Thread{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
MultiDemo t1=new MultiDemo();
t1.start();
}
}
:- thread is running…
Runnable interface implement
class MultiDemo implements Runnable{
public void run(){
System.out.println("thread is running...");
}

public static void main(String args[]){


MultiDemo m1=new MultiDemo();
Thread t1 =new Thread(m1);
t1.start();
}
}
:- thread is running…
Thread class औ runnable interface ब
1. thread class extend class classes extend
. multiple inheritance .
runnable interface implement class base
classes extend .
2. thread class extend ए thread (functionality)
. in-built methods :- yield(), interrupt()
. runnable interface उ .

Thread methods in Java in Hindi


thread class thread methods :-

start() इ start ए .

run() इ run ए .

sleep() thread ए time period ए suspend .

join() इ .

getPriority() priority return .

setPriority() priority .

getName() name return .

setName() name change .

isAlive() check alive ( ) .

yield() execute thread object pause औ threads execute .

suspend() इ thread suspend ए .

resume() इ suspended thread resume ए .

stop() इ उ thread stop ए .


destroy() इ thread group destroy ए .

interrupt() इ interrupt ए .

Thread Exception
sleep() Method ए Exception Throw इ Exception Catch ,
Program Compile ई Thread Suspend Mode , Method
Invoke उ उ Thread Method Invoke ,
sleep() Method IllegalThreadStateException Throw
उ ए ई Thread Sleep Mode resume() Method Invoke
ई Sleeping Thread ई Instruction Execute suspend()
Method
Method Call , Exception Throw , उ Exception
Handle इ ए Appropriate Exception Handler ए Exception
Handler catch Block ई :
catch(ThreadDeath excp )
{
. . .
. . . // Killed Thread
}

catch(InterruptedException excp )
{
. . .
. . . // Killed Thread
}

catch(IllegalArgumentException excp )
{
. . .
. . . // Killed Thread
}

catch(Exception excp )
{
. . .
. . . // Killed Thread
}
Thread Priority-:
Java ए thread ए JVM default priority set | thread create
programmer priority set | इ priority set ए Java
getPriority() औ setPriority methods |
Priorities 1 10 |

Constants for Thread Priorities

 public static int MIN_PRIORITY : thread ए minimum priority | इ value 1 |


 public static int NORM_PRIORITY : thread default priority | thread ए ई priority
priority set |इ value 5 |
 public static int MAX_PRIORITY : maximum priority | इ value 10 |

EX-:

//CheckPriority.java

class CheckPriority extends Thread{

public void run(){

System.out.println(Thread.currentThread().getPriority(
));

public static void main(String args[]){

CheckPriority t1 = new CheckPriority();


CheckPriority t2 = new CheckPriority();

CheckPriority t3 = new CheckPriority();

t1.start();

t2.start();

t3.start();

Output :

Synchronization-:
Multiple Threads Use , Concurrency ए ई
Threads Activities Coordinate Threads Coordinate
इ Synchronization
Synchronization Use Most Common Threads
Resource Share ए ए Thread उ Shared
Resource Access , Serialization
Java Applet - Local and Remote
Applet Web Page Embed
Web Page औ उ Applet Embed Applet
Remote Computer System Download औ उ Web Page Embed

Applet Local Develop औ उ Local System उ


Applet Store , इ Applet Local Applet ए Local
Web Page Local Applet उ Internet Connected
Web Page Local Computer Directories Search Applet
औ Web Page Load

Applet Applet Developer Develop औ


Store Internet Connected Computer
Internet Connected उ Remote Applet Internet Download
Local Computer System Run Remote Remote Applet
Computer System Web Browser Load ए उ Applet Web
Address औ Applet इ Web Address Uniform
Resource Locator (URL) औ इ Address HTML File APPLET Tag
CODEBASE Attribute ए Specify

Application-: Java ए General-purpose programming language , class based


औ object-oriented .इ . ए
Application Program .इ , Computer Execute
औ इ ए .

Applet/Life cycle of Applet:-


Applet ए उ run ई applet
create 5
Applet इ इ 5 5 methods
1:-Initial state:- ई applet create init() activate
life applet ए initialize
इ syntax :-
Public Void init()
{
//action
}

2:-Running state:- start() call running


applet
इ syntax :-
Public void start()
{
//action
}

3:-Idle state:- stop() call Idle applet


इ call
इ syntax :-
Public void stop()
{
//action
}

4:-Dead state:- destroy() call इ


applet ए remove applet
ए execute
इ syntax :-
Public void destroy()
{
//action
}

5:-Display state:- paint() call इ


ई call
इ syntax :-
Public void paint()
{
//action
}

Passing parameter applet-:


Parameter in Applet
We can get any information from the HTML file as a parameter. For this purpose, Applet
class provides a method named getParameter(). Syntax:

1. public String getParameter(String parameterName)

Example of using parameter in Applet:


1. import java.applet.Applet;
2. import java.awt.Graphics;
3. public class UseParam extends Applet{
4. public void paint(Graphics g){
5. String str=getParameter("msg");
6. g.drawString(str,50, 50);
7. }
8. }

myapplet.html

1. <html>
2. <body>
3. <applet code="UseParam.class" width="300" height="300">
4. <param name="msg" value="Welcome to applet">
5. </applet>
6. </body>
7. </html>

HTML applet tags-:


 align: Specifies the alignment of an applet.
 alt: Specifies an alternate text for an applet.
 archive: Specifies the location of an archive file.
 border: Specifies the border around the applet panel.
 codebase: Specifies a relative base URL for applets specified in the code
attribute.
 height: Specifies the height of an applet.
 hspace: Defines the horizontal spacing around an applet.
 mayscript: Indicates whether the Java applet is allowed to access the
scripting objects of the web page.
 name: Defines the name for an applet (to use in scripts)
 vspace: Defines the vertical spacing around an applet.
 width: Specifies the width of an applet.

Ch-: 3
what is constructor i

constructor झ :-
 Constructors data members values initialize
ए .
 constructor member function .
 constructors .
 constructors return type .
 create constructor .
 virtual .
 public declare .
 derived class inherit .
 constructors - default, parameterized copy
constructors.
 ई constructors इ ए default
constructor .
types of constructors
इ :-
1:- default constructors:- default constructors empty constructors
इ ई arguments .इ ई .
ई constructors इ इ default constructor
. constructor class
.औ constructor return type declare
.
syntax:-
class – name ()
{
// constructor definition;
}
2:- parameterized constructors:- ए constructor arguments
इ class name . arguments,
create उ initialize .
इ constructors data members values
.

class Employee {
2 String name;
3 int id;
4
5 void details() {
6 System.out.println("My name is " + name);
7 System.out.println("My id is " + id);
8 }
9}
10
11public class ConstructorDemo {
12 public static void main(String[] args) {
13 Employee ram = new Employee();//creating object of class Employee
14 ram.details(); // calling method using object
15 }
16
17}
18
19Output:
20My name is null
21My id is 0
Method Overloading in Java in Hindi

Method Overloading in Java in Hindi


java , ए class ए methods उ parameters
- इ method overloading .
, “method overloading ए feature ए class
same ( ) ए methods औ उ parameters - .”
constructor overloading .

advantage (इ )

इ :-

 program readability .
 programmers flexibility method
different type data ए call .
 इ clean .
 execution time इ binding, compilation time
.
 इ code use , memory .
 method overloading complexity .
method overloading ?
java method overloading :-

1. By changing number of arguments (arguments )


2. by changing data types (data types change )

Arguments
ए example methods , method arguments औ
method arguments .

class Demo
{
void multiply(int l, int b)
{
System.out.println("Result is"+(l*b)) ;
}
void multiply(int l, int b,int h)
{
System.out.println("Result is"+(l*b*h));
}
public static void main(String[] args)
{
Demo ar = new Demo();
ar.multiply(8,5);
ar.multiply(4,6,2);
}
}
:-
Result is 40
Result is 48.

Method Overriding in Java in Hindi – इ ?


November 28, 2020 by yugal joshi

Hello ! इ post Method Overriding in Java in Hindi (


इ ?) औ इ examples . ए
:-

(contents) [show]
Method Overriding in Java in Hindi
subclass (child class) method parent class declare
इ java method overriding .
, “ए method subclass declare parent
class इ method overriding ”
subclass ए method , super-class method ए name, ए
parameters, औ return type subclass method overriding
method .

Rules of method overriding in Hindi

इ , :-

1. child class औ parent class ए method same (ए )


ए.
2. parent-class औ child class same ( ) return type औ same
parameter list ए.
3. final औ static declare method override
.
4. child class method access modifiers, parent class method
restrictive ( ) ए. – parent-class
method public declare child-class private औ
protected declare .
5. instance methods override subclass
inherit .
6. ए method inherit उ override
.
7. parent class abstract methods override ए.
8. constructors override .

class Animal{
//Overridden method
public void eat()
{
System.out.println("Animal is eating");
}
}
class Dog extends Animal{
//Overriding method
public void eat(){
System.out.println("Dog is eating");
}
public static void main( String args[]) {
Dog obj = new Dog();
//This will call the child class version of eat()
obj.eat();
}

Method overloading Method overriding

इ different ए
इ औ same ए.
same ए.

compile time polymorphism . run time polymorphism .

code readability . code reusability .

इ return type औ
इ return type ए ए.
.

inheritance इ inheritance
औ . .

इ static method perform इ static method perform


. .

static binding . dynamic binding .

इ access modifiers औ non access इ access modifiers औ non access modifiers


modifiers change . .

ए code refinement . ए code replacement .

private, static औ final method overload private, static औ final methods override
. .

इ compile time polymorphism औ static इ run time polymorphism औ dynamic polymorphism


polymorphism early binding . late binding .
इ example:-
इ example-
class OverloadingDemo{ static int
class OverridingDemo{ void a()
add1(int x,int y){return x+y;}
{System.out.println("A");}} class b extends
static int add1(int x,int y,int
c {void a(){System.out.println("B");}
z){return x+y+z;} }

}
इ उ :-
Dog is eating.

Advantage of method overriding


इ :-

 इ child class ए method ई


implementation , parent class ई .
 इ runtime polymorphism ए .

Difference b/w Method Overloading and Method Overriding in Hindi


औ इ :-

Introduction to Static Keyword in Java


Java , static keyword use memory management ए
इ use variables, methods, blocks and nested classes
ए keyword ए ए class variable or method share
ए use Basically, static use constant variable
method ए class example ए ए
class main method static labeled

Static member ए, keyword static इ declair


class member static declared , इ class
objects औ object reference इ access
Applications of Static keyword

 Static Block
 Static Variable
 Static Method
 Static Classes

1. Static Block
static variables ए computation
, ए
static block declair class
load ए execute Static Block use झ ए
ए ए Java program ए

import java.util.*;
public class BlockExample{
static int a = 20;
static int b;

static {
System.out.println(“Static block initialized.”);
b = a * 9;
}

public static void main(String[] args)


{
System.out.println(“Inside main method”);
System.out.println(“Value of a : “+a);
System.out.println(“Value of b : “+b);
}
}

2. Static Variable
variable static declare , variable ए copy class
level objects created and divided Static variables are,
essentially, global variables Basically, class example same static
variable share Static variables class-level ए

import java.util.*;

public class VariableExample


{
static int a = b();

static {
System.out.println(“Inside the static block”);
}

static int b() {


System.out.println(“from b “);
return 20;
}

public static void main(String[] args)


{
System.out.println(“Value of a : “+a);
System.out.println(“Inside main method”);
}
}

3. Static Methods
ई method static keyword declare , इ ए static method
static method example main( ) method static
declared following restrictions :
static methods call

static data directly access

public class StaticMethodExample


{
static int j = 100;

int n = 200;

static void a()


{
a = 200;
System.out.println(“Print from a”);

n = 100;

a2();

System.out.println(super.j);
}

void a2()
{
System.out.println(“Inside a2”);
}

public static void main(String[] args)


{
}
}

4. Static Classes
ए class static ए nested class Nested static
class Outer class reference need इ , ए static class
Outer class non-static members इए ए example
work |
public class NestedExample{
private static String str= “Codeash”
static class MyNestedClass{
public void disp(){
System.out.println(str);
}
}
public static void main(String args[]){
NestedExample.MyNestedClass obj = new NestedExample.MyNestedClass();
obj.disp();

Nested Class in Java-:


Java , ए class class define औ class
define उ Nested Class .
Nested classes classes ए group ए
use .इ encapsulation ,औ इ program read
इ code maintain .

syntax –
class OuterClass {
// ...
class NestedClass {
// ...
}
}
 nested class scope इ outer class scope bound ( ) .
ऊ syntax .
 ए , outer class members access , (private
member ). outer class members access
.
 ए , outer class ए member .
 ए nested class public, private protected declare .
Types of Nested Class
इ :-

1. Static Nested Class – ए class static members .


2. Non-static Nested Class (Inner class) – ए class non-static
members .
इ :-

Static Nested Class in Hindi


, ए ए static class define इ
static nested class .ए static nested class outer class member variables
औ methods access . इ restriction ( ) static nested class
.
Syntax-
class MyOuter {
static class Nested_Demo {
}
}

Non-static Nested Class (Inner Class) in Hindi


Non-static Nested Class inner class . nested class
. Inner Class, outer class members access . Inner class
private declare , ए इ private declare
इ class access .

example:-
class Outer_Demo {
int num;

// inner class
private class Inner_Demo {
public void print() {
System.out.println("This is an inner class");
}
}
// Accessing he inner class from the method within
void display_Inner() {
Inner_Demo inner = new Inner_Demo();
inner.print();
}
}

public class My_class {

public static void main(String args[]) {


// Instantiating the outer class
Outer_Demo outer = new Outer_Demo();

// Accessing the display_Inner() method.


outer.display_Inner();
}
}
:- This is an inner class.
ऊ ए उ Outer_demo ए outer class औ Inner_demo() ए inner class .

Inner Class –
इ :-

1. Local inner class


2. Anonymous inner class

Local inner class –

local inner class ए block define . , method


body . local inner class, outer class members . उ block
define ए .

:-
public class localInner1{
private int data=30;//instance variable
void display(){
class Local{
void msg(){System.out.println(data);}
}
Local l=new Local();
l.msg();
}
public static void main(String args[]){
localInner1 obj=new localInner1();
obj.display();
}
}
उ :- 30

Anonymous inner class –

inner class declare उ anonymous inner class


.इ classes ए declare औ instantiate . इ
ए class interface method override ए .इ
example :-

example:–
abstract class Person{
abstract void eat();
}
class TestAnonymousInner{
public static void main(String args[]){
Person p=new Person(){
void eat(){System.out.println("awesome nuts");}
};
p.eat();
}
}
उ :- awesome nuts.

Advantage of Nested Class in Hindi


इ :-

 outer class members access .


 encapsulation .
 इ code read औ maintain .
 code optimize code .
Access Modifiers in Java in ए ?
Access Modifiers in Java in Hindi
java , access modifiers class, constructor, variable, method data
member accessibility set .
, “access modifiers class, constructor, methods variable
scope .”
ए इ access level . java 4
access modifiers , :-

1. Default
2. Private
3. Protected
4. Public

Default

class, constructor, methods ए access modifier


उ default ए झ .

Default modifier इ package .इ


ए package default modifier ए class classes इ
package इ class access . package ई
class इ class access .
modifier, private accessibility protected औ
public restricted .

Example:-
इ ए उ झ :-

package myWebsite;
class Study {
void message () {
System.out.println ("This is a study related website");
}
}
ऊ ए उ Study class default access modifier . औ इ Study class
classes ए myWebsite . इ class
इ package access compiler error .

Private
इ private specify .
 private declare methods data members उ class
access declare .
 package ई class इ members access .
 top level class interface private declare .
nested classes private declare .
example:- इ उ :-
एउ myPackage - Message औ Example . औ
Message ए private declare .औ इ method Example
access compile time error .

package myPackage;
class Message {
private void show () {
System.out.println ("This is a message");
}
}
public class Example {
public static void main (String args []) {
Message obj = new Message ();
//trying to access private method of another class
obj.show (); // Compile Time Error
}
}

Protected

इ protected specify .

 protected declare methods data members उ


package access package sub-class
access .
example:-
एउ packages P1 औ P2 create .इ class A, P1
public . इ ए इ package access . इ show
method protected . इ एइ class B inherit .

package p1;
public class A{
protected void show(){
System.out.println("this is ehindistudy.com");
}
}
package p2;
import p1.*;

class B extends A{
public static void main(String args[]){
B obj = new B();
obj.msg();
}
}
:- this is ehindistudy.com

Public

Public access modifier public specify .

 इ modifier access .
 इ restriction ( ) .
 इ modifiers scope .
Example:- इ उ :-
package myPackage;
public class Study
{
public void show ()
{
System.out.println ("this is study related website");
}
}
package yourPackage;
import myPackage. *;
class Test
{
public static void main (String args [])
{
Study obj = new Study;
obj.show ();
}
}
Methods in Java – ?

Methods in Java in Hindi


ए Method ए block run इ call .
method parameters pass . methods
ए , औ इ functions .

, “Java method statements ए collection


.”

methods code use ए . ए code


औ उ - use . code
.इ methods code .

Create a Method –

method class declare . इ method define


औ इ parentheses () . java define methods
:- System.out.println() , methods ए
ए create .

example:-
public class Yugal{
static void myMethod () {
// code to be executed
}
}
ऊ ए उ :-

 myMethod() .
 static method Yugal class .
 void इ method ई return value .

Call a Method –

ए method call ए, method parentheses () औ


semicolon ; .ए call .
ए उ myMethod() text print ए , इ
call .

example:-
public class Yugal {
static void myMethod () {
System.out.println ("My name is Yugal!");
}

public static void main (String [] args) {


myMethod ();
}
}
// इ उ :- My name is Yugal!

Types of Java Methods in Hindi


इ :-

1. pre-defined methods
2. user-defined methods

Pre-defined method –

, pre-defined methods methods java class library define


. इ standard library method built-in method . इ
program इ call . pre-defined methods :- length(),
equals(), compareTo() औ sqrt() .
pre-defined methods class define .

User-defined methods –

methods user define उ user-defined methods .इ


modify .
Object create
ए object class create . , new
keyword objects create ए .
ए class object create steps :-

 Declaration – variable declare .


 Instantiation – new keyword object create ए
.
 Initialization – ,इ new class name औ parenthesis
. - object initialize ए class
constructor call .

 ए object ए real world entity .


 ए run time entity .
 object ए entity state औ behaviour .
 ए object, class ए instance .

Final Keyword in Java in Hindi


, Final Keyword user restrict ए . ए non-
access modifier औ य variables, classes औ methods य
.
Java final keyword constant denote ( ) ए .
final उ value change .
Final Variable
variable final declare इ value
. constant . declare ए variable initialize ए.
initialize इ blank final keyword .

Blank final variable constructor औ static block initialize .


ए initialize compile time error ए .

example:-
class Study{
final int capacity=50;
void display(){
capacity=60;
}
public static void main(String args[]){
Study obj=new Study();
obj.display();
}
}
:- Compile Time Error
final variable औ variable इ ए variable
assign final variable value assign .इ ए
final variable ए value constant .

Final Method –
method final keyword declare उ final method .
ए final method overridden .इ ए child class,
parent class final method call उ override .

example:-
class ABC{

public final void finalMethod(){


System.out.print("this is ABC class");
}

class XYZ extends ABC{


public final void finalMethod() {
System.out.print("this is XYZ class");
}
}
इ compile time error ए show() method override .

Final Class –
ए class final declare उ final class .ए final class
inherit . इ extend .

:-
final class FirstClass {
public void show() {
System.out.println("Hello world!");
}
}

// try to extend the final class


class SecondClass extends FirstClass {
public void show() {
System.out.println("How are you?” }

public static void main(String[] args) {


Main SecondClass = new SecondClass();
obj.show();
}
}

finalize Method in Java


इ इ Resources Release इ Resources Release
ए Java ए Mechanism Provide Finalization

Class Finalize Method Add ए Class ए finalize()


Method Define Java Compiler इ Method Automatically उ
Call , ई Object Destroy इ Method Actions Specify
, Object Destroy Perform

Abstract Class in Java in Hindi


Class abstract declare उ Abstract Class .इ
abstract औ non-abstract methods . class abstract
methods .
 abstract class abstract keyword declare .
 इ abstract औ non-abstract methods .
 इ instantiate इ objects create
ए .
 इ constructors औ static methods .
 abstract class use ए, इ class inherit औ
abstract methods implementation .
 इ final methods .
 abstract methods body .
ए abstract class

Abstract method ?
abstract keyword declare उ abstract method .इ
implementation इ body .

 इ abstract method name .


 ए abstract ए method signature contain इ body
.
 curly braces , इ method semicolon ; .

Visibility mod and control

ब य , , इ
उ ए

( ) , / उ
/ ए

, ए इ ,इ एउ य
इ ए औ उ

य (access specifiers in java in hindi)

<access specifier> <class-keyword> <class name>

4 ए -
1. (Default Access Specifier in Hindi)

ए , ए औ
, ई ए उ इ

ए , ए , उ
, ए ए ए

String version=”1.5.1”;

boolean processOrder()

return true;

2. (Private Access Specifier in hindi)

, ए औ ए
, इ ,उ इ ए

इ ए उ , ए ए ( )

public class Logger

private String format;

public String getFormat()

return.this.format;
}

public void setFormat(String format)

this.format=format;

ऊ ए एउ Logger ए ,इ format इ
इ ए इ ए Logger
ई ए

,इ ए ,
इ इ ए
format औ उ इ

getFormat() इ ए ,
format

, ए format औ ए ए ,इ
ए ए , इ ई

3. (Public Access Specifier in hindi)

, , ,इ इ , ए
उ ई , ए

,ए ए ए , ए
ई उ ए

ई ए , उ
, उ

उ उ इ उ इ
इ ए , उ
इ ए इ ,
, ए इ ए

4. (Protected Access Specifier in hindi)

, , ,इ इ , ए
उ ए

औ इ , इ इ ए
इ , इ ए य

class Audio

protected Boolean openSpeaker(speaker sp)

//implementation details;

class Stream extends Audio

boolean opeanSpeaker(Speaker sp)

//implementation details;

You might also like