0% found this document useful (0 votes)
36 views47 pages

Abstraction in Java PDF

java notes

Uploaded by

vivek kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views47 pages

Abstraction in Java PDF

java notes

Uploaded by

vivek kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

.

Abstraction in Java
Abstraction यह एक कय (process) ह user क , क product क क य (क क
क ह) क hide क क, क क functions क ह य ह|

कह , user क product - क क ह ह, ह ह, product क


internal working क क क ह ह |

How to Achieve Abstraction in Java? Abstraction achieve ?

Java Abstraction achieve क क कह|

1. Abstract class क use क क

2. Interface क use क क

Interface ह 100 % abstraction क ह Interface क use क क ह method


implementation क abstract क क ह| कह , Interface क method
abstract ह ह क method क implementation body ह ह |

Abstract class क use क क ह partial abstraction achieve क ह requirement क


ह 0 100 % क abstraction achieve क क ह | Abstract class क method क
implementation body ह क हऔ क क ह |

post ह Abstract class क औ Interface क ह post |

Abstract Class in Java

1. class क abstract keyword क use क क declare कय ह|

2. Abstract class क regular method abstract method ह क ह | regular method


क method क implementation body abstract method method
क implementation body न |

3. यह ह क abstract class क abstract method ह ह | , क class क


क एक abstract method ह , class क abstract declare क ह
compile time error ह |

4. Abstract class ह default constructor ह ह औ ह parameterized constructor define क


क ह | Constructor क क ए Constructor in Java click क |

5. क final static method ह क ह|

6. Abstract class क object ह create कय क | , क sub class क object create क


क ह|
Abstract method in Java

1. ह method क क implementation body ह, Abstract method कह ह |

2. method क abstract keyword क use क क declare कय ह|

3. क, abstract method क body ह ह , { } क use ह ह

4. Abstract method क semicolon ; end क कह

5. Abstract method क use क क ए क abstract class क inherit extends क क

abstract method क override क ह|

Advantage of abstraction in Java

1. यह code duplication क avoid क reusability क ह

2. यह security confidentiality( य )क ह क, user क क functionality क


ह य ह|

3. क code क enhance क easy ह ह क, ह end-user क ए


ह internal coding क change क क ह|

4. Abstract class, loosely-coupled class create क help क ह|

Encapsulation in Java
Encapsulation एक mechanism/process ह, क use क क, data (variable) data
कयक methods (functions) क एक wrap group क क एक single unit य ह
|

यह ह क ह data औ क methods क एक Java class define क ह|

ए, Java class, Encapsulation क example ह |

Encapsulation ? – Need of Encapsulation in Java


Mostly, Java Encapsulation क data hide क क ए use कय ह| क ह यह decide
क ह क, user क code क क part क access हए औ क part क ह | ह यह कह
क ह क, data security क ए use कय ह|

Polymorphism

polymorphism एक य ह क object क behaviour क object update य modified


क क कय क ह य method overriding औ method overloading achieve
कय ह

polymorphism यह क ह Poly औ morph क ह क क क


एह

ह क क एह ह औ

Real world example of polymorphism in java in hindi

क animals ए ह ह animals क - behaviour ह ह क


animals क क ह ह animal क एक ह ह
image ह क

image ह एक class य क Animal ह औ क एक method ए


( void sound() )

ह class य Lion, Dog औ Cat classes animal class क extends क क


method sound क override कय

औ क क

Defination of polymorphism in java in hindi


polymorphism एक य ह यह object क क object क modified क
क ह

यह य inheritance क ह ह यह inheritance ह ह

क inheritance parent class child class क property क grab क ह

Also read : inheritance in java in hindi

polymorphism child class parent class क property क क modification क


क ह

Important points of polymorphism in java in hindi

1. parent class क property क child class क modified क ह

2. polymorphism method overloading औ method overriding achive कय ह

3. polymorphism क कह ह runtime polymorphism औ compile time polymorphism

Features of JAVA in hindi

1:-Object-Oriented:- एक pure ए ह procedures क


य ह कय ह यह objects ह

2:-Platform Independent:- ह यह ह क run ह


क ह यह feature औ क क suit ह क क क क ह

platform independent एह क source क क ए क compile


कय ह ह byte क कह ह औ ह क JVM ह ह ह byte code क
interpret क ह
3:-Secure:- क feature यह ह क यह एक ह क secure ह
क java runtime environment run ह ह public key encryption क य क
ह क applications encrypted access ह ह

4:-Compiled Interpreted:- source क क byte क compiled कय ह


JVM क machine क interpreted कय ह
5:-Simple, Small Familiar:- एक ह क c++ क ह ह syntax ह ह
क क ह
operator overloading( ) header files क य ह
कय ह यह औ ह ह

6:-Portable:- एक portable ह क byte क ह क run ह ह ए यह


एक portable ह; कय क ह

7:-Robust:- garbage collection ह ह ए क य ह


errors ह ह कय क ह क Robust

8:-Distributed:- एक distributed ह क ह क run क क ए


कय ह HTTP FTP क क य कय ह क
ए कय क

9:-Multi threaded:- multi threading क य कय ह क sub


program divide कय ह sub programs क execute कय ह
What is JVM and JRE in hindi

JVM क (virtual) ह JVM एक virtual ह क runtime environment


क ह

JVM byte code क Native machine code convert क ह Native machine code क
execute क ह

JVM क execute क ह क generate क ह

JVM independent ह ह

JRE(java runtime environment):-

JRE क java runtime environment ह JRE क java runtime कह ह JRE, JDK(java


development kit) क एक ह ह JRE applications क क क क ए य tools
क एक हह ह

JRE क ह क contain कय ह ह, runtime JVM य क ह


यह JVM क contain कय ह ह

क क run क ह ह क JRE क ह

JRE क sun Microsystems क कय


Java Program Structure In
Hindi
 क 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 Program Structure In Hindi

 Constructor In Java In Hindi

Java Structure In Hindi


java क क Basic Structure ह क ह :-

Documentation Section

1) यह optional ह यह एक comment line क group ह program related document ह ह


program क ह ? program क owner क ह? क program क य य ह?

2) क क ह ह|

3) क कक क य कय ह :–

 //text – यह क क compiler ignore कय ह यह एक क ignore क ह|

 /* text */ – यह group of lines य multiple lines क ignore क ह|

 /** text */ – ह क ignore क ह but यह syntax automatic


documentation section क ए कय ह|

Package Statement

1) यह optional ह हय ह program package ह ह य create क हह ह package


statement क use क ह|

2) package create क क ए यह statement ह–


package <package_name >;

example :- package student;

क कय ह क क ह|

Import Statement

 यह optional ह ह| क C य C++ header file क include क क ए


#include क य क ह, क क क header file क include क क ए
import keyword क य कय ह|

 example:- import [Link] ;

 test package क य class ह program import ह ए औ ह


क ए method() क program use क क ह, ह test package ए
class क program import क ह ह :-

 import test.*;

 Java Applet In Hindi


Interface Statement

यह हय ह multiple inheritance क implement क ह ह क


य क ह | 2 क properties क 1 क ह|

Class Definition

य ह multiple class क य क ह ह multiple class क definition section


यह ह क क ह|

class <class_name>

data member ;

member method;

Main Class Definition

1) यह ह ह|
2) क क 1 main method ह हए |
3) यह ह ह ह |

main method statement

How to compile and run


a java program
क क क क2 कह ह. java ह ह IDE क use
क ह notepad ह औ console क ह .य क
ह console क य क क क ह
हए

1. Through IDE (Integrated Development Environment)


2. Through Console

1. Through IDE

IDE क क क ह ह क क हऔ
कक ह. IDE क Eclipse, NetBeans क ह. ह
कक ह IDE Java Compiler क execute क ह. क ह क एक IDE
क .

[Link] Console

Console program क क steps ए ए ह.


1. Run cmd क य औ command prompt क य
[Link] prompt क क drive य install ह औ क bin
folder क locate क य

3. क य कक हए क क ह क क ह हय ह क ए javac
क क य औ enter क य क क image क ह

4. क ह ह .java extension क य
[Link]. क क prompt javac command क यऔ क
य क javac [Link] औ enter क य य क क errors ह
ए ह य यक ह क executable file ए
क ह.

5. java क क क यऔ ए क य java
MyProgram. क ह य
what is constructor in hindi?
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 in Hindi

क क ह:-

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 क


ह.

3:- copy constructors:- यह एक क क constructors ह.

constructors ह क क क pass क ह.

क क ह copy constructors, एक क values क class क


copy क .
values क copy क क एह क pass क ह ह क values ह copy क ह
औ ह क क constructors pass क ह ह & ampersand (address operator) क
य क कह ह.

syntax:-

class – name (class – name &)

Destructor in hindi

destructor क य constructor क create कय य क destroy ( )क क ए


कय ह.

destructor क class name क हह ह ह ह tilde (~) ह


destructor क declare क क ए ह destructor ह tilde (~) ह.

destructor क क क ह ह ह.

Access specifier
Access specifier एक keyword ह ह ह ह class क औ class variable ए function क
क ह|

औ Access specifier क nature क base Access क क ह|


Access specifier use न : Access
specifier In Java In Hindi

public
Private
Protected
Default

यह Default keyword क ह क ह ह ह|

ह क class , variable , औ function क क Access specifier use ह क ह ह


Default Access specifier automatic क क ह|

ए ह Access specifier क effect क एक example क ह|

ए ए क य यह ह ह class A , class B ए class C |

class A ए class B एक ह क क हय कह क ह क एक ह य क हऔ
C ह एक क हय य ह|

ह यह assume क ह क class ह, ह एक क Access specifier क


declare कय य ह| क एक क क य, क कक य ,…

… क क य औ क क य य ह क ह क क
specifier ह य ह ह य |

ह यह ह एक औ क Access specifier क scope ह|

Private Member:

Aक क ह class B ए क क हऔ ह Class C ए क
क ह|

क यह ह ह क Private Member क class क ह accessible ह ह|

औ क class क क क class क औ क क class Access क


क ह|

ह यह कह क ह क क scope class ह ह|

public Member :

class A क public ह class B औ Class C Access क क ह|

क public members क scope ह ह, कह Access कय क ह, ह


ह same क क class ह य क different क |

Protected Member :
A क Protected Member क class B ए क क ह class C Access ह क क ह|

य class C A क sub class ह ह class A क Protected Member क Access क क ह

Default Member :

ह क क Access specifier declare ह क ह ह यह Default Access


specifier क ह|

औ यह ह ए A क Default क क class B ए क क ह|

class C Access ह क क ह| यह ह यह कह क ह क Default Member क


क क ह ह |Access specifier In Java In Hindi|

Quick Q&A:

What is the difference between access specifier and access modifier?/ access specifier औ access
modifier difference ह ह?

access specifier औ access modifier ह same ह औ access modifier क access specifier


क official name कह क ह |

यह एक ह ह औ क public private, protected औ default specifier ह| ए


क क क क confusion य|

What is the default access specifier?/ Default access specifier ह ह?

ह क ए , औ क क access specifier ह ह ह by
Default Default access specifier work क ह|

औ यह Default access specifier ह package private specifier ह ह|

कह क कह क variable य method क एक ह package same


package access क क ह|

Are access modifiers necessary?/ access specifier क use क ह?

ह | program क member variable औ method क accessibility क control क क ए access


specifier ह ह|

क private ह हए, ह member variable औ


method क ह क क ह|

What is the purpose of abstract class?/ How do we use an abstract class?/ Abstract class ह ह?
औ Abstract class क purpose ह ह?

Abstract class ह ह ह एक य एक क Abstract method ह ह| class non -


Abstract method ह क ह|
Abstract method ह method ह ह method definition ह ह क क
implementation ह ह ह|

औ क subclass Abstract class क inherit क ह ह implement क ह


ह |

Abstract class क object ए ह क क ह| ए क Abstract औ non -Abstract


क access क क ए क subclass inherit कय ह|

क interface क method क define कय हऔ implement


ह कय ह|

औ क class क क ह ह ह क
क ह|

एक एक Abstract class क inherit क क ह| क एक class क interface क


implement क क ह|

What are the 8 access modifiers in Java? Java क access specifier क क ह ह?

Java access specifier न :

public.
private.
protected.
default.
final.
synchronized.
abstract.
native.

What are Java keywords? Java keywords ह ह?

क keywords ह ह 50 reserved terms ह ह|

औ Java क कक एक definition औ function ह ह|

औ क यह keywords reserved keywords ह ह ए क ए क ए


य क ह use ह क क ह|

यह program elements ह ह classes , variables , methods , objects , etc |

Can a constructor be private? एक constructor ह क ह?

Java constructor क य ह object creation क क क एक ह|

यह एक instance constructor ह ह क य क static ह ह


classes |
क constructor क कय ह क object क ह ए
क क ह declare कय य ह|

Constructor class क ह क object क ए ह क ए |

What is the main () in Java? java क main method क य?

क क ह, यह main method ह method ह ह


ह|

यह method क क क क क ए entry point ह ह|

यह main method methods क call execute क कक क ह|

औ main method क क क class क ह|

What is data type in Java? java क क क data types ह ह?

क ह क ह, क ह:

Primitive :

byte, short, int, long, float, double, boolean, and char. Non-primitive data types – such as

Non -primitives :

String , Arrays and Classes

What is the smallest type in Java? क data type क ह ह?

java क short data type ह ह ह| यह क 2 byte क ह ह (16


bits)|

Is void a return type in Java? void एक return type ह ह java क ?

य क method क void declare कय ह क यह ह क ह method


क value return ह क |

methods return statement क क ह ह ह, यह क ह, क


ह ह|
Static Keyword in Java in
Hindi
Java , static keyword क य memory management क य कय ह. क
य variables, methods, blocks औ nested classes क कय क ह.

keyword क य क class क variable य method क share क क ए कय ह.


Static member क create क क एह क static क क declare क ह .

class क member ‘static’ क क declare ह ह, class क objects क create क


ह औ क object reference क access कय क ह.

, static keyword एक non-access modifier ह औ क ए य कय


क ह:-

 Block

 Variable

 Method

 Class

Static Block

Static block क य static variables क initialize क क ए कय ह. यह block execute ह


ह class load ह ह. एक class क static blocks ह क ह, य blocks
execute ह ह program य ह ह.

example:- क क ह य य ह:-

class A2{

static{[Link]("static block is invoked");}

public static void main(String args[]){

[Link]("Hello world");

}
:-
static block is invoked
Hello world

Java - Comments in Hind

क क क एऔ औ क य क ए Java programming Comments


क य कय ह Alternative code क test क य क क क ए क
य कय ह

एक program , comments क क क कऔ य क य क क
कय क औ क य क हऔ क हऔ
क ह क क क य क क य क क य ह

comments statements ह compiler औ interpreter execute ह कय ह


य क य variable, , य क क क क य क क क
ए कय क ह क य यक ए क क hide क क ए कय
क ह

3 क क Comments ह ह

Types of Java Comments

 Single Line Comment

 Multi Line Comment

 Documentation Comment

Java Single Line Comment

Single line comment क य क एक line comment क क ए कय ह

Syntax:

//This is single line comment

Multi Line Comment


Multi line comment क य क क multiple lines comment क क ए कय ह

Syntax:

/*

This

is

multi line

comment

*/

Documentation Comment

Documentation comment क ए documentation comment क य कय ह


Documentation API क ए, क javadoc क य क क क ह

Syntax:

/**

This

is

documentation

comment

*/

Data types in Java in Hindi


]

Java Data Types in Hindi – ?

statically-typed ह क ह क variables क य क ह declare


क ह . strongly typed language ह क data type ह ह define ह ह.

Data Type - क क size औ value क specify क ह variable कय क


ह. java क क data types ह ह:-
1. Primitive Data Type

2. Non-primitive Data Type

Primitive Data Type

java 8 क क primitive data types ह ह, क ह:-

1:- Boolean – य क क possible values ह ह:- true य false. क य क


true/false condition क ए कय ह. क default false ह ह. य क
boolean क क declare कय ह.

:-
boolean isCold = true;
boolean isFoodTasty = false;

[Link](isCold); // क true ए .
[Link](isFoodTasty); // क false ए .

2:- Byte – -128 127 क whole numbers क क क ह. क य int क


कय क ह. memory क ह ह. क य int क कय ह
ह ह ह क क -128 127 क ह.

:- byte x =30, byte y = -50

3:- Short – -32768 32767 क whole numbers क क क ह. क default


value 0 ह ह. byte data क ह ह ह short क य memory क save क क एक क
ह.

:- short a = 10000, short b = -5000

4:- Int – int क -2147483648 (-231) 2147483647 (231-1) क ह ह. क default


ह ह. int क य कय ह.

example – int y = 100000, int z = -200000

5:- Long – data type क 9223372036854775808 (-263) 9223372036854775807 (263-1 ) क


ह ह. क य कय ह int value क ह क ह. ह
हए क क value क L end क ह ह.

example:- long myNumber = 15000000000L

6:- Float – यह 3.4e−038 3.4e+038 क क fractional number क क क ह. यह


यह ह क ह value क f end क ह ह. क default 0.0f ह ह.

:- float myNumber = 5.75f;


7:- Double – 1.7e−308 1.7e+308 क क fractional number क क क ह.
यह ह क ह value क d क ह ह. क 0.0d
ह ह

ex:- double myNumber = 19.99d

8:- Char– char data type क य एक single character क क क ए कय ह.


character क ह single quote क ह हए. क ‘\u0000 औ
क ‘\uffff’ ह ह.

ex:- char myCharacter = ‘B’

Non primitive Data type in Hindi

non primitive क reference types कह ह क object क refer क ह. य


क कह ह:-

String:- string क य characters क एक (sequence) क क क ए कय ह. क


value क double quote क ह.

ex:- String MyName = “yugal”

Class – user क define कय य prototype ह objects य ह. methods औ


variables ह ह.

कह , “एक objects क एक हह ह एक properties ह ह. यह एक


blueprint ह ह objects क create कय ह. यह एक logical entity ह. यह physical ह ह
क .”

:- Class औ object ह ह?

Object:- यह class क instance ह ह. औ यह real world क entity क क ह.

Interface – क ह ह interface methods औ variable ह ह. declare क य


abstract ह ह.

कह ,“ Interface एक reference type ह हऔ क abstract methods


औ static constants ह ह. क य abstraction औ inheritance क क क ए कय
ह.”

:- interface ह?

array:- array एक data type एक collection ह ह.


java variables in hindi

Java Variables ?

ए एक ह क ह ह| ए एक क क क क ह क
क कक ह| ए एक temperory क ह ह|

ए एक य क ह ह क ह कक क ह| ए
ह क क क हऔ य क क ह|

क क क java variable kya hai, types of variable in java, static variable


in java, instance variable in java, local variable in java, what is variable in java in hindi

Variable क ह (vari + able) | vari क ह य औ able क ह


य ह |य क variable क ह क य ह|

ह क क य क हय क ह ह य क य
य क क ए क ह ह यह values क क ह क ह क String, integer,
character, boolean, float, etc.
ह ए क एक क assign कय ह| य Data Type ह ह?
ए क ए - क क क क क ह, य कह
ए क क क ह क क क क |

क :

 Integer – …..-3, -2, -1, 0, 1, 2, 3……..

 Float – ए (1.2, 34.2,…)

 String – क य sentence (Amit, rahul, vishal, mukesh….)

 Boolean – true or false

 Character – क (a,b,c,x,y,z…..)

Java Variables declare न न (Declaration Rule of variable in java) :

ह ह variables क क कक य ह ह क
क क हए, क क क error क क
ह:

 ए क क ह ह हए ए क ह
(a,b,A,B,c…) य underscore ( _ ) ह ह हए|

 ए क क क (@,#,₹,&,*,etc) क य ह कय हए|

 ए क क short औ हए क क एक
क purpose क ए क ह|

 ए क क ह ह ए क variable क क ह
क हए|”name” औ “Name” variable ह|

 ए क क ह कक क क क
ए क क ह | क ह a = 10; ह ह int a = 10;
क ह|

 ए क क ह ह हए ह ह underscore क य क क
ह| क int number = 10; क int num ber =10; ह क ह

 Reserved keywords क use ए क क ह क हए| क int float = 10;


य float if = 2; क यह float औ if ह java reserved keywords ह|

Variable declare औ initialize (How to declare a variable in java) :

 Variable Declaration : ए क क क एह क औ ह
| ए क nature औ क ह|
Syntax : data_type variable_name;

Ex : int count;

यह count ए क ह औ int क ह, य क ए क integer


क क क ह|

 Variable Initialization : ए क initialize क क ह क क |


क य क क य क initialize क ह ह क
error ह instance ए औ static ए क initialize क ह ह
क assign ह क ह क ह|

Syntax : variable_name = value;

count = 10;

य int count = 10; (य variable क declare ह कय ह )

variables क क (Types of variable in java with example) :

न :

1) Local Variable

2) Instance Variable

3) Static Variable

(1) Local Variable :

क य क ह method, constructor य block क declare कय ह| य variables


method, constructor य block access कए क ह, य declare कए ए ह ह| क
ए क initialize क ह ह ह क Error ह|

public void printMessage(){

String message = "Hello World" // local variable message

[Link](message); // print the value of message

(2) Instance Variable :

ए क कए ह क क ह | क ए
कय क ह| ए क ह Object क ए ए ह हऔ ह क ए
- ह क ह|

public class Car{


String make; // instance variable make

String model; // instance variable model

int year; instance variable year

public void displayCarInfo(){

[Link]("Make: "+make);

[Link]("Model: "+model);

[Link]("Year: "+year);

(3) Static Variable :

Static Variable class क ह कए ह क क ए ह कय


क ह| यह Variable कह क ए ह ह| Static य क क
access कय क ह|

public class Example{

Static int counter = 0; // Static variable counter

public Example(){

counter++;

public static void main(String args[]){

Example obj1 = new Example();

Example obj2 = new Example();

Example obj3 = new Example();

[Link]("Number of objects created: "+counter); // print the value of static variable


counter
}

operators In Java In Hindi


Java operator variable क manipulate क क ए provide क ह| operator क
क कय क क य ह

Operators In Java In Hindi

 Debugging In Hindi

Types Of Java Operator In Hindi

 Arithmetic Operator

 Relational Operator

 Bitwise Operator
 Logical Operator

 Assignment Operator

ए एक एक क क Java operator क ह ..!!

Arithmetic Operator In Hindi

 Arithmetic operator क य mathematical operations, , ,


क क ए कय ह

 यह Mathemetical Expression क ए Use ह ह क य ह कय ह कह


Algebra क य क ह| कaक 10 ह औ b क 20 ह ,

Operator Description Example

(+) 2 operand क “+” perform क a + b = 30

(-) 2 operand क “-” perform क a – b = 10

(*) 2 operand क “*” perform क a * b = 200

(/) 2 operand क “/” perform क b/a = 2

(%) 2 operand क “%” perform क b%a = 0

(++) एक (increment) b++ = 21

(–) एक (decrement) a– = 9

Arithmetic Operator In Hindi

Relational Operator In Hindi

Relational operator य क क क क क क एय ह ह,
expression य कए य operator ह य क ह य ह.

Operator Description Example


(==) Equal to a==b is not true

(!=) Not Equal to a!=b is true

(>) Greater than a>b is not true

(<) less than a<b is true

(<=) Greater than Equal to <= b is true

(>=) Less than Equal to a>=b is not true

Relational Operator In Hindi

Bitwise Operator In Hindi

यह Bit work क ह Bit By Bit perform कय ह|

कaक 60 ह औ b क 13 ह ,

a = 0011 1100

b = 0000 1101

Operator Value Operation

a&b 0000 1100 and

a|b 0011 1101 or

a^b 0011 0001 xor

~a 1100 0011 compliment

Bitwise Operator In Hindi

Logical Operator In Hindi


Logical operator क binary variable क Use कय ह. क Use एक condition क
क क क ए conditional statements औ loops क ए कय ह

क ह :- कaक True ह औ b क False ह ,

Operator Description Example

(&&) Logical and (a&&b) is false

(||) Logical or (a||b) is true

(!) Logical not !(a&&b) is true

Logical Operator In Hindi

Assignment Operator In Hindi

Assignment operator क Use variable values क क क ए कय ह

Ex:- int age;

age = 70;

Assignment operator औ क variable क ह औ क क क ह, यह 70


Operator क य क क variable क Age कय य ह

Assignment operator value क left side क operand ह|

कC ए ह , औ variable A क 10 ह औ variable b क 20 ह ,

c=a+b

c =10 +20

c= 30
control statements(structures)
in hindi
, क execution क flow क य क क ए य structures य
कय ह control statements(structures) कह ह.

control statements क कह ह:-


1:-conditional statements
2:-loop statements

1:-conditional statements:-

य क कह ह.

(a):-if statement:-

if statement एक control statement ह क य एक क क test क क ए कय


ह. क क एक execute ह ह क ह ह.
syntax-
if(condition)
{
statements
}

Fig:+if

(b):–if-else statements:-
क क क test क क ए if-else statement क य कय ह. य क ह
if statement क execute कय ह क ह else statement क execute कय
ह.
syntax-
if(condition)
{
statement
}
else
{
statement
}

fig:-if else flow chart

(c):- switch statements:-

switch statement एक multi-way branch ह.


यह statement एक selection क एक क execution क ए paths क
क ह.
यह if-else क ए क क कयक ह.
syntax:-
switch(variable)
{
case constant 1;
statements(s);
break:
case constant 2;
statement(s);
break;
case constant 3;
statement(s);
break;
———–
default
statement(s);
}

Fig:-switch statement flowchart

(2):-Loop statements( ):-

loops क ह क एक य क एक execute क क ह
क क condition क ह क य .

loops क कह ह:-
1:-while loop
2:-do-while loop
3:-for loop

1:-while loop:-

while loop एक entry-controlled ह. क execute ह ह ह क क


एक condition (true) ह ह ह. यह ह condition क क हऔ क
execute क ह.
syntax:-
while(condition)
{
statement1;
statement2;
————-
}
Fig:-while loop
flowchart

2:-do-while loop:-

यह loop एक exit-controlled ह. यह while क हह ह यह ह क execute


क ह condition क क ह.

यह loop यह क ह क क क क एक execute कय य ह.
syntax:-
do
{
Statement1;
Statement2;
————–
}
While (condition);

Fig:-while loop flowchart

3:- For loop:-

यह एक entry controlled ह. क execute ह ह क क condition ह ह


ह. यह loop क initialization , boolean increment/decrement
क ह ह.

syntax:-
for(initial condition, test condition; incrementor or decrementor)
{
statement1;
statement2;
}
Fig:-for loop flowchart

:- क क औ ह ह:-
1:- Break statement
2:- Continue statement

1:-Break statement:-

क य switch क (sequence) क क क ए कय
ह क loop क exit क क ए कय ह.
syntax:- break;

2:-continue statement:-

continue क य कय ह ह loop क iteration क run क


ह ह iteration क ए क क skip क ह ह.
syntax:- continue;

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:

int[ ] empID = new int [10];

0 1 2 3 4 5 6 7 8 9

क variable क access क क ए square brackets [] क क index position क ह


क क ह array क ह|

1 [Link](empID[0]);

2 [Link](empID[1]);

2. Multi-dimensional arrays (or 2D, 3D….nD arrays)

2D arrays क ह subscript [][] क ह, क ह 3D arrays क ह


subscript [][] [] क ह| values क row औ column क index positions क
store कय ह|

Example:

int[ ][ ] marks = new int [3][5];

यह [3][5] क ह 3 rows औ 5 columns

[0][0] [0][1] [0][2] [0][3] [0][4]

[1][0] [1][1] [1][2] [1][3] [1][4]

[2][0] [2][1] [2][2] [2][3] [2][4]

Declaration of Array variable

Array क declare क क ए ह data type क ह, क क [] औ क


reference variable क ह|
Syntax:

1 dataType[] arrayRefVar;

Example:

1 int[] empId;

2 int[][] marks;

Note: Array क declare क यक क size क ह हए compile time error


|

Creations of Arrays

Array क create क क ए new keyword क use कय ह|

Syntax:

1 arrayRefVar = new dataType[arraySize];

Example:

1 empId = new int[7];

2 marks = new int[3][5];

Note: Array क create क यह क size क हए compile time error


|

Initialization of values in Array

Array initialization क ह values क index position क store क ह|

Syntax:

1 arrayRefVar[index position] = value;

Example:

1 empId[0] = 101;

2 marks[0][0] = 57;

3 marks[0][1] = 87;

Array variable Declarations , Creations, Initialization in single line

ह Declarations, Creations, Initialization क एक एक ह line define क क ह, ह 2


क क क ह|

1. size न define direct values store |


Syntax 1:

1 dataType[] arrayRefVar = {value0, value1, ..., valuek};

Example:

1 int*+ empId = ,101,102,103,……,110-;

2. new keyword use size न define values store |

Syntax 2:

1 dataType[] arrayRefVar = new dataType[] {value0, value1, ..., valuek};

Example:

1 int*+ empId = new int*+ ,101,102,103,……,110-;

length variable in Array

Java क arrays क length क क ए length variable क use कय ह|

Program 1:

1 public class ArrayDemo {

3 public static void main(String[] args) {

4 int[] empId = new int[10];

5 int[] rollNo = new int[] {10,20,30};

6 [Link]("Size of Array empId is --> "+[Link]);

7 [Link]("Size of Array rollNo is --> "+[Link]);

8 }

9 }

OutPut:

1 Size of Array empId is --> 10

2 Size of Array rollNo is --> 3

length variable length() method

length variable क use, क arrays क length क क ए कय ह क program 1


य य ह|
length() method क use, क String क length क क ए कय ह|

Program 2:

1 public class ArrayDemo {

3 public static void main(String[] args) {

5 String name = "RajHindiMe";

6 int[] empId = new int[10];

7 int[] rollNo = new int[] { 10, 20, 30 };

8 [Link]("size of Array empId is --> " + [Link]);

9 [Link]("size of Array rollNo is --> " + [Link]);

10 [Link]("*******************************");

11 [Link]("Length of name String is --> " + [Link]());

12 }

13 }

OutPut:

1 size of Array empId is --> 10

2 size of Array rollNo is --> 3

3 *******************************

4 Length of name String is --> 10

Processing Arrays

क, Arrays data type औ size ह ह ह ह, ए arrays क process क क एह


क for loop foreach loop क use क ह|

Processing Arrays using for loop

Program 3:

1 public class ArrayDemo {

2
3 public static void main(String[] args) {

5 int[] empId = new int[] { 10, 20, 30 };

6 for (int i=0; i<[Link];i++) {

7 [Link](empId[i]);

8 }

9 }

10 }

OutPut:

1 10

2 20

3 30

Processing Arrays using foreach loop

Program 4:

1 public class ArrayDemo {

3 public static void main(String[] args) {

5 int[] empId = new int[] { 10, 20, 30 };

6 for (int i : empId) {

7 [Link](i);

8 }

9 }

10 }

OutPut:

1 10

2 20
3 30

Anonymous Array in Java

Java ह Arrays क declare कए ह, क method arguments क क क ह|

Array क क ह ह Anonymous Array कह ह |

क instant use ह य क array क क एक use क ह


ह Anonymous Array क use क ह|

Anonymous Array क method arguments क कय ह|

Program 5:

1 public class AnonymousArrayDemo {

3 public static void printArrayValues(int[] arr ) {

4 for (int i=0; i<[Link];i++) {

5 [Link](arr[i]);

6 }

7 }

9 public static void main(String[] args) {

10

11 printArrayValues(new int[] { 10, 20, 30 });

12 }

13 }

OutPut:

1 10

2 20

3 30

ArrayIndexOutOfBoundsException

य ह क array क index position कयक ह array avaliable ह ह,


JVM ह execution क ArrayIndexOutOfBoundsException show क |
Program 6:

1 public class ArrayDemo {

3 public static void main(String[] args) {

5 int[] empId = new int[] { 10, 20, 30 };

6 for (int i=0; i<=[Link];i++) {

7 [Link](empId[i]);

8 }

9 }

10 }

OutPut:

1 10

2 20

3 30

4 Exception in thread "main" [Link]: Index 3 out of bounds for length 3

5 at [Link]([Link])

You might also like