0% found this document useful (0 votes)
10 views177 pages

Java Starting Notes

The document provides an overview of Java programming, detailing the types of applications that can be created, the classification of programming languages, and the features of Java. It explains the components of the Java Development Kit (JDK), the structure of Java programs, and the differences between various types of variables and data types. Additionally, it covers operators, tokens, and conventions in Java programming, along with examples of code and commands.

Uploaded by

Patil Mangesh
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)
10 views177 pages

Java Starting Notes

The document provides an overview of Java programming, detailing the types of applications that can be created, the classification of programming languages, and the features of Java. It explains the components of the Java Development Kit (JDK), the structure of Java programs, and the differences between various types of variables and data types. Additionally, it covers operators, tokens, and conventions in Java programming, along with examples of code and commands.

Uploaded by

Patil Mangesh
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

Page No

 JAVA NOTES 
Date

SECTION-NO:-1

With the help of java we can create four type of application

1. Standalone application

2. Mobile application

3. Web application

4. Baseness application
The language is a medium which is use to communicate with person

 PROGRAMING LANGUAGE :-

Programing language is a medium which is use to communication with the machine we have

three types of programing language

1. Low level

2. Middle level

3. High level

1) LOW LEVEL LANGUAGE :-

The language which is understandable & executable by machine

Example:- binary language

In binary language there are two representation 0,1

2) MIDDLE LEVEL LANGUAGE :-

In middle level language are sum pre-defined word which is known as mnemonics

Example:- ADD which use for addition

Move :- This word is use for moving the data from one place to another place

This words (mnemonics ) are not understandable by machine we have to use a software

called as assembler this assembler will convert middle level language in to low level language so that

machine can understand

3) HIGH LEVEL LANGUAGE :-

The language which is readable execution & understandable by programmer hence it is called

as high level language

Example: - java, c, c++.

This high level language is not understandable by machine so we will translate the high level

language in to binary language with the help of software compiler so that machine can easy to understand
Page No
 JAVA NOTES 
Date

 FEACHURS OF JAVA :-

1. Java is a high level programing language

2. Java is an object oriented language

3. Java provides high security

4. Java is easy to understand

5. Java sport packages

6. Java is platform in dependent language


 JDK & COMPONANT OF JDK :-

For a programmer to develop a software has to basic requirement

Java compiler

JRE (java run time environment)

1. JAVA COMPILER :-

Java compiler will check your program in top bottom order

2. JRE (JAVA RUN TIME ENVIREMENT) :-

JRE provide you an environment which is use to successfully execute a java program

JDK is a package which consist of development such as compiler JRE etc.

JRE consist of two important component JVM and Java library

 JVM (JAVA VIRTUAL MACHINE) :-

JRM is a one vino is responsible for converting byte code instruction into machine and

Standebal language with the help of interpreter and just in time [JIT] compiler
Page No
 JAVA NOTES 
Date

 SOURCE CODE :-

The code which is created by the programmer is known as source code

 BYTE CODE :-

The code which is generated by the compiler is known as byte code

 FLOW OF JAVA PROGRAM :-

 PLATFORM DEPENDENT :-

The code written on one platform & can be executable on some platform is known as platform

dependent

Example :- c language
Page No
 JAVA NOTES 
Date

Question Why java is platform independent?

The code written on a one platform of can be executable on any platform is called as platform

Independent

Example :- java

Note:-

Java is a platform independent language but it is totally dependent on JDK

 IMPORTANT COMMAND FROM COMMAND PROMT :-

 drive Name :-

This command is use to move from one drive to another drive

 Dir. :-
This command is used to list all the files & directories from current directory

 Mkdir folder Name :-


This command is use to create new directory with this command we have to pass directory name

 cd.:-
This command is used to come outside the current folder

cd folder name :-

This command is used to enter in side for given folder given directory.

 cis :-

This command is used to clear the screen

java c :-
Page No
 JAVA NOTES 
Date

This command is used to compile the java source code with this command use have to pass java

source file name with java extension

 java name:-

This command is used to execute java class file with this command name of file passed without

Extension.

 MEMBERS OF A CLASS :-

In class block we can create first.

1. Methods

2. Variables

3. Initialization
1. METHOD :-

Methods is a block of instructions which is use to perform a task

2. VARIABLES:-

Variable is a container which is used to store the data

3. INITIALIZER :-

Its use to execute the startup instruction of program

 BASIC STRUCTURE OF JAVA PROGRAM :-

Program :-

class sub

public static void main(String[] args)

[Link]("100-50");

}
Page No
 JAVA NOTES 
Date

Out Put:-

Java instruction is always return.

Avery class must have a name which is known as class name

Avery class have a block which known as class block

 SYNTAX OF MAIN METHOD:-

class sub

public static void main(String[] args)

A class in java can be executed only if main method is created class

We can create a class without main method it is compiler time successful and dot class file will

Generated but we cannot execute that class.

 DEFFERENCE BITWEEN PRINT AND PRINT L N :-

Print l n :-

It is use to print the value it will not to the next line

If we do not pass any value it will not print any think but it will move the cursor on the next line
Page No
 JAVA NOTES 
Date

Program:-

class numberdisplay

public static void main(String[] args)

[Link](10);

[Link](20);

[Link](30);

Output:-

Print :-

It is use to print the value & move the cursor on same line

If we do not pass any value it will not move the cursor on the same line but it will give you compile time

error

Program :-

class emty

{s

public static void main(String[] args)

[Link]();

[Link]();
Page No
 JAVA NOTES 
Date

[Link]();

output :-

 TOKENS :-

Token is the smallest unit of java

Token are classified in to four type

1) Keyword

2) Identifier

3) Separator

4) Literals

1) KEYWORD :-

Keyword are predefined word of java

Keyword are reserve word of java

We can use this keyword but we can modify

Keyword are allows written in lower case

There are 50 plus keyword in java

Example:- class , public, void, static etc.

2) IDENTIFIER :-

Identifier is a name given to the component of java by programmer

Example :- class name , method name , variable name ,


Page No
 JAVA NOTES 
Date

 RULES OF IDENTIFIER :-

 Identifier should not start with the number but we can use the number in between & in the end “alpha

Numeric”

 Any special character is not allowed in identifier $, &, _ , expected

 Character space is not allowed in identifier


 We cannot use any keyword as identifier

Note:-

If any of above rule is not followed we will get compile time error

 CONVENTIONS :-

The coding or industrial standards to be followed by programmer is known as conventions

Compiler doesn’t validate the convention there for if convention are not followed we don’t get

Compile time error but it is highly recommended to follow conventions

 CONVENTION FOR CLASS NAME :-

If it is single word that word should start upper case

If it is multi word each word we should start upper case

Example :- square root

 CONVENTION FOR METHOD OR VARIABLE :-

If it is a single word that word should be in lower case

Example :- sub , add ,

If it is a multi-word first word should be in lower case rest can should be in upper case

3) SEPARATOR :-

Separator is use to separate the set of instructions

Example: - {}, (), [],

4) LITERALS :-
Page No
 JAVA NOTES 
Date

The value or data use in a java program is known as literals

The literals are category’s in to two type

1. Primitive

2. Non-Primitive
1. PRIMITIVE :-

Single value or data use in a java program is known as primitive literal

Example :- Number , character , Boolean

A. NUMBER :-

Number is categorize in to two type

i. Integer

ii. Float
Example :- 20, 8, 9, 100

B. CHARACTER :-

Any think which is in close in a single code is known as character literal

The size of character is one

Example :- ‘5’ , ‘A’ , ‘@’

C. BOOLEAN :-

Boolean literal is use to write logical value

Example :- True , Foalse

Ex 1 Write a java program to print name, contact _No ,10th_percentage, Birth_date, gender, status, age .

Program:-

class studentinformation

public static void main(String[] args)


Page No
 JAVA NOTES 
Date

[Link]("Magesh Patil");

[Link]("7219040074");

[Link](51.48);

[Link]("4-07-1999");

[Link]('M');

[Link]("False");

[Link](23);

Output :-

 + OPERATOR :-

Addition

Concatenation (Marge)

1) CONCATENATION WITH BOOLEAN:-

class concatwithboolean

public static void main(String[] args)


Page No
 JAVA NOTES 
Date

[Link](true+false); //error

[Link](true + %); //error

[Link](true + 10); //error

[Link](true + 340); //error

[Link](true + "hallow word"); //rune the command print "true hallow word"

2) CONCATENATION WITH STRING :-

Program :-

class concatwithstring

public static void main(String[] args)

[Link](10+"hellow");

[Link](100 + "hellow");

[Link]("hellow" + 't');

[Link](false + "hellow");

[Link]("hellow" + "java");

Output :-
Page No
 JAVA NOTES 
Date

3) CONCATENATION WITH CHARACTER:-

Program :-

class concatwithchar

public static void main(String[] args)

//[Link](9+ true); //error//

[Link]('a' + "hellow");

[Link]('a' + 10);

[Link]('b' + 45.7);

[Link]('A' + 'A');

Output:-

4) CONCATENATION WITH NUMBER :-

Program:-

class concatwithnumber

public static void main(String[] args)

[Link](40 + "ok");
Page No
 JAVA NOTES 
Date

[Link](50 + 'A');

[Link](60 + 20);

[Link](70 + 10.5);

Output:-

2. NON PRIMITIVE:-

Non-primitive literal is a reference between or address of an object.

 DATA TYPE :-

Data type are used to create variable of specific type in java data types ate classified in to two type

1. Primitive

2. Non-primitive

1. PRIMITIVE DATA TYPE :-

The data type which is used to create a variable to store primitive value such as number , character,

Boolean , is known as primitive data type

Note:-

All the primitive data type is keyword in java


Page No
 JAVA NOTES 
Date

 PRIMITIVE DATA TYPE WITH SIZE :-

Sr. No Primitive literal Primitive data type size

1. Integer Byte 1 byte

Short 2 byte

Int 4 byte

Long 8 byte

2. Float Float 4 byte

Double 8 byte

3. Character Char 2 byte

4. Boolean Boolean 1 bit

2. NON-PRIMITIVE DATA TYPE :-

The data type which is used to create non-primitive variable is known as non-primitive data type

Example :- string

Note:-

Avery class name is java is non-primitive data type

 VARIABLE :-

Variable is container or a block of memory which is used to store the value

Syntax: - Data type Name = Value

Int a = 10

Keyword identifier literal


There are two types in variable

1. Primitive variable

A. Non-Primitive variable
Page No
 JAVA NOTES 
Date

1. PRIMITIVE VARIABLE :-

The variable which is used to store primitive value is known as primitive variable.

We can create a primitive variable with the help of primitive data type.

2. NON-PRIMITIVE VARIABLE :-

Non-primitive variable is used to store address or reference of an object

Example:- string

Program :-

class datatype

public static void main(String[] args)

String name = "patil mangesh";

long mobno = 7219040074l;

double percentage = 65.48;

String dob = "4-7-199";

char gender = 'm';

boolean status = false;

[Link](name);

[Link](mobno);

[Link](percentage);

[Link](dob);

[Link](gender);

[Link](status);

}
Page No
 JAVA NOTES 
Date

 SCOPE OF VARIABLE :-

The visibility or accessibility of variable is known as scope of variable

Based on scope of variable we can categorize variable in three type

1) Local

2) Static

3) Non-static

1) LOCAL VARIABLE :-

The variable declared in side method block or any other block is known as local variable (accept class)

 CHARACTARISTICS OF LOCAL VARIABLE :-

❶ We can’t use local variable without initialization

❷ If we try to use local variable without initialization then we will get compile time error

❸ The scope of local variable is nested inside the block where are it is created hence it can’t be use out
outside the block

 OPERATORS:-

Operators are pre-defined symbol which is use to perform specific task on even data the data given as
an input to the operator is known as operators

Basic on the No of operant operator are further classified in to their types

1. Unary

2. Binary

3. Ternary

1. UNARY OPERATOR:-
The operator which can accept only one operator is known as unary operator

Unary operators classified in to three types

A. Increment

B. Decrement

C. Type cast
Page No
 JAVA NOTES 
Date

2. BINARY OPERATOR:-

The operator which accept two operator is known as binary operator

Binary operator is further classified in three type


A. Arithmetic

B. Relational
C. Logical

3. TERNARY OPERATOR :-

The operator which accept the operator is known as ternary operator

A. Conditional operator

A. INCRIMENT OPERATOR :-
❶ Increment operator is a unary operator

❷ It takes only one operator at a time

❸ Increment operator is denoted by ‘++’

❹ Increment operator is classified in to two type


a. Pre increment operator (++a)
b. Post increment operator (a++)

a. PRE INCREMENT OPERATOE :-


The increment operator which prefix to the variable name is called as pre increment operator
Syntax:-

++ variable name

Example :- int a = 22

[Link] (++a);
Stapes to perform pre increment operator

❶ Create the value present inside the variable by 1 and update


❷ Use the update value present inside the variable

b. POST INCREMENT OPERATOR :-


Page No
 JAVA NOTES 
Date

The increment operator which is suffix to its variable name is known as post increment operator

Syntax:-

Variable name ++

Example :- int a = 22

System. out .println (a++); //22

[Link] (a) ; // 23

Steps to perform post increment operator

❶ Use the value present inside the variable by

❷ Increment the value present in side variable by one and update

Program :-
class incrementoperator
{
public static void main(String[] args)
{
int f = 56;
[Link](f++ + ++f -f + ++f);
}
}

Output :-

Program :-
class incrementoperator1
{
public static void main(String[] args)
{
int a = 10;
int b = 30;
[Link](a+b);
[Link](a++ + ++a + b -a );
[Link](++a + b++ + b++ - ++a);
}
}
Page No
 JAVA NOTES 
Date

Output :-

B. DECREMENT OPERATOR :-

Decrement operator is a unary operator

Decrement operator is denoted by ‘_ _’


Decrement operator is classified in to two types
a. Pre decrement operator

b. Post decrement operator

a. PRE DECREMENT OPERATOR :-

Syntax: - -- variable name

Example :- class

Public static void main (String[] args)

Int c = 99

[Link] (c);

[Link] (--c);

[Link] (c);

Steps to perform pre decrement operator


❶ Decrement the value present inside the variable by one and update the value

❷ Use the update value inside the variable


Page No
 JAVA NOTES 
Date

b. POST DECREMENT :-

The decrement operator which suffix to its variable name it’s called as a post decrement operator

Syntax :- variable --;


Example :- class
{
Public
{
Int c=99
[Link](c);
[Link](c--);
[Link](c);
}
}

Steps to perform post decrement operation


❶ Use the value present inside the variable by one

❷ Decrement the value present inside the variable by one and update

Program :-

class decrementoperator
{
public static void main(String[] args)
{
char g = 'A';
[Link](g + --g + g--);
[Link](g);
}
}

Output:-

C. TYPE CAST OPERATOR :-


Page No
 JAVA NOTES 
Date

It is a process of converting one data type in to un-other data type

Type casting is classified in to two type

1. Primary
2. Non-primary

1. PRIMARY :-

The process of converting one primary data type in to un-other primary data type

Primary type casting in classified in to two types

a. Winding

b. Narrowing

Short -char -int - long - float - double

a. WINDING :-

The process of converting smallest primary data type in two largest primary data type

It is implicit process

There is no data loss in winding


Program :-
class winding
{
public static void main(String[] args)
{
int f = 69;
long h = f;
[Link](f);
[Link](h);

}
}
Output:-
Page No
 JAVA NOTES 
Date

b. NAROWING :-

The process of converting larger range primary data type in to smaller reang of primitive data type is

known as narrowing
It can be don explicitly by the programmer using type cast operator

 TYPE CAST :-

1. Unary

The type cast operator is used to explicitly convert one data type in to un-other data type

Program :-
class narowing
{
public static void main(String[] args)
{
double d = 45.7;
int i = (int)d;
[Link](d);
[Link](i);

}
}
Output :-

2. BINARY OPERATOR:-

A. ARITHMETIC OPERATOR :-

It is binary operator

What needs two operator

+,-,/,%, *

Example :-
Page No
 JAVA NOTES 
Date

Program:-
class arithmaticoperator
{
public static void main(String[] args)
{
int a = 10;
int b = 5;
[Link](a+b);
[Link](a-b);
[Link](a/b);
[Link](a*b);
[Link](a%b);
}
}

Output:-

B. RELATIONAL OPERATOR :-

< , > , <= , >= , != , ==


Example:-
Program:-
class relationaloperator
{
public static void main(String[] args)
{
int a = 10;
int b = 5;
[Link](a<b);
[Link](a>b);
[Link](a<=b);
[Link](a>=b);
[Link](a!=b);
[Link](a==b);

}
}
Page No
 JAVA NOTES 
Date

Output:-

C. LOGICAL OPERATER:-

AND OR NOT

&& || !

a. AND (&&) OPERATER:-

1 2 RESULT
T T T

T F F

F T F
F F F

Example:-

Program:-
class andoperator
{
public static void main(String[] args)
{
[Link](true && true);
[Link](true && false);
[Link](false && true);
[Link](false && false);
}
}

Output:-
Page No
 JAVA NOTES 
Date

b. OR (||) OPERATOR:-
1 2 RESULT

T T T
F T T
T F T

F F F

Example:-

Program:-
class oroperator
{
public static void main(String[] args)
{
[Link](true || true);
[Link](true || false);
[Link](false || true);
[Link](false || false);
}
}
Output:-

c. NOT (!) OPERATOR:-


Page No
 JAVA NOTES 
Date

1 RESULT

T F

F T

Program:-
class notoperator
{
public static void main(String[] args)
{
[Link](!true);
[Link](!false);

}
}
Output:-

3. TERNARY OPERATOR :-
A. CONDITIONAL OPERATOR :-
Syntax:-

Condition? statement1: statement2;

 WORK FLOW :-

If the condition is true statement1 will get executed

If the condition is false statement2 will get executed


Example:-

Program:-
class conditionoperator
{
public static void main(String[] args) {
int num1 = 159;
Page No
 JAVA NOTES 
Date

int num2 = 79;


[Link](num1>num2?num1:num2);
}
}

Output:-

Question Write a java program to check whether the given character is alpha bate or not
Program:-

class alphabateornot
{
public static void main(String[] args)
{
char al = 'A';
String res = (al>='a' && al<='z')||(al>='A' && al<='Z')? "it is alphabate" : "it is not alphabate";
}
}

 METHOD :-
A method is a block of instructions which is use to perform a specific task

Method is used to transfer a data

Syntax:-

[access modifier ] [modifier] return type name ([formal argument])

Instruction;

A. ACCESS MODIFIER:-

Access modifier is use to change the accessibility of a member

Example:- public , privet, etc.


Page No
 JAVA NOTES 
Date

B. MODIFIER :-

It is use to change the behavior of a method

Example:- static, find , abstract etc.

C. METHOD SIGNATURE:-
Method signature contains name of method and formal argument

D. METHOD DECLERATION :-

Method declaration contains access modifier, modifier, return type and method signature

E. METHOD DEFINATION :-

Method definition counters method definition and method body

F. METHOD CALLS STATEMENT :-

The statement which is used to call un-other method is known as method call statement

Note:- A method will get executed only when it is called we can call a method using
method calls statement

 METHOD CALL STATEMENT FLOW :-


❶ The execution of caller method will be posed

❷ Control list transfer to the called method

❸ Execution of called method will beginning

❹ Hence the control will be call back to calling method

❺ Execution of caller method will resume

a. CALLING METHOD :-

The method which is trying to call another method is known as calling method or caller method

b. CALLED METHOD :-

The method which is called by the un-other method is known as called method
Page No
 JAVA NOTES 
Date

Diagram:-

Program:-
class methodcallstatement
{
public static void main(String[] args)
{
[Link]("main start");
anjali();
[Link]("main end");
}
public static void anjali()
{
[Link]("anjali like rahul");
rahul();
}
public static void rahul()
{
[Link]("rahul like tina");
tina();
}
public static void tina()
{
[Link]("dead");
}
}
Output:-
Page No
 JAVA NOTES 
Date

Note:-

A method can’t be create in another method

Calls can have any number of methods

G. MAIN METHOD :-
The execution of a program always start from main method

Syntax:-

Public static void main (String[]arng)

 PURPOSE OF MEAN METHOD :-

❶ Start the execution


❷ Control the flow of execution
❸ End of execution
Note :-

A method can be execution only when it is call we can call a method any number of
time there for it is said to be a code reusable

Main method is always called by JVM

 TYPE OF METHOD :-

Best on the number of argument method can be classified in to two type


1) No-argument

2) Parameterized

1) NO-ARGUMENT METHOD :-

A method which does not have formal argument is known as no argument

2) PARAMETERIZED METHOD :-
The method which has formal argument is known as parameterized method

A. FORMAL ARGUMENT :-
Page No
 JAVA NOTES 
Date

A variable which is declared in a method declaration is known as formal argument


B. ACTUAL ARGUMENT :-

The value passed in a method call statement is known as actual argument

 RULLS TO CALL PARAMETERIZED METHOD :-


The no of actual argument should be same as a number of formal argument

The type of actual argument should be same as a type of formal argument , if not compiler try’s to

perform implicit conversion

If implicit conversion is not possible we will get compile time error

 RETURN STATEMENT :-
❶Return is keyword
❷A method after execution return the data back to the caller with the help of return key word

❸It is control transfer statement

❹When return statement is executed the execution of current method will get term heated & control is

transfer back to the caller


❺The type specified return type should be same as the type of value passed in return statement
Program :-
class paramiter
{
public static void main(String[] args)
{
[Link]("start main");
add(10,30); //parameter statement
[Link]("end main");
}
public static void add(int a , int b) //parameter statement
{
[Link](a);
[Link](b);
int res = a+b;
[Link](a+b);
}
}
Output:-
Page No
 JAVA NOTES 
Date

 IMPORTANT POINT TO REMAMBER ABOUT METHOD :-

❶A class can have multiple method in any order


❷A method get executed only on invocation

❸A method can be called any number of times

❹A method can have either void or some other return type (return type mandatory)
❺Void method can have return statement

❻If a method has any other return type except void then there must be a return statement

❼A method can have only one return type


❽A method can logically have only one return statement

❾In side method the return statement should be the last execution instruction

❿The return type and return value must match

 DECISION MEKING STATEMENT :-


Decision making statement is used to skip the set of instruction

There are four type of decision making statement

Statement :-

1) If

2) If____Else
3) Else_____If ladder

4) Switch
1) IF STATEMENT:- Syntax:- If (condition)
{
task
}
Page No
 JAVA NOTES 
Date

 WORK FLOW :-

If condition is true if block will get executed

If condition is false if block will get skip and instruction which is return after f block will get execution
Program :-
class ifstetment
{
public static void main(String[] args)
{
int a = 10;
if (a<50)
{
[Link](a + "is low ");
}
[Link]("Hello World!");
}
}
Output”-

2) IF_______ELSE:-

SYNTAX:-

If (condition)
{ true/false
Task;
}
Else
{
Task;
}

 WORK FLOW:-

❶ If the condition is true if block will be executed of else block will get skipped
❷ if condition is false if block will be skipped it else block will get executed
Page No
 JAVA NOTES 
Date

Program:-
class ifelse
{
public static void main(String[] args)
{
int a = 10;
if (a<50)
{
[Link](a + "is smaller than 50");
}
else
{
[Link](a+ "is grater than50");
}
}
}
Output:-

3) ELSE IF___LADDER:-

Syntax:-
If (condition)
{ true/false
Task;
}
Else if (condition)
{ true/false
Task;
}
Else if (condition)
{ true/false
Task;
Else (condition)
{
Task;
}
Page No
 JAVA NOTES 
Date

 WORK FLOW:-

❶In else if __ladder we can check multiple condition

❷condition will start checking in top to bottom order which ever condition is true that block will get
other block will get skipped

❸if non-of the condition are true else block will get executed

4) SWITCH():-

Syntax:-
switch(value/variable)
{
Case value:
{
Task;
}
Case value :
{
Task;
}
Break;
Default:
{
}
}

 WORK FLOW:-

❶The value variable pass in switch gets compare with value pass in a case from top to bottom or

❷if any case is match that class block will get executed and the blocks below will also get executed
❸If no case is match default case will get executed after each case we can use break statement which is

Optional to stop the continuation


Note:- ❶for a switch we can’t pass long, float; double and boolean

❷for a case we can’t pass variable

 BREAK KEYWORD:-

❶Break keyword is a control transfer statement break can be used inside switch and loop
Page No
 JAVA NOTES 
Date

❷When the break statement executed the executed the execution of current block will be stop and control

is transferred outside the block

Program:-
class switchvowel
{
public static void main(String[] args)
{
char ch ='i';
switch (ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
{
[Link]("it is vowel");
}
break;
default:
{
[Link]("28 days");
}
}
}
}

Output:-

Program:-
class dasynmonth
{
public static void main(String[] args)
{
int a =1;
switch (a)
{
case 1:
Page No
 JAVA NOTES 
Date

case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
{
[Link]("31 days");
}
break;
case 2:
{
[Link]("28 days");
}
break;
case 4:
case 6:
case 9:
case 11:
{
[Link]("30 days");
}
break;
default:
{
[Link]("invalid input");
}
}
}
}

Output:-

 LOOP:-
Loops are used to perform the set of instruction repeatedly there are four of loop

1) While
2) Do while
Page No
 JAVA NOTES 
Date

3) For

4) For each

1) WHILE :-

Syntax:-

Initialization

While (condition)

{ true/false

Task;

Updation;

 WORK FLOW:-

❶First condition will get check if condition is true the control will go inside while loop and it will

perform task after task the value get updated and again it will go to check the condition if condition is

True same procedure will be repeated


❷if condition is false control will not inter inside while loop control will directly go outside the loop
Program:-
class whileloop
{
public static void main(String[] args)
{
int a=1;
while (a<=5)
{
[Link]("Hello World!");
a++;
}
}
}
Output:-
Page No
 JAVA NOTES 
Date

2) DO WHILE:-

SYNTAX:- Initialization
Do
{
Task;
Updation;
}
While (condition)
{ true/false
Task;
}

 WORK FLOW:-
❶First control will enter inside do block and perform the task after performing a task the value will get
Updation condition will get check if the condition is true control will again enter in a do block and same

procedure will get repeated until the condition is false

❷If the condition is false control will enter in do block to perform a task and update the value at least once

(even if the condition is false do while loop will execute)


Program:-
//write a java program to print the factor of 5//
class factor

{
public static void main(String[] args)

int a = 5;
int fact = 1;

while (a>=1)

fact = fact * a;

a--;

[Link]("factorial is :"+fact);

}
Page No
 JAVA NOTES 
Date

Output:-

//write a java program to print even number between 1 to 50//


class evenno
{
public static void main(String[] args)
{
for (int i=1; i<=50; i++ )
{
if (i%2 ==0)
{
[Link](i);
}
}
}
}
Page No
 JAVA NOTES 
Date

Program:-

//write a java program to find a last digit of number //


class lastno
{
public static void main(String[] args)
{
int num =6754;
int last = 0;
last=num%10;
[Link]("last digit is :"+last);
}
}

Output:-

Program:-
//write a java program to cut the last digit of number //
class cutlastno
{
public static void main(String[] args)
{
int num =6754;
int last=num/10;

[Link]("last digit no cut is :"+last);


}
}
Output:-
Page No
 JAVA NOTES 
Date

//write a program to print revers of a number //


class reversno
{
public static void main(String[] args)
{
int num = 6754;
int rev = 0;
int rem = 0;
while (num!=0)
{
rem = num%10;
rev = rev*10+rem;
num = num/10;
}
[Link]("revers no is :" +rev);
}
}
Output:-

Program:-
//write a java program to cheek whether the given number palindrome//
class palindrom
{
public static void main(String[] args)
{
int num = 1321;
int sum = num;
int rem = 0;
int rev = 0;
while (num!=0)
{
rem = num%10;
rev = (rev*10)+rem;
num = num/10;
}
if (sum==rev)
{
[Link]("no is palindrom : "+rev);
}
else
{
[Link]("no is not palindrom : "+rev);
Page No
 JAVA NOTES 
Date

}
}
}
Output:-

Program:-
class patternsymbol
{
public static void main(String[] args)
{
for (int i = 1; i<=4; i++)
{
for (int a = 1; a<=4; a++ )
{
[Link]('*');
}
[Link]();
}
}
}
Output:-

Program:-
class patte10101
{
public static void main(String[] args)
{
Page No
 JAVA NOTES 
Date

int k = 1;
for (int i = 1; i<=5; i++)
{
for (int a = 1; a<=5; a++ )
{
[Link](k);
if (k==1)
{
k--;
}
else
{

k++;
}
}
[Link]();
}
}
}
Output:-

Program:-
class patte12345
{
public static void main(String[] args)
{
int k = 1;
for (int i = 1; i<=5; i++)
{
for (int a = 1; a<=5; a++ )
{
[Link](k);
k++;
Page No
 JAVA NOTES 
Date

if (k>5)
{
k=1;
}
}
[Link]();
}
}
}
Output:-

Program:-
class pattern0000011111
{
public static void main(String[] args)
{

for (int i = 1; i<=5; i++)


{
for (int a = 1; a<=5; a++ )
{
if (i%2==0)
{
[Link]('1');
}
else
{
[Link]('0');
}
}

[Link]();
}
}
}
Page No
 JAVA NOTES 
Date

Program:-
class pattern123
{
public static void main(String[] args)
{

for (int i = 0; i<5; i++)


{
int k=1;
for (int a =0; a<5; a++ )
{
if (a%2==1)
{
[Link]("*");
}
else
{
[Link](k);
k++;
}
}
[Link]();
}
}
}

Output:-

Program:-

class pattern1s0s1
{
public static void main(String[] args)
{
for (int i = 0; i<5; i++)
Page No
 JAVA NOTES 
Date

{
for (int a =0; a<5; a++ )
{
if (a%2==1)
{
[Link]("*");
}
else if (a==2)
{
[Link](0);
}
else
{
[Link](1);

}
}
[Link]();
}
}
}
Output:-

Program:-

class patternABCDE
{
public static void main(String[] args)
{

for (int i = 1; i<=5; i++)


{
for (int a = 65; a<70; a++ )
{
[Link]((char)a);
}

[Link]();
Page No
 JAVA NOTES 
Date

}
}
}
Output:

Program:-
class patterntrangle
{
public static void main(String[] args)
{

for (int i = 0; i<=5; ++i)


{
for (int a = 1; a<=i; ++a)
{
[Link]('*');
}
[Link]();
}
}
}
Output:-

 STATIC AND STACK MEMBAR :-


1) Static method
Page No
 JAVA NOTES 
Date

2) Static variable

3) Static initializer

1) STATIC METHOD :-
❶ It is modifier

❷ Static is a keyword
❸ Any memorial of class which is prefix with a static modifier then it is known as static member of class

 JRM (JAVA RUN TIME MEMORY ):-

To execute a java program a portion of memory in ram is allocated for VRE in that portion of memory we
have deferent rang of memory

Hence they are classified as following


1. Method Area

2. Class Static Area (Static Pull)

3. Stack Area

4. Heap Area

1. METHOD AREA:-

All the method blacks will be stored in method area with method name instruction and address
Page No
 JAVA NOTES 
Date

2. CLASS STATIC AREA:-

For average class there is a dedicated block of memory is created in class static area

The static members of a class will be allocated inside a memory created for class

3. STACK AREA:-

Stack area is use for an execution of instruction


For average method that is under execution a block of memory gets created in stack area which is known

as a fream
Once the execution of a method dis completed the fream will get remove

4. HIPE AREA:-

In a heap area a block of memory is created for the instance of a class (object)
Avery block of memory created with the help of reference

All the non-static members of a class will be allocated inside the block of memory

There for we can access the non-static members with the help of reference

class treasing
{
public static void main(String[] args)
{
[Link]("Hello World!");
}
}
Trashing:
Page No
 JAVA NOTES 
Date

Program:-

class treasingSubmethod
{
public static void main(String[] args)
{
[Link]("main start");
sub ();
[Link]("main end");
}
public static void sub()
{
int a = 50;
int b = 20;
int res = a-b;
[Link](res);
}
}
Tracing:-

 STATIC METHOD:-
A method prefix with a static modifier is known as static method

 CHARACTERSTICS STATIC METHOD:-

Static method block will get stored in method area with name, instruction and address
The address of static method will get stored in class static area

We can use static method with the help of class name


Page No
 JAVA NOTES 
Date

A static method of the class can be used in any other class with the help of class name

Trashing :-

2) STATIC VERIABLE:-

Program:-

class staticVeriable
{
static int a;
public static void main(String[] args)
{
[Link]("main start");
[Link](a);
[Link]("main end");
}
}
Trashing:-
Page No
 JAVA NOTES 
Date

Variable declared in a class block and prefix with a static modifier is known as static variable

 CHARACTERISTIC OF STATIC VARIABLE :-

It is member of class it will be assign with a default value


Memory will be allocated for static variable in class static area

It is global in nature it can be used within the class as well as in different class
We can use a class name to print the value of static variable

We can access the static variable in different class using class name
If the local variable name and static variable name is same then priority will be given to the local variable

To differentiate a static variable and local variable can use a class name

Q Write a difference between static and local variable

Program:-

class add
{
static boolean b;
static int d;
public static void main(String[] args)
{
[Link]("main start");
int g = [Link]();
[Link](demo1.a);
test();
[Link](g);
[Link](b);
sub();
[Link]("main end");
}
public static void sub()
{
[Link]("sub start");
int a = 20;
int b = 10;
int sub = a-b-d;
[Link](sub);
[Link](b);
[Link]("sub end");
Page No
 JAVA NOTES 
Date

}
public static void test()
{
[Link]("test start");
[Link](demo1.a);
int c=34;
[Link](add.d);
[Link](c);
[Link]("test end");
}
}

Program:-

class demo1
{
static int a;
public static void main(String[] args)
{
add();
[Link]("Hello from main method");

}
public static int add()
{
[Link](a);
int res = 40+20;
[Link](res);
return res;
}
}
Trashing :-
Page No
 JAVA NOTES 
Date

3) STATIC INITIALIZATION :-

Program:-

class staticinitialization
{
static int f = 34;
public static void main(String[] args)
{
[Link]("main start");
add();
[Link]("main start");
}
static
{
[Link]("Hello from multi line static initializer");
}
public static void add()
{
[Link](20+30);
}
}
Trashing:-

Static initializer is use to the startup instruction of program as static initializer gets execution before the

actual execution

We have two types of initializer

1) Single line static initializer :-


Page No
 JAVA NOTES 
Date

Syntax:-

Static data type name = value

2) Multi line static initializer :-

Syntax:-
Static

 CHARACTERISTICS STATIC INITIALIZER:-


Static initializer gets execution implicitly during the loading process of class

A class can have more than one static initializer


Static initializers gets executed in top to bottom order

 CLASS LOADING PROCESS:-

A block is created for a class in the static pull it can be access with the help of class name

All the method definition will get loaded in method area and the method is static the reference will get
stored in class static area
It class has any static variable they will get loaded in class static area with default value

If class has any static initializer they will get executed in top to bottom order

The loading process of class is completed now JVM call the main method of initial loaded class

Note:-

JVM will only call the main method of initial loaded class

 OBJECT:-

Any substance which has real world existence is known as real world object
Avery object will have attributes and behavior

 OBJECT IN JAVA:-
Page No
 JAVA NOTES 
Date

According to object oriented programing object is a block of memory created in heap area during run time

it represents the real world object

A real world object consist of attribute and bihever

Attributes are represented with the help of non-static variable


Bihever is represented with the help of non-static method

 CLASS:-

According to real world situation before costarring an object blue print of an object must be design it
It provides the specification of real world object

Similarly in object oriented programing before creating an object the blue print of an object must be design
which provides the specification of real world object

This is done with the help of class


It is a non-primitive data type which represent the real world object

 STEPS TO CREAT A OBJECT:-

Step 1 Create a class or use the executing class

Step 2 Instunliantion
Syntax:-
New class name()

constructer

 NEW KEYWORD:-

It is keyword and unary operator

It is use to create a block of memory in heap area during run time


Once the object is created new keyword will written the reference of an object to the variable

 CONSTRUCTER:-
Constructer is a special member of a class whose name is same as the class name

Constructer
Page No
 JAVA NOTES 
Date

 NON-PRIMITIVE DATA TYPE:-

Avery class name in java is a non-primitive data type

Non-primitive data type is use to create is non-primitive variable to store the reference of an object
Program:-

class bag
{
String colour;
double price;
int compartment;
String company;
public void tocarry()
{
[Link]("tocarry a bag");
}
public static void main(String[] java)
{
bag b1=new bag();
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
[Link]("---------");
[Link]="black";
[Link] =500;
[Link]=4;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]="puma";
[Link]([Link]);
}
}
Trashing:-
Page No
 JAVA NOTES 
Date

 STATIC CONTACT:-

The block which belongs to static method and multiline static initializer is known as static contact

In static contact we cannot use non-static member directly by its name

Program:-
class subprogrambag
{
public static void main(String[] args)
{
bag b1=new bag();
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
}
}
Trashing :-
Page No
 JAVA NOTES 
Date

 DYNAMIC READ:-

The process of reading the data from the user during execution of a program is known as dynamic read

 STEPS TO ACHIVE DINAMIC READ:-


Step 1:- import the scanner class from java utill scanner;

Step 2:- create an abject of scanner class scanner s1 = new scanner ([Link]);
Step 3:- call the method of a scanner class to read the data from user int a1 = [Link]();

 Method in a scanner class:-

Type of Data

Byte Nextbyte()
Short Nextsort()
Int Nextint()

Long Nextlong()

Floot nextfloot

Double Nextdouble()
Boolean Nextboolean()
Char Nextchar()
String (string word) Next()charft()

String (multi word) Next()

class shoes
{
String colour;
int size;
String company;
public static void forrunning()
{
[Link]("use for running");
}
public static void main(String[] args)
{
shoes s1 = new shoes();
Page No
 JAVA NOTES 
Date

[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link] = "black";
[Link] = 7;
[Link] = "woodland";
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
shoes s2 = new shoes();
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
}
}

class Books
{
String name;
int noofpages;
int price;
public static void main(String[] java)
{
Books b1 = new Books();
Page No
 JAVA NOTES 
Date

[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]("_________________________");
[Link] = 300;
[Link] = "SQL";
[Link]();
[Link]([Link]);
[Link]([Link]);
[Link]("________________________");
Books b2 = new Books();
[Link] = 500;
[Link] = "java";
[Link] = 500;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
[Link]("________________________");
Books b3 = new Books();
[Link] = 650;
[Link] = "python";
[Link] = 450;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]();
}
public void toread()
{
[Link](name+ "is a book of" +noofpages+ "pages");
}
}
Trashing:-
Page No
 JAVA NOTES 
Date

 NON-STATIC AND NON-STATIC METHOD:-

Any member declared in a class and not prefix with a static modifier is known as non-static member of class
Non-static member belongs to an instance of class hence it is also known as instance member or object
member
The member for non-static member is allocated inside the heap area
We can create any no off instance for a class

Non-static member will be allocated in every instance of class

 NON-STATIC MEMBER:-

1) Non-Static Variable
2) Non-Static Method
3) Non-Static Initialization

1) NON-STATIC VERIABLE:-

A variable declared inside a class block and prefix with a static modifier is known as non-static variable

 CHARACTERISTIC NON-STATIC VERIABLE:-


❶We can’t use the non-static variable without creating an object
❷We can only use the non-static variable with the help of object reference

❸Non-static variable are assigned with default value


❹Multiple copies of non-static variable will be created for every object

2) NON-STATIC METHOD:-

Any member declared in a class block and not prefix with a static modifier is known as non-static method

 CHARACTERISTICS NON-STATIC METHOD:-

❶A method will gets stored inside a method area and reference of method will get stored in side instance

of a class (object of class)

❷We can’t call the non-static method of a class without creating instance of class (object of class)

❸We can’t access the non-static method directly with the help of class name

❹Non-static method can’t be access directly with their name inside static context.
Page No
 JAVA NOTES 
Date

3) NON-STATIC INITIALIZER:-

Non-static initializer will execute during the loading process of object

Non-static initializer will execute once for every instance of class (for every object)

 PURPUS OF NON-STATIC INITIALIZER:-


Non-static initializer is use to execute to the start of instance of an object

There are two type of non-static initializer

1) Single line non static initializer

Syntax:-

Data type variable name = value

2) Multi line non-static initializer


Syntax:-
{

Instruction

}
Note:-
All non-static initializer will get execution in top to bottom order by constructer for
every instance of a class

class nonstaticinitializer
{
static int b = 34;
int a = 25;
static
{
[Link]("Hello World MLSI");
}
public static void main(String[] args)
{
[Link]("Main start");
nonstaticinitializer n1 = new nonstaticinitializer();
[Link]("Main End");
}
{
[Link]("Hello World MLNSI");
}
}
Page No
 JAVA NOTES 
Date

Trashing:-

 ARRAY:-

Array is a continuous block of memory which is use store multiple values

 CHARACTERISTIC OF AN ARRAY :-
❶The size of array must be define at the time of declaration
❷Once declare the size of array can’t be modified hence array is known as fixed size

❸In an array we can access the element’s with the help of index
❹Index is a integer number which start’s from zero and end’s with the size of array minus one

❺In an array we can store only homogeneous type of value. It is also known as homogeneous collection of

object

Note:-

In java, Array is an object

DECLARING AN ARRAY:-

Syntax:-
Data type name [] = new data type [size]
Page No
 JAVA NOTES 
Date

INSTANTIATING AN ARRAY :-

INITIALIZING THE ELEMENT’S IN AN ARRAY :-

Ar[0]=10 0 0 10

Ar[1]=20 1 0 20

Ar[2]=30 2 0 30

Ar[3]=40 3 0 40

Int ar[] = {10,20,30,40}

ACCESSING THE ELEMENT FROM ARRAY:-

We can access the element’s from array using index

[Link](ar[0]+ar[1])
Page No
 JAVA NOTES 
Date

[Link](ar[2])

[Link](ar[3])

DECLARING, INITIALIZING, INSTANTIATING AN ARRAY IN ONE LINE:-

Int a[] = {10,20,30,40}


Example program:-
class array
{
public static void main(String[] args)
{
String ar[] = new String[4];
[Link](ar[0]+ar[1]+ar[2]+ar[3]);
ar[1] = "black";
ar[0] = "pink";
ar[2] = "pink lite";
ar[3] = "read";
[Link](ar[0]+ar[1]+ar[2]+ar[3]);
}
}
Output:-

Q.1 Create all array initializer the value in array and print all the value an array using loop

Q.2 Create an array and print the addition of all the number’s from array

Q.3 Write a java program to print even number from array

Q.4 Write a java program to copy all the elements from one array to another
Page No
 JAVA NOTES 
Date

 COMSTRUCTER:-

Program:-
class constructerMarker
{
String color = "Read";
double price;
constructerMarker()
{
[Link]("Hello from no args constructer");
}
public static void main(String[] args)
{
constructerMarker m1 = new constructerMarker();

}
{
[Link]("Hello from MLNSI");
}
}
Output :-

Constructer is a special type of non-static method whose name is the same as a class name but it does not
have written type

Syntax :-

[access modifier] [modifier][class name] ([formal argument])

{
Instruction

 PURPOSE OF A CONSTRUCTOR :-

During the execution of constructer

❶Non-static members of a class will be loaded of an object if there is non-static initializer in the class

❷It will start execution in top to bottom order


❸Programer inside the constructor gets executed
Page No
 JAVA NOTES 
Date

 CLASSIFICATION OF CONSTRUCTER:-

1. No-argument constructer

2. Parameterize constructer

1. NO-ARGUMENT CONSTRUSTER:-
A constructor which does not have a formal argument is known as no argument constructer

2. PARAMETERISE CONSTRUCTER:-

A constructer which constant formal argument is known as parameterize constructer

 CONSTRUCTER OVER LOADING:-

If a class as having more than one constructer with a same name but different formal argument is known
as constructer over loading

 PURPOSE OF PARAMETERISE CONSTRUCTER :-

Parameterize constructer is use to initialize non-static variable buy a accepting data from constructer in the

object creation process.

Program:-

class pen
{
String color;
double price;
pen()
{
[Link]("Hello no argument construction");
}
pen(String h)
{
Page No
 JAVA NOTES 
Date

color=h;
}
pen(String a, double b)
{
color = a;
price = b;
}
public static void main(String[] args)
{
pen p1 = new pen ();
[Link]([Link]);
[Link]([Link]);
pen p2 = new pen ("black",100);
[Link]([Link]);
[Link]([Link]);
pen p3 = new pen ("blue");
[Link]([Link]);
[Link]([Link]);

}
}
Output:-

Program:-
import [Link];
class calculater
{
public void add()
{
Scanner sc =new Scanner ([Link]);
[Link]("Enter the 1st num");
int a = [Link]();
Page No
 JAVA NOTES 
Date

[Link]("Enter the 2nd num");


int b = [Link]();
int res = a+b;
[Link]("Addition is :"+res);
}
public void sub()
{
Scanner sc =new Scanner ([Link]);
[Link]("Enter the 1st num");
int a = [Link]();
[Link]("Enter the 2nd num");
int b = [Link]();
int res = a-b;
[Link]("Subtraction is :"+res);
}
public void mul()
{
Scanner sc =new Scanner ([Link]);
[Link]("Enter the 1st num");
int a = [Link]();
[Link]("Enter the 2nd num");
int b = [Link]();
int res = a*b;
[Link]("Multiplication is :"+res);
}
public void div()
{
Scanner sc =new Scanner ([Link]);
[Link]("Enter the 1st num");
int a = [Link]();
[Link]("Enter the 2nd num");
int b = [Link]();
int res = a/b;
[Link]("Dividation is :"+res);
}
}

import [Link];
class calculaterDriver
{
public static void main(String[] args)
{
Scanner sc =new Scanner ([Link]);
calculater c1 = new calculater();
boolean exit = true;
while(exit)
Page No
 JAVA NOTES 
Date

{
[Link]("Enter the choice \[Link]\[Link]\[Link]\[Link]\[Link]");
int choice = [Link]();
switch (choice)
{
case 1:
{
[Link]();
}
break;
case 2:
{
[Link]();
}
break;
case 3:
{
[Link]();
}
break;
case 4:
{
[Link]();
}
break;
case 5:
{
exit = false;
[Link]("Application Closed______");
}
break;

}
}
}
}
Page No
 JAVA NOTES 
Date
Page No
 JAVA NOTES 
Date

SECTION-NO:-2

 PRINCIPLE OF OPUS:- (OBJECT ORIENTED PROGRAMING SYSTEM):-


Object oriented programing system has followed principle

1. Encapsulation

2. Inheritance

3. Polymorphism

4. Abstraction

1. ENCAPSULATION:-
❶The process of binding seats behavior of an object together is in known as encapsulation

❷We can achieve encapsulation in java with the help of class

❸Class has both stets and behavior of an object


❹By using encapsulation we can achieve data hiding

1) DATA HIDING :-
It is process of restricting the direct access of data member of an object and provides indirect secured

access of data member throw the method of the same object is known as data hiding

 EXAMPLE OF WITHAUT DATA HIDING :-


Page No
 JAVA NOTES 
Date

 EXAMPLE OF WITH DATA HIDING :-

 STEPS TO ACHIVE DATA HYDING :-


❶Prefix data members of a class with private modifier
❷Design a getter and setter method

 PRIVET MODIFIER:-
❶Private is access modifier

❷Private is a class level modifier


❸If the member of a class are prefix with a private modifier then we can access those member only private
modifier
Note:-

Data hiding can be achieve with the help of privet modifier

 GETTER METHOD:-

❶The getter method is used to fetch the data (print, display, read)

❷The written type of getter is the type of hidden value

 SETTER METHOD:

❶The setter method is use to update or modify the data


❷The written type of setter method is always void
Page No
 JAVA NOTES 
Date

Note:-

❶ If you won’t to make your data member only readable get create only getter

❷If you won’t to make your hidden data member only modifiable then create only setter method
❸If you won’t to make your hidden data member both readable and modifiable then create both getter and

setter method
❹If we won’t to make your hidden data member neither readable non modifiable then don’t create getter

and setter method

Program:-
class Mobile
{
private String color;
private double price;
private String company;

public String getcolor()


{
return color;
}
public void setcolor(String color)
{
[Link] = color;
}
public double getprice()
{
return price;
}
public void setprice(double price)
{
[Link] = price;
}
public String getcompany()
{
return company;
}
public void setcompany(String company)
{
[Link] = company;
}
}
Page No
 JAVA NOTES 
Date

import [Link];
class MobileDriver
{
public static void main(String[] args)
{
Scanner sc = new Scanner ([Link]);
Mobile m1 = new Mobile();
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]("---------------------------");
[Link]("Enter the mobile company");
String comp = [Link]();
[Link](comp);
[Link]("mobile company updated successfully-----");
[Link]("---------------------------");
[Link]("Enter the mobile price");
double price = [Link]();
[Link](price);
[Link]("mobile price updated successfully-----");
[Link]("---------------------------");
[Link]("Enter the mobile color");
String color = [Link]();
[Link](color);
[Link]("mobile color updated successfully-----");
[Link]("--------------------------");
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
}
}
Out Put:-
Page No
 JAVA NOTES 
Date

 RELATIONSHIP:-

A connection between two object is known as relationship

Type of relationship
1. Has a relationship

2. Is a relationship

1. HAS A RELATIONSHIP:-

If one object is dependent upon another object is known as has a relationship

Based on the level of dependent on the has a relationship is classified in to two type

1) Composition

2) Aggregation

1) COMPOSITION:-

The dependency between two object such that one object can’t exist without another object is known

as composition

Ex:- car and engine

2) AGGREGATION:-
The dependency between two object such that one object can exist without the another object is know

as aggregation
Ex:- train and online train booking

Car Engine

{ {

} }

Note:-
❶We can achieve a has a relationship is java by placing the reference variable of dependent class in side

another class
❷The instance of dependent object can be created in two ways
Page No
 JAVA NOTES 
Date

1) Early instantiations

2) Lazy instantiations

1) EARLY INSTANTIATIONS:-

If the instance of dependent object is created implicitly is known as early instantiations

This design can be achieved with the help of constructer

 STEPS TO ACHIEVED EARLY INSTANTIATIONS:-


Step1:- Create a dependent class
Step2:-Create another class and place the reference of dependent object variable another class

Step3:-Create constructer of a class which also accept the dependent type object

Step4:-Create the object of a class so the object of dependent class gets created

Program:-
package relationship;

public class Battery {


public static final String Company = null;
int bno;
String Companny;
public Battery(int bno, String Companny) {
[Link] = bno;
[Link] = Companny;
}
}

package relationship;

public class Mobbile {


String Company;
double Price;
Battery b;
public Mobbile(String Company,double Price,Battery b) {
[Link] = Company;
[Link] = Price;
this.b = b;
}
}
Page No
 JAVA NOTES 
Date

package relationship;

public class MobbileDrive {


public static void main(String[] args) {
Mobbile m1 = new Mobbile ("Samsung",25000, new Battery(12344,"ABC"));
[Link]("Mobile Company"+ [Link]);
[Link]("Mobbile Price"+[Link]);
[Link]("Battery Company :"+ [Link]);
}
}

Out Put:-

Program:-
package bagStudentBagDrive;

public class Bag {


String Company;
double Price;
String Color;
public Bag(String Company, double Price, String Color) {
[Link] = Company;
[Link] = Price;
[Link] = Color;
}
}
package bagStudentBagDrive;
public class Student {
String name;
int RollNo;
Bag b;
public Student(String name, int RollNo) {
[Link] = name;
[Link] = RollNo;
}
public void tocarry(Bag b) {
this.b = b;
[Link]("Student name :"+ name );
[Link]("Student RollNo :"+ RollNo );
[Link]("Bag Company :"+ [Link]);
[Link]("Bag Price :"+ [Link]);
[Link]("Bag Color :"+ [Link]);
}
}
Page No
 JAVA NOTES 
Date

package bagStudentBagDrive;

import [Link];

public class BagDriver {


public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
[Link]("Enter student name");
String name = [Link]();
[Link]("Enter Student RollNo");
int RollNo = [Link]();
Student s1 = new Student (name, RollNo);
[Link]("Enter Bag Company");
String Company = [Link]();
[Link]("Enter Bag Price");
double Price = [Link]();
[Link]("Enter bag color");
String Color = [Link]();
[Link](new Bag(Company,Price,Color));
}
}

Out Put:-

Program:-
package StudentSchool;
public class Student {
private String sname;
private int id;
private int std;
public String getSname() {
return sname;
}
public void setSname(String sname) {
[Link] = sname;
}
Page No
 JAVA NOTES 
Date

public int getId() {


return id;
}
public void setId(int id) {
[Link] = id;
}
public int getStd() {
return std;
}
public void setStd(int std) {
[Link] = std;
}
public Student(String sname, int id,int std) {
[Link] = sname;
[Link] = id;
[Link] = std;
}
}

package StudentSchool;
import [Link];
public class School {
String name;
Student s;
public School(String name) {
[Link] = name;
}
public void addstudent() {
if (this.s == null)
{
this.s = s;
[Link]("admision successfully");
[Link]("----------------------------------------");
}
else
{
[Link]("admision is already taken yet");
[Link]("-----------------------------------------");
}
}
public void canceleadmision() {
if (this.s == null)
{
[Link]("admision is not taken yet");
[Link]("-----------------------------------------");
}
else
{
this.s = null;
[Link]("admision cancele successfully");
[Link]("-----------------------------------------");
}
}
public void updatestd() {
if (this.s == null)
{
Page No
 JAVA NOTES 
Date

[Link]("admision is not taken yet ");


[Link]("-----------------------------------------");
}
else
{
Scanner sc = new Scanner ([Link]);
[Link]("enter the new std to update");
int std = [Link]();
[Link](std);
[Link]("std updated successfully-----");
[Link]("-----------------------------------------");
}
}
public void displaydetails() {
if (this.s == null)
{
[Link]("admision is not taken yet----");
[Link]("------------------------------------------");
}
else
{
[Link]("=========="+name+"===========");
[Link]("student name:"+ [Link]());
[Link]("student id :"+ [Link]());
[Link]("student std:"+ [Link]());
[Link]("------------------------------------------");
}
}
}

package StudentSchool;
import [Link];
public class SchoolDriver {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
School s1 = new School("Hal School");
boolean exit = true;
while (exit)
{
[Link]("Enter the Choice\n1 Taken Admision\n2 Cancele Admision\n3
Update STD \n4 Display Details\n5 Exite");
int choice = [Link]();
switch (choice)
{
case 1:
{
[Link]("ENTER THE STUDENT NMAE");
String name = [Link]();
[Link]("ENTER THE STUDENT ID");
int id = [Link]();
[Link]("ENTER THE STD");
int std = [Link]();
[Link]();
}
break;
Page No
 JAVA NOTES 
Date

case 2:
{
[Link]();
}
break;
case 3:
{
[Link]();
}
break;
case 4:
{
[Link]();
}
break;
case 5:
{
exit = false;
[Link]("APLICATION CLOSED..........");
[Link]("---------------------------------------");
}
break;
default:
{
[Link]("Invalid choice______");
}
}
}
}
}

 IS A RELATIONSHIP:-

The relationship between two object which is similar to parent and child relation is known as is a relationship
In an is a relationship the child object will acquire all the property of the parent object and child object will

have its owned extra property

In is a relationship we can achieve generalization and specialization parent is called as generalization and

child is called as specialize

Note:-

Private members, constructers, initializers cannot be inheritance


Page No
 JAVA NOTES 
Date

With the help of child class deference type we can use members of parent as child class with the help

Of parent class reference we can use only the member of parent class but not the child class

 PARENT CLASS (SUPER,BASE):-

The parent class is also known as supper class or base class

 CHILD CLASS (SUB,DERIVED):-

The child class is also known as subclass or derived class

Note:-

Is a relationship can be achieved with the help of inheritance

 INHERITANCE:-
The process of one class is acquiring all the property and behavior of another class is called as

Inheritance
In java we can achieve inheritance with the help of
1. Extend keyword

2. Implement keyword

1. EXTENND KEYWORD:-

Extend keyword is use to achieve inheritance between two class

public class parent {


public void fromparent()
{
[Link]("Hello From Parent!");
}
}
public class child extended parent {
public void fromchild()
}
{
[Link]("Hello From Child!");
}
public static void main(String [] args)
Page No
 JAVA NOTES 
Date

{
child c1 = new child ();
[Link] (); //hello from child
[Link] (); //hello from parent
[Link]("------------------------");
parent p1 = new parent ();
[Link](); // hello from parent
[Link](); // error
}
Program:-
public class user {
private String name;
private long cno;
private int pswd;
private String status;
public user(String name, long cno, int pswd, String status) {
[Link] = name;
[Link] = cno;
[Link] = pswd;
[Link] = status;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
public long getCno() {
return cno;
}
public void setCno(long cno) {
[Link] = cno;
}
public int getPswd() {
return pswd;
}
public void setPswd(int pswd) {
[Link] = pswd;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
[Link] = status;
}
}

package relationship;
import [Link];
public class Instagram
Page No
 JAVA NOTES 
Date

user u;
public void loginuser(user u) {
if (this.u==null) {
this.u=u;
[Link]("Login Successfully......");
[Link]("-------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the passward");
int pswd = [Link]();
if (pswd == [Link]()) {
[Link]("Already Logged in");
[Link]("-------------------------");
}
else {
[Link]("Incorrect Passward");
[Link]("-------------------------");
}
}
}
public void logout () {
if (this.u==null) {
[Link](" loged in First");
[Link]("-------------------------");
}
else {
this.u=null;
[Link]("Logout Successfully.....");
[Link]("-------------------------");
}
}
public void updateStatus () {
if (this.u==null) {
[Link]("Login First....you havent log in");
[Link]("-------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the passward");
int pswd = [Link]();
if (pswd == [Link]()) {
//Scanner sm = new Scanner([Link]);
[Link]("Update the status");
String status = [Link]();
[Link](status);
[Link]("Status updated succesfully.......");
[Link]("-------------------------");
}
else {
[Link]("Incorrect Passward");
}
Page No
 JAVA NOTES 
Date

}
}
public void displayDetails () {
if (this.u==null) {
[Link]("login first...");
[Link]("-------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the passward");
int pswd = [Link]();
if (pswd == [Link]()) {
[Link]("user name : "+ [Link]());
[Link]("user contact number : "+ [Link]());
[Link]("user satus : "+ [Link]());
[Link]("-------------------------");
}
else {
[Link]("Incorrect Passward");
}
}
}
public void changePassward () {
if (this.u==null) {
[Link]("Login first");
[Link]("------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the Old passward");
int opswd = [Link]();
if (opswd == [Link]()) {
Scanner sm =new Scanner ([Link]);
[Link]("Enter new Passward");
int npswd = [Link]();
[Link](npswd);
[Link]("New Passward Updated Succesully.....");
}
else {
[Link]("Incorrect Old Passward");
}
}
}
}

package relationship;
import [Link];
public class DriverInstagram {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
Instagram ref = new Instagram ();
boolean condition = true;
while (condition) {
Page No
 JAVA NOTES 
Date

[Link](">>>>>>>>>>>>>> INSTAGRAM <<<<<<<<<<<<<<<<");


[Link]("Enter the choice\n1. Login\n2. Logout\n3. Update
Status\n4. Display Detalis\n5. Change Passward\n6. EXIT");
int choice = [Link]();
switch(choice) {
case 1 : {
[Link]("Enter User Name");
String name =[Link]();
[Link]("Enter User Contact Number");
long cno = [Link]();
[Link]("Enter Passard");
int pswd = [Link]();
[Link]("Enter the status");
String status = [Link]();
[Link](new user (name,cno,pswd,status));
[Link]("===============================");
}
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : [Link]();
break;
case 6 :{
condition = false;
[Link]("Aplication Exit........");
}
break;
default : {
[Link]("Invalid Input....Please take valid
input");
}
}
}
}
}

Program:-

package relationship;
public class Account {
private String name;
private long acno;
private String branch;
private long cno;
private double balance;
private int pswd;
public Account(String name, long acno, String branch, long cno, double balance, int
pswd) {
Page No
 JAVA NOTES 
Date

[Link] = name;
[Link] = acno;
[Link] = branch;
[Link] = cno;
[Link] = balance;
[Link] = pswd;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
public long getAcno() {
return acno;
}
public void setAcno(long acno) {
[Link] = acno;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
[Link] = branch;
}
public long getCno() {
return cno;
}
public void setCno(long cno) {
[Link] = cno;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
[Link] = balance;
}
public int getPswd() {
return pswd;
}
public void setPswd(int pswd) {
[Link] = pswd;
}
}

package relationship;
import [Link];
public class Bank {
Account a;
String bankName;
public Bank(String bankName) {
[Link] = bankName;
}
public void createAccount(Account a) {
Page No
 JAVA NOTES 
Date

if (this.a==null) {
this.a=a;
[Link]("Account Created Successully....");
[Link]("-------------------------------");
}
else {
[Link]("Account Already created.......");
[Link]("------------------------------");
}
}
public void cancelAccount() {
if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc =new Scanner ([Link]);
[Link]("Enter the Pin");
int pin = [Link]();
if (pin==[Link]()) {
this.a=null;
[Link]("Account Canceled Successfully..");
[Link]("------------------------------");
}
else {
[Link]("Incorrect Pin....");
}
}
}
public void updateDetails() {
if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc =new Scanner ([Link]);
[Link]("Enter the Pin");
int pin = [Link]();
if (pin==[Link]()) {
[Link]("Enter the new Contact Number");
long ncno = [Link]();
[Link]("Enter New Branch Name");
String branch = [Link]();
[Link](ncno);
[Link](branch);
[Link]("The updation for Branch And Contact Number is
Successfull.....");
[Link]("------------------------------");
}
else {
[Link]("Incorrect Pin....");
}
}
}
public void displayDetails () {
Page No
 JAVA NOTES 
Date

if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc =new Scanner ([Link]);
[Link]("Enter the Pin");
int pin = [Link]();
if (pin==[Link]()) {
[Link](">>>>>>>>>>>>>>> "+bankName);
[Link]("Name : "+ [Link]());
[Link]("Branch Name :"+ [Link]());
[Link]("Contact Number : "+ [Link]());
[Link]("Account Number : "+ [Link]());
[Link]("------------------------------");
}
else {
[Link]("Incorrect Pin....");
}
}
}
public void changePassward () {
if (this.a==null) {
[Link]("Login first");
[Link]("------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the Old passward");
int opswd = [Link]();
if (opswd == [Link]()) {
Scanner sm =new Scanner ([Link]);
[Link]("Enter new Passward");
int npswd = [Link]();
[Link](npswd);
[Link]("New Passward Updated Succesully.....");
}
else {
[Link]("Incorrect Old Passward");
}
}
}
public void withdrawAmount () {
if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the pin");
int pswd = [Link]();
if (pswd == [Link]()) {
[Link]("Enter Withdraw Amount");
int amt = [Link]();
if (amt <= [Link]()) {
Page No
 JAVA NOTES 
Date

double remainingAmount = [Link]() - amt;


[Link](remainingAmount);
[Link]("Withdraw Successull....");
[Link]("-------------------------");
}
else {
[Link]("Insuficient Balance");
[Link]("-------------------------");
}
}
else {
[Link]("Inncorect Pin..");
}
}
}
public void depositeAmount () {
if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the pin");
int pswd = [Link]();
if (pswd == [Link]()) {
[Link]("Enter Deposite Amount");
double depositeAmount = [Link]();
double remainingAmount = [Link]() + depositeAmount;
[Link](remainingAmount);
[Link]("Deposition Successull....");
[Link]("-------------------------");
}
else {
[Link]("Incorrect Passward");
}
}
}
public void displayBalance () {
if (this.a==null) {
[Link]("Account not created Yet.......");
[Link]("------------------------------");
}
else {
Scanner sc = new Scanner([Link]);
[Link]("Enter the pin");
int pswd = [Link]();
if (pswd == [Link]()) {
[Link]("Total Balance is : " + [Link]());
[Link]("----------------------");
}
else {
[Link]("Incorrect pin..");
[Link]("----------------------");
}
}
Page No
 JAVA NOTES 
Date

package relationship;

import [Link];
public class DriverBank {
public static void main(String[] args) {
Bank ref = new Bank("IndianBank");
Scanner sc = new Scanner ([Link]);
boolean condition = true;
while (condition) {
[Link]("Enter the choice\n1. Creat Account \n2.
Cancel Account\n3. Update Details\n4. Display Detalis\n5.
Change Passward\n6. Withdraw Amount\n7. Deposite Amount\n8.
Display Balance\n9. Exit ");
int choice = [Link]();
switch(choice) {
case 1 : {
[Link]("Enter The Name");
String name = [Link]();
[Link]("Enter The Account Number");
long acno = [Link]();
[Link]("Enter The Branch");
String branch = [Link]();
[Link]("Enter The Contact Number");
long cno = [Link]();
[Link]("Enter The Balence");
double balence = [Link]();
[Link]("Enter The Passward/Pin");
int pswd = [Link]();
[Link](new Account
(name,acno,branch,cno,balence,pswd));
}
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : [Link]();
break;
case 6 : [Link]();
break;
case 7 : [Link]();
break;
case 8 : [Link]();
break;
case 9 : {
condition = false;
Page No
 JAVA NOTES 
Date

[Link]("Application Closed.....");
}
break;
default : [Link]("Something Went
Wrong....Try Again");
}
}
}
}

 TYPES OF INHERITANCE :-
1. Single Level Inheritance:-

Inheritance of only one level is known as single level inheritance

2. Multi-Level Inheritance:-

Inheritance of more than one level is known as multi-level inheritance

3. Hieratical Inheritance:-
If a parent (super class) has more than one child (sub class) at the same level then it is known as
Page No
 JAVA NOTES 
Date

hieratical inheritance

4. Multiple Inheritance:-

If a child class (sub class ) inheritance more than one parent class (supper class ) then it is known as

multiple inheritance

Note:-
❶Multiple inheritance has a problem known as demand problem
❷Because of demand problem we can’t achieve multiple inheritance with the help of class

❸In java we can achieve multiple inheritance with the help of interspace

 DEMAND PROBLEM:-

C c1 = new (c)

c1.m1();
Page No
 JAVA NOTES 
Date

Assume that there are two classes class A and class B both are having a method with same

signature
If class C inheritance class A and class B then this two methods are inheritance to C

Now an ambiguity a arise when we try to call to super class method with the help of sub class reference

This problem is known as demand problem

5. Hybrid Inheritance:-

Hybrid is a combination of hierarchical inheritance and multiple inheritance

 SUPER CLASS STATEMENT :-

Super class is a keyword it is use to access the members of super class


Super call statement is use to call the constructer of parent class from child class constructer

 PURPUS OF A SUPER CALL STATEMENT :-


Page No
 JAVA NOTES 
Date

When the object is created the super call statement help to load the non-static member of parent class

In to child object

We can also use super call statement to pass the data from child class to parent class

 RULLES TO USE THE SUPER CALL STATEMENT :-


Super call statement should always be the first instruction of constructer call

If a programmer doesn’t use a super call statement then compiler will add no argument super class

statement in to the no of body

package relationship;
public class Vehical {
int noofseats;
int noofwheels;
public Vehical(int = noofseats, int = noofwheels) {
[Link];
[Link];
}
}

package relationship;
public class Bike extends Vehical {
Bike (_int a, int b)
{
super(a,b)
}
public static void main(String[] args) {
Bike b1 = new Bike (2,2);
[Link]([Link]);
[Link]([Link]);
}
}

 INDERSTANDING REFERANCE VARIABLE:-

One object can be reference with multiple reference variable

We can copy the reference of one object in to multiple reference veriable


Program:-
package relationship;
public class Student {
int id;
String name;
public Student (int id,String name) {
[Link] =id;
Page No
 JAVA NOTES 
Date

[Link] = name;
}
}

package relationship;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student(34, "ram");
Student s2 = s1;
Student s3 = s2;
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
}
}

Note:-

We can access the member of student object by using all three variable (s1,s2,s3)
The state of an object can also be modify by any of this three reference veriable

We can copy the reference of one veriable in to another veriable only if both the reference veriable
are of the same type
If both the reference veriable are of different type then the conversion of one reference to another

Reference is required (non-primitive type casting)

 NON-PRIMITIVE TYPE CASTING:-


The process of converting one type of reference in to another type of reference is known as non

primitive type casting


There must be is a relationship between two reference

There should be a common child


Page No
 JAVA NOTES 
Date

Fruit can be converted to apple and apple can be converted to fruit vegetable can converted to current

and current can be converted to vegetable

But fruit and apple can’t be converted vegetable and carrot as well as

Fruit can be converted in to an apple as well as mango and apple cannot convert in to fruit

But mango can’t converted to apple as well as apple can’t converted to mango

Example 3:-

We can convert A to B type B to A type , A to C type, C to A type B to C type and C to B type


Page No
 JAVA NOTES 
Date

 TYPE OF NON-PRIMITIVE TYPE CASTING :-

Non-Primitive type casting can be fruit classified in to two type

1. Up casting
2. Down casting

1. Up casting:-

The process of converting the child class reference in to the parent class reference type

Note:-

The up casting is implicitly don by the compiler it is also auto up casting

Once the reference is up casted we can’t access the members of child class

Up casting can also be don explicitly with the help of type cast operator
Program:-
package relationship;
public class Apple extends Frute {
String color;
public static void main(String[] args) {
Frute f1 = new Apple();//up casting
[Link]([Link] );
//[Link]([Link]);//CTE
[Link]("----------------------------");
}
}
Page No
 JAVA NOTES 
Date

Cab- generalized variable

C = new min();

C = new micro();
C = new prime ();

It is usual to achieve generalization


It help to create generalization contender so that the reference of any type of child object can be stored

 DISADVANTAGE OF UPASTING:-

There is only one disadvantage of up casting that is once the reference is up casting the child member

Can’t be use

In order to overcome this problem we should go from down casting

2. DOWN CASTING :-

The process of converting super class reference to child class reference is known as down casting

Note:-
Down casting is not implicitly don by the compiler
It should be don explicitly by the programmer with the help of type cast operator

 PURPUS OF DOWN CASTING:-


If the reference is up casting we can’t use the member of child class

To use the member of child class we need to perform down casting


Apple a1 = (Apple)f1;//Down casting
[Link]([Link]);//null
[Link]([Link]);//null
Page No
 JAVA NOTES 
Date

 CLASS CAST ACEPTION:-


It is a run time exception

Which we try to convert a reference to the specific type and the object does not exit then we will get

Class cast exception


package relationship;
public class Apple extends Frute {
String color;
public static void main(String[] args) {
Frute f1 = new Frute();
Apple a1 = (Apple)f1;
[Link]([Link]);
}
}

 INSTANCE OF OPERATOR:-

It is a binary operator it is use to chaek the reference variable which object is present and which object
Is not present the return type of the instance of operator is boolean

If the specific object is present it will return true else it will return faults
Program:-
package relationship;
public class Frute {
}
package relationship;
public class Apple {
}
package relationship;
public class Mango {
}
package relationship;
public class FruteDriver {
public static void main(String[] args) {
Frute f1 = new Apple();
[Link]([Link] of Mango);
[Link]([Link] of Apple);
}
}

Program:-
package relationship;
public class Ball {
private double radius;
public Ball(double radius) {
[Link] = radius;
}
public void setRadius(int radius) {
Page No
 JAVA NOTES 
Date

[Link] = radius;
}
}
package relationship;
public class Bag {
Ball b;
public void addBall (int choice, double radius) {
if (this.b==null) {
if(choice==1) {
b=new TennisBall(radius);
[Link]("Tennis Ball is successfully addes in Bag");
[Link]("----------------------------");
}
else if (choice==2) {
b=new BasketBall(radius);
[Link]("Basket Ball is successfully addes in bag");
}
else {
[Link]("Invalid Choice");
[Link]("----------------------------");
}
}
else {
if (choice == 1) {
[Link]("Tennis The Ball is Already Addes");
[Link]("----------------------------");
}
else if (choice ==2) {
[Link]("Basket The Ball is Already Addes");
[Link]("----------------------------");
}
else {
[Link]("Invalid Input");
[Link]("--------------------------------");
}
}
}
public void removeBall() {
if (this.b==null) {
[Link]("Bag is not added in the Bag");
[Link]("---------------------------");
}
else {
this.b=null;
[Link]("Ball is successfully removed");
[Link]("----------------------------");
}
}
public void checkBag() {
if (this.b==null) {
[Link]("Bag is Empty");
[Link]("----------------------------");
}
else {
[Link]("Bag is Not Empty");
[Link]("----------------------------");
Page No
 JAVA NOTES 
Date

}
}
public void showGame() {
if (this.b==null) {
[Link]("Ball is not added in the Bag");
[Link]("----------------------------");
}
else {
if (this.b instanceof TennisBall) {
TennisBall t1 = (TennisBall)b;
[Link]("You can play " + [Link]());
[Link]("----------------------------");
}
else if (this.b instanceof BasketBall)
{
BasketBall b1 = (BasketBall)b;
[Link]("You can Play "+[Link]());
[Link]("----------------------------");
}
else {
[Link]("Ball Not Found");
}
}
}
}
package relationship;
public class BasketBall extends Ball {
private String gname = "BasketBall";
public BasketBall(double radius) {
super(radius);
}
public String getGname() {
return gname;
}
}

package relationship;
public class TennisBall extends Ball {
private String gname = "Tennis Ball";
TennisBall(double radius) {
super(radius);
}
public String getGname() {
return gname;
}
}
package relationship;
import [Link];
public class DriverBag {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Bag ref = new Bag ();
boolean condition = true;
while (condition) {
Page No
 JAVA NOTES 
Date

[Link]("Enter The number \n1. Add The Ball\n2. Remove The


Ball\n3. Check The Bag\n4. Show The Game\n5. Exit");
int number = [Link]();
switch (number) {
case 1 : {
[Link]("Enter The choice\n1. Add Tennis Ball\n2. Add Basket
Ball");
int choice = [Link]();
[Link]("Enter The Radius Of Ball");
double radius = [Link]();
[Link]("-----------------------------");
[Link](choice,radius);
}
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : {
condition = false;
[Link]("Exit successfully...........");
}
break;
default : {
[Link]("Something went Wrong...");
}
}
}
}
}

Program:-

package Book;
public class Book {
private int quantity;
Book (int quantity) {
[Link]=quantity;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
[Link] = quantity;
}
}

package Book;
public class HarryPotter extends Book {
Page No
 JAVA NOTES 
Date

private String bname = "Harry Potter";


private String author = "J. K. Rawling";
HarryPotter (int quantity ) {
super (quantity);
}
public String getBname() {
return bname;
}
public String getAuthor() {
return author;
}
}

package Book;
public class RomeoJuliet extends Book {
private String bname = "Romeo Juliet";
private String author = "William Shakespear";
RomeoJuliet (int quantity ) {
super (quantity);
}
public String getBname() {
return bname;
}
public String getAuthor() {
return author;
}
}
package Book;
public class TwoStates extends Book {
private String bname ="2 States ";
private String author ="Chetan Bhagat";
TwoStates (int quantity ) {
super (quantity);
}
public String getBname() {
return bname;
}
public String getAuthor() {
return author;
}
}
package Book;
public class Cart {
Book b;
public void addBook (int choice, int quanity) {
if (this.b==null) {
if (choice== 1) {
b=new RomeoJuliet(quanity);
[Link]("The RomeoJuliet Book Add Successfully");
[Link]("-------------------------------------");
}
Page No
 JAVA NOTES 
Date

else if (choice == 2) {
b=new TwoStates(quanity);
[Link]("The 2 States Book Add Successfully");
[Link]("-------------------------------------");
}
else if (choice == 3) {
b=new HarryPotter(quanity);
[Link]("The Harry Potter Book Add Successfully");
[Link]("-------------------------------------");
}
else {
[Link]("Invalid Choice...");
}
}
else {
[Link]("The Book is Already Added !!");
}
}
public void removeBook () {
if (this.b==null) {
[Link]("Book is Not Added Yet..");
[Link]("-------------------------------------");
}
else {
this.b=null;
[Link]("The Book Remove is succesfull....");
[Link]("-------------------------------------");
}
}
public void checkCart () {
if (this.b==null) {
[Link]("Cart is Empty");
[Link]("-------------------------------------");
}
else {
[Link]("Cart is Not Empty");
[Link]("-------------------------------------");
}
}
public void showBook () {
if (this.b==null) {
[Link]("Add Book first...");
[Link]("-------------------------------------");
}
else {
if (b instanceof RomeoJuliet) {
RomeoJuliet r = (RomeoJuliet)b;
[Link]("Book Name : "+[Link]());
[Link]("Book Author Name : "+[Link]());
[Link]("Book Quantity : "+[Link]());
[Link]("---------------------------------");
}
else if (b instanceof TwoStates) {
TwoStates t = (TwoStates)b;
[Link]("Book Name : "+[Link]());
[Link]("Book Author Name : "+[Link]());
Page No
 JAVA NOTES 
Date

[Link]("Book Quantity : "+[Link]());


[Link]("---------------------------------");
}
else {
HarryPotter h = (HarryPotter)b;
[Link]("Book Name : "+[Link]());
[Link]("Book Author Name : "+[Link]());
[Link]("Book Quantity : "+[Link]());
[Link]("---------------------------------");
}
}
}
}

package Book;
import [Link];

public class DriverCart {


public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
Cart ref = new Cart();
boolean exit = true;
while (exit) {
[Link]("Enter The Choice\n1. Add Book\n2. Remove Book\n3. Check
Cart\n4. Show Book\n5. Exit");
int choice = [Link]();
switch (choice) {
case 1 : {
[Link]("Enter Book (What You Want to Add)\n1. Romeo
Juliet\n2. 2 States\n3. Harry Potter");
int a = [Link]();
[Link]("Enter The Quantity For Selected Book");
int quantity = [Link]();
[Link](a,quantity);
}
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : {
exit = false;
[Link]("Application Closed......");
}
break;
default : [Link]("Something Went Wrong...");
}
}
}
}
Page No
 JAVA NOTES 
Date

 POLIMORPHISM:-

Polymorphism is derived from to different greek word poly means number and morph means form

which means numeric form or different form polymorphism is a ability of an object to exiblit more than one
form in same name

There are two types of polymorphism


1. Compile time polymorphism

2. Rum time polymorphism

1. COMPILE TIME POLYMORPHISM:-

If the binding is achieved at the compile time and the same behavior get executed is known as compile

time polymorphism
It is also called as static polymorphism compile time polymorphism can be achived by
1) Method overloading

2) Constructor overloading

3) Method shadowing

4) Variable shadowing
5) Operator overloading (does not support in java )

1) METHOD OVERLOADING :-

If more than one method is created with the same name but different formal argument in the same
class is known as method overloading

Ex:-
class Test
{
public static void main(String[] args)
{
add();
add(2,5);
add(3,2,1)
}
public void add(int a, int b)
{
int res = a+b;
[Link](res);
Page No
 JAVA NOTES 
Date

}
public void add (int a, int b, int c)
{
int res = a+b+c;
[Link](res);
}
public void add ()
{
[Link]("use for addition ");
}
}

2) COMSTRUCTOR OVERLOADING :-
If a class content more than one constructor with a same name but different formal argument is known

as constructor overloading

3) METHOD SHADOWING:-
It the sub class and superclass have the static method with same signature is known as method

shadowing

If the method shadowing is done all compile hence it is compile time polymorphism
The execution of method depends on a reference type and does not depends on the type of object

Created
Note:-

Method shadowing is applicable only for static method

Ex:-

package ParentChild;
public class Parent {
public static void m1()
{
[Link]("Hello From Parent m1()");
}
}

package ParentChild;
public class Child extends Parent {
public static void m1()
{
[Link]("Hello Frome Child m1()");
}
public static void main(String[] args) {
Page No
 JAVA NOTES 
Date

Parent p1 = new Parent();


p1.m1();
Child c1 = new Child();
c1.m1();
Parent p2 = new Child();
p2.m1();
}
}

4) VARIABLE SHADOWING:-

If the superclass and subclass have a variable if the same name then it is known as variable shadowing

In variable shadowing binding is done at compile time hence it is compile time polymorphism
The execution of variable is dependent upon the type of reference variable we have use

Note:-
It is applicable for both static and non-static variable

package ParentChild;
public class ParentC {
String s1 ="ParenC";
}

package ParentChild;
public class ChildP extends ParentC {
String s1 = "ParentC";
public static void main(String[] args) {
ParentC p1 = new ParentC();
[Link](p1.s1);
ChildP c1 = new ChildP();
[Link](c1.s1);
ParentC p2 = new ChildP();
[Link](p1.s1);
}

2. RUN TIME POLYMORPHISM:-

The binding is achieve at the rune time it is known as runtime polymorphism


It is also called as dynamic binding run time polymorphism can be achieve by method overriding

 METHOD OVERRIDIGN:-
It the subclass and superclass have the non-static method with same signature is known as method

Overriding
Page No
 JAVA NOTES 
Date

Note:-
It is applicable only for non-static method
For method overriding is a relationship is mandatory
The type of method will get executed depends upon the type of object created

package ParentChild;
public class Parent {
public static void m1()
{
[Link]("Hello From Parent m1()");
}
}

package ParentChild;
public class Child extends Parent {
public static void m1()
{
[Link]("Hello Frome Child m1()");
}
public static void main(String[] args) {
Parent p1 = new Parent();
p1.m1();
Child c1 = new Child();
c1.m1();
Parent p2 = new Child();
p2.m1();
}
}

 OBJECT CLASS:-

Object class is defined in java long package

Object class is a supper most parent class for all the classes in java

In object class there are it non-static method

1. To String ():-

To string method return string value

To string method of an object class return the reference of an object in string formal

package Student;
public class Student {
String sname;
int id;
public Student (String sname , int id) {
[Link] = sname;
[Link] = id;
Page No
 JAVA NOTES 
Date

}
}
package Student;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student (Ram,12);
[Link](s1);//object class student @ 3d on address of object
}
}

Note:-
Java does not provide the real address of an object
Whenever program try to print the reference variable the to-string method of object class
get implicitly call

 PURPOSE OF OVERRIDING TOSTRING:-

We overriding to-string method become instance of retuning address of an object it will returning the

State of an attribute or object

package Student;
public class Student {
String sname;
int id;
public Student (String sname , int id) {
[Link] = sname;
[Link] = id;
}
public String tostring() {
return sname;
}
}
package Student;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student (Ram,12);
[Link](s1);//object class student @ 3d on address of object
}
}

2. Equals(obj):-

The return type of equal method is boolean

Two equals method we can pass the return of any object

The equals method of object class is use to compare the reference of an object
Page No
 JAVA NOTES 
Date

package Student;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student (Ram,12);
Student s2 = new Student (Ram,12);
[Link](s1);
[Link](s2);
[Link]([Link](s2));//false
Student s3 = s2;
[Link]([Link](s3));//true
}
}

 PURPUS OF OVERRIDING EQUALS(OBJ):-


We can overriding the equals method to compare the state of an two object inside of comparing the

address of an two object

package Student;
public class Student {
public boolean equals (object o) {
Student s1 = (Student)o;
return this [Link](s1 sname) && [Link] ==[Link];
}
}

package Student;

public class StudentDriver {


public static void main(String[] args) {
Student s1 = new Student (Ram,12);
Student s2 = new Student (Ram,12);
Student s3 = new Student (Ram,12);
[Link]([Link](s2));
[Link]([Link](s3));
}
}

 HASHCODE METHOD:-
The return type of hash code method is int

The object class hash code method is used to given a unic integer value of object according to the refrance
Page No
 JAVA NOTES 
Date

package Student;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student (Ram,12);
Student s2 = new Student (Ram,12);
[Link]([Link]());
[Link]([Link]() );
}
}

 PURPOSE OF OVERRIDING HASHCODE:-

After overriding hash code method it will return the intiger value on the basis of state of an object

public int hashCode()

return objects hash(sname,id);

}
package Student;
public class StudentDriver {
public static void main(String[] args) {
Student s1 = new Student (Ram,12);
Student s2 = new Student (Ram,12);
[Link]([Link]());
[Link]([Link]() );
}
}

 ABSTACTION:-

It is a design process of hiding the replace enation and showing only declaration to the user is known
as abstraction

We can achieve a abstraction with the help of abstract classes and interface

We can provide implementation to the abstract component with the help of inheritance and method

Overriding

1. Abstract Modifier :-

Abstract is a modifier and a keyword

It is applicable for only method and classes


Page No
 JAVA NOTES 
Date

2. Abstract Method:-

A method which is prefix with a abstract modifier it is known as abstract method

This is also set to be an incomplete method


The abstract method does not have a body

Note:-

Only the child class is response for given implementation two abstract method

3. Abstract Class:-

If the class is prefix with a abstract modifier then it is known as abstract class we cannot create

Instance (object) for an abstract class

Note:-

We cannot instantiate an abstract class

We can have abstract class without abstract method

If a class has at list one abstract method declare then it is monetary to make that class as an abstract class
An abstract class can have both abstract and concrete method (with body)

Ex:-
package newpackage;
abstract public class vehical {
abstract public void noofwheels();
abstract public void noofseats();
}
package newpackage;
abstract public class Car extends vehical
{

}
package newpackage;
public class Bike extends Car {
public void noofwheels()
{
[Link]("4 wheels");
}
public void noofseats()
{
[Link]("5 seats");
}
Page No
 JAVA NOTES 
Date

public static void main(String[] args) {


Bike b1 = new Bike ();
[Link]();
[Link]();
}
}

 IMPLIMANTATION OF ABSTRACT METHOD:-

If a class extends abstract class then should be given implementation to all the abstract method of

Supper class
If inheriting class doesn’t like to give implementation to the abstract method of supper class then it is

mandatory to make that class as abstract class

If subclass is also becoming and abstract class then the next level child class is responsive is given
implementation to the abstract method

 STEPS TO IMPLEMENTATION:-

Create a class

Inherit the abstract class

Override the abstract method (provide the implement to abstract method)

 Concrete Class:-

The class which is not prefix with a abstract keyword and which does not content any abstract method
is known as concrete class

Note:-

In java we can create object of any concrete class

 Concrete Method:-

The method with body is known as concrete method

package newpackage;
abstract public class Bank {
abstract public void cAccount();
abstract public void changeMno();
}
Page No
 JAVA NOTES 
Date

package newpackage;
abstract public class SBI extends Bank
{

package newpackage;
public class Axis extends SBI {
public void cAccount()
{
[Link]("Account is creted");
}
public void changeMno()
{
[Link]("mobil no change succesfully");
}
public static void main(String[] args) {
Axis a = new Axis();
[Link]();
[Link]();
}
}

 INTERFACE

It is a component in java which is use to achieve 100% abstraction with multiple implementation

Note:-
When an interface is compile we will get a class with class extension
Interface by default abstraction

Non-static method is interface is also by default abstraction

Q. What all the member the can be declared in an interface?

Member Class
Static variable Yes Yes but only final static variable

Non-static variable Yes No

Static method Yes Yes from jdk 1.8v

Note:- they are by default public in nature


Non-static method
Page No
 JAVA NOTES 
Date

Example:-
package project1;
public interface Demo1 {
int a;//CTE variable is by default public static variable must be initialize
}
package project1;
public interface Demo2 {
public void test()//CTE
{

}
}
package project1;
public interface Demo3 {
public static void main(String[] args) {
[Link]("Hello world");
}
}

 PURPUSE OF INTERFACE:-

To achieve 100% abstraction because concrete non-static method are not allowed in interface

To achieve 100% abstraction

Note:-

Only static method of interface cannot be inherited to both the child class and child interface

Inheritance with respect to interface and interface can inherit any number of interface with the help of
extends key word

package project1;
public interface int1 {
}
package project1;
public interface int2 {
}

Note:-

The interface which is inheriting an another interface should not give implementation (0

Ex:-

Interface i1 have 3 method

2-nonstatic (t1(),t2())
1-static (t5())
Page No
 JAVA NOTES 
Date

Interface i2 have 3 method

2-interfce non-static method (t1(),t2())

1-decleared non-static method(t4())

Ex2:- Interface inherit can multiple interfaces at a time

Note:-

With respect to interface there is no diamond problem


Page No
 JAVA NOTES 
Date

Rezone:-

 They don’t have a constructer


 Non-static method are abstract

 Static method are not interface

 INHERITANCE OF AN INTERFACE BY THE CLASS:-

Class can inherited an interface with the help of implement keyword

A class can inherited more than one interfaces at a time

Note:-

If a class inherit and interface then it should give implementation to the abstract method of an interface
If the class is not ready to give then it mandatory to make that class as an abstract class
Next level of child class responsible abstract method of an interface

 SOLUTION FOR DAIMOND PROBLAM:-


EX3:- Class inheriting multiple interface

The diamond problem is solved by implementing multiple interfaces by the class at a time

Rezone:-
Non-static method are not implemented in an inherit static method are not inherit
Page No
 JAVA NOTES 
Date

EX4:- Class can inherit interface

RULE:-

Use the extends first and then implement


Note:-
Class can inherit interface but it can’t inherit multiple classes at a time
Interface can’t inherit a class

EX5:- Interface can’t inherit from the class

Rezone:-

Class has concrete non-static method so class can’t be a parent to interface


Page No
 JAVA NOTES 
Date

 PACKAGES:-

A packages is use to group related classes interface and sub-classes

In a simple word it is a folder of directory which consist of several classes interfaces

 ADVANTAGES PACKAGES:-
Packages is use to avoid name conflate

It increases maintainability

It is use to categories classes and interface

It is use to achieve code reusability

 TYPES OF PACKAGES:-
We have two types of package
1. User-defined

2. Belding package

1. USER-DEFINED PACKAGE:-
The package which is created by programmer and user is known as user- defined package

2. BELDING PACKAGE:-

In java we have many belding packages


Ex:- java, utill, sql, lang

Which are included in java development kits

Java-package
Util-sub-package

Scanner-class

1) SUB PACKAGE:-
Package inside package is called as sub package

Note:-
We can also create a user defined sub package
Page No
 JAVA NOTES 
Date

We can use in-billed package in two ways

1. By using fully qualified

2. Import statement

1. BY USING FULLY QUALIFIED:-


By using fully qualified name compiler will understand to which package space filed class is available

There is one class name as scanner class is use to take input from user the fully qualified name is java. utill.

scanner
Create object for scanner class by using its fully qualified name

Java. utill. Scanner sc = new java. Utill. Scanner ([Link])

By using fully qualified name compiler will understand scanner class belong to java. Utill package

 DISADVANTAGES OF FULLY QULIFIED NAME:-


We need to use fully qualified name for any time whenever we accessing class and name

Readability is low
To overcome this we can use a class by using import statement

2. USING IMPORT STATEMENT:-

Import statement is use to import classes or interfaces present in specific package or sub package
Import java. Utill . scanner ;

By using import statement in state of using fully qualified name of class we can directly use class name

 RULL TO USE IMPORT STATEMENT:-

Import statement should be used before declaring a class

Import statement should end with semicolon (;)


We can use multiple import statement in one program or class

 ADVANTAGE OF IMPORT STATEMENT:-

We can directly use the class name instead of fully qualified name

By importing package one we can use class interface as many times as possible
Page No
 JAVA NOTES 
Date

Note:-

Java. lang package is implicitly import by compiler

Package should be the first statement in java program


A java source file should content package content

 ACCESS MODIFIRES:-

Access modifier a responsible to change modify the accessibility of members

We have four type of access modifier

1) Private

2) Default

3) Protected
4) Public

1) PRIVATE:-

It is a class level modifier it is applicable for variable method and constructer

If a member of class its prefix with private modifier then it is accessibility only within the class out-side the
class not possible

2) DEFAULT:-

The accessibility of default modifier is only within the package it can’t be access
If use don’t declare any access modifier then it is as consider as default access modifier

3) PROTECTED:-
The access level of protected modifier is within the package and outside the package throw child class

If you do-not make child class it cannot be access outside the package

4) PUBLIC:-
The access level of public modifier is any

It can be access within the class outside class within package outside package
Page No
 JAVA NOTES 
Date

 SCOPE OF AN ACCESS MODIFIER:-

Access Modifier Within Class Within Package Outside Package Outside Package By Children
Private True False False False

Default True True False False

Protected True True False True

Public True True True True

 TO SORT THE ARRAY USING INBILT SORT METHOD:-

In java . utill . arrays class we have a static method which can access the array
The sort method uses compare to method of comparable interface for sorting

There for the sort method can sort an array only

If all the element in array belongs to comparable type


All the element in array must be of same type
Note:-

Any one of the above condition are not followed then we will get class cast exception

 COMPARABLE INTERFACE:-
Comparable interface is functional interface (only one abstract method )

 MATHOD DECLARATION COMPARE TO METHOD:-

Public abstract int compareTo (object o)

 STEPS TO MAKE AN OBJECT COMPARABLE TYPE:-

STEP1:- The class must implement java. Lang comparable interface

STEP2:- Over ride compare to method

 COMPARE TO MATHOD:-
It is defied in comparable interface

This method is use to compare to object

The return type of compare to method is int


Page No
 JAVA NOTES 
Date

 WORK FLOW:-

If type value one object is greater than another object it will return position integer

If the value of one object is lesser than another object it will return negative integer
If value of one object is equal to another object it will return zero

Program:-

 STRING (LITTERAL):-
Anything unclosed in a double code in java will be consider as a string literal is used in a java program an

instants of java land string class is created inside string constant pull

For given string literal if the instants of string is already present then new instant is not created instead of

reference existing is given

 STRING:-
String is a data and group of character which is in-close within a double cote

It is a non-primitive data
In java data we can store a string by creating instance of following closes

i. Java. Lang. string class

ii. Java. Lang. string buffer


iii. Java. Lang. string bilder

In java whenever we create a string compiler implicitly create and instant of java. Lang. string in string

constant Pull (string pull)


package StringClass;
public class Test {
public static void main(String[] args) {
[Link]("Hello");//Hello
[Link]("Hello");//Hello
[Link]("hello");//hello
}
}
Page No
 JAVA NOTES 
Date

Diagram:-

package StringClass;
public class Test1 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "Hello";
[Link](s1);//Hello
[Link](s2);//Hello
[Link](s1==s2);//true
[Link]([Link](s2));//true
}
}

Diagram:-
Page No
 JAVA NOTES 
Date

 STRING CLASS:-

String is in bild class defined in java. Lang. object class

String class is a final class


String class inherits java. Lang. object class

In string class to string method equals method and hash code method of object class use over return it
implement

Comparable serializable and current sequence interface

package StringClass;
public class Test2 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = new String ("Hello");
[Link](s1==s2);//false
[Link]([Link](s2));//true
}
}
Diagram:-

package StringClass;
public class Test3 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "hello";
String s3 = new String ("Hello");
String s4 ="hello";
String s5 = new String ("Hello World");
[Link](s1=s3);//Hello
[Link]([Link](s3));//false
[Link]([Link](s4));//true
[Link]([Link](s5));//false
}
}
Page No
 JAVA NOTES 
Date

Diagram:-

package StringClass;
public class Test4 {
public static void main(String[] args) {
String s1 = "hello";
[Link]([Link]());//Hello
[Link](s1);//hello
}
}

Diagram:-
Page No
 JAVA NOTES 
Date

 CONSTRUCT IN STRING CLASS:-

CONSTRUCTER:-

Constructer Description
String() Create an empty string object

String(string literal) Create string object by initializing with string


String (char[]ch) Create string converting character array in to string

String(byte[]b) Create string by converting byte array into string

 METHOD OF STRING CLASS:-

Return Method Name Description

Type
String ToupperCase() Convert the special string upper case
String tolowerCase() Convert the special string lower case
String Trim() Remove the space precast before and after
String Substring(int,index) Extract char from string object start from special index and end

at the end at a string


String Concat(strings) Join the specified string
String Substring(int strat,int end) Extract char from a string from specified index ends at end

1-string

Char charAt(int index) Return char of the specified index from string

Int IndexOf(char ch) Return the index of the character specified if not return -1
Int IndexOf(char,ch,int, Return the index of the character specification by searching

start_index) from specified index if not return -1

Int indexOf(char, sequence start) Return the index of the specified string index if not return -1
Int IndexOf(char,sequence string Return the index of the specified string searching from specified

Int,strat_index) index if not return-1

Int lastIndexOf(char ch) Return the index of the character which is occurred at least in the

original string

Int Length() Return length of the string

Boolean Equals(object o ) Compare state of two string


Page No
 JAVA NOTES 
Date

Boolean equalsIgnorCase(string s) Compare state two string ignoring its case

Boolean Contains(string str) Return true if specified string is present else it returns false

Boolean IsEmpty() Return true if string is empty else return false

1) package StringClass;
public class Test5 {
public static void main(String[] args) {
String s1 = "Hello";
[Link]([Link]());//hello
}
}
2) package StringClass;
public class Test6 {
public static void main(String[] args) {
String s1 = "Hello";
[Link]([Link]("world"));//Helloworld
}
}
3)
package StringClass;
public class Test7 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]());//Hello
}
}

4)
package StringClass;
public class Test8 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link](1));//ello
}
}

5)
package StringClass;
public class Test9 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link](1, 4));//ell
}
}

6) package StringClass;
public class Test10 {
public static void main(String[] args) {
Page No
 JAVA NOTES 
Date

String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link](2));//l
}
}
7)
package StringClass;
public class Test11 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]('l'));//2
}
}

8)
package StringClass;
public class Test12 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]('e',1 ));//1
}
}

9)
package StringClass;
public class Test13 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]('o'));//4
}
}

10)
package StringClass;
public class Test14 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]('H'));//0
}
}

11)
package StringClass;
public class Test15 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]('l'));//2
}
}
Page No
 JAVA NOTES 
Date

12)
package StringClass;
public class Test16 {
public static void main(String[] args) {
String s1 = "Hello";
[Link](s1);//Hello
[Link]([Link]());//5
}
}

13)
package StringClass;
public class Test17 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "hello";
[Link](s2);//hello
[Link]([Link](s2));//true
}
}

14) package StringClass;


public class Test18 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "hello";
[Link](s1);//Hello
[Link]([Link]("ell"));//true
}
}
15) package StringClass;
public class Test19 {
public static void main(String[] args) {
String s1 = "Hello";
String s2 = "";
[Link](s1);//Hello
[Link]([Link]());//true
}
}

 CHARACTERISTICS OF STRING:-

The instance of string class is immutable in nature once the object is created then state cannot be modify
If we try to modify it will directly create new object and reference to the new object

 COMPARISEN OF STRING:-
1) ==Operator:- compares the reference
2) = Equal Method:- compare the state
3) Equal Ignore Case():- compare the state by ignore its case
Page No
 JAVA NOTES 
Date

4) Compare To Method:- compares the string and returns the integer value

 DISADVANTAGE:-
Because of in mutability for avery modification its create new object to overcome this problem we use string

buffer

Q Write A Java Program To Reverse The String


Program:-
package StringClass;
public class ReversString {
public static void main(String[] args) {
String s1 = "mangu";
String s2 = "";
for(int i=0; i<[Link]();i--) {
s2 = s2+[Link](i);
}
[Link](s2);
}
}
Diagram:-

 STRUNG BUFFER:-

It is a in bild defined in java. Lang package


String Buffer is a final class

It helps to create mutable instance of string

String Buffer does not have string constant root

Its inherit java. Lang. object class


In string Buffer only to string method is override equals and hash code method is not overridden

String Buffer implement serializable and char sequence interface


Page No
 JAVA NOTES 
Date

 CONSTRUCTER OF STRING BUFFER:-


1. No-Argument Constructer Buffer:-

Constructer Description
StringBuffer() Create string with initial capacity 16

StringBuffer(String str) Create string buffer with the specified string

package StringBuffer;
public class Test {
public static void main(String[] args) {
StringBuffer s2 = new StringBuffer("Bye");
StringBuffer s1 = new StringBuffer("Bye");
[Link](s2);//Bye
[Link](s1);//Bye
[Link](s1==s2);//false
[Link]([Link](s2));//false
}
}

package StringBuffer;
public class Test1 {
public static void main(String[] args) {
StringBuffer s2 = new StringBuffer("Hello");
[Link]("world");
[Link](s2);//Helloworld
}
}

 IMPORTANT METHOD OF STRING BUFFER:-

Return Method Name Description

Type

Int Capacity() Return current capacity

Int Length() Return length of string

char charAt(int inder) Return the character of specified index


String Buffer Append(string str) Join string cover loaded method

String Buffer Insert(int, index, string ) Insert a specified string into original string of specified index

cover loaded method

String Buffer Delete(int begin, int end) Delete string from specified beginning index to end -1index

String Buffer deleteCharAt(int index) Delete the character present in the specified index

String Buffer Revers() Revers the string letter


Page No
 JAVA NOTES 
Date

String Buffer Set length(int length ) Only specified length in a string is exist remaining get

remove

String Buffer Substring(int begin) Return the sub string from the specified beginning index
String Buffer Substring (int begine int end) Return the specified string from the beginning index to end

1 index
String Buffer Replace(int begin int end Replace a specified string from the beginner index to end

String s) -1 index

Void TrimtoSize() Remove the unused capacity of set the capacity till length at

The string

Void Set Char At(int index char Replace the new character in a string of specified index

new char)

1) package StringBuffer;
public class Test2 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link]());//21
}
}
2) package StringBuffer;
public class Test3 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link]());//5
}
}
3) package StringBuffer;
public class Test4 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](3));//l
}
}
4) package StringBuffer;
public class Test5 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](2, "ok"));//Heokllo
}
}
Page No
 JAVA NOTES 
Date

5) package StringBuffer;
public class Test6 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](1, 4));//Ho
}
}
6) package StringBuffer;
public class Test7 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](2));//Helo
}
}
7) package StringBuffer;
public class Test8 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link]());//olleH
}
}
8)
package StringBuffer;
public class Test9 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link](3);
[Link](s1);//Hel
}
}

9) package StringBuffer;
public class Test10 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](2));//llo
}
}
10) package StringBuffer;
public class Test11 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](1, 4));//ell
}
}
11) package StringBuffer;
public class Test12 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link](1, 4, "ok"));//Hoko
}
}
Page No
 JAVA NOTES 
Date

12) package StringBuffer;


public class Test13 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link]([Link]());//21
[Link]();
[Link]([Link]());//5
}
}
13)
package StringBuffer;
public class Test14 {
public static void main(String[] args) {
StringBuffer s1 = new StringBuffer("Hello");
[Link](2, 'W');
[Link](s1);//HeWlo
}
}

 CHARACTERISTICS OF STRING BUFFER:-


String is new table

For string buffer string constant pull is not applicable

 COMPARISON OF STRING BUFFER:-

==operator:- compare the reference


Equal():- compare to reference

 STRING BUILDER:-

String Builder in java is a class used to create a mutable or in other words a modifiable succession of characters

like string Buffer the string builder class is fan alternative to the java string class as the string class provides an

immutable succession of character

 USE THE CONSTRUCTOR:-

Constructor Description

String Builder() It constructs a blank string builder with a capacity of is character

String Builder(int capacity) It create and empty string builder with the specified capacity

String Builder(char sequence seq) It create a string builder with the same character specified as the argument

String builder (string str) It will construct a string builder with the string specified in the argument
Page No
 JAVA NOTES 
Date

 USE OF METHOD:-

Sting Builder append (string s)

String Builder insert (int offset string s)


String Builder replace (int start int end string)

String Builder delete (int short int end )


String Builder reverse()

Int capacity

Void ensurecpacity(int min)

charcharAt(int index)

Int length ()

String substring (int start)


String substring (int start int end)
Int indexof (string str)

Int lastindexof(string str)

Void trimTosize()

 EXCEPTION:-
The exception is a problem that occurs during execution of a program (runtime)
When an exception occurs the execution of a program stop abnormal (suddenly)

Note:-
Every exception in java is a class of throwable tip
Diagram:-
Page No
 JAVA NOTES 
Date

Note:-

Every exception is occurs because of statement

A statement will through and exception during abnormal situation

1) ARITHMATIC EXCEPTION :-
package Exception;
public class Test {
public static void main(String[] args) {
[Link]("Mani strart");
int a = 10;
int b = 0;
int res = a/b;//Arithmatic exception
[Link](res);
[Link]("main end" );
}
}

2) ARRAY INDEX OUT OF BOUNDS EXCEPTION:-

package Exception;
public class Test1 {
public static void main(String[] args) {
[Link]("main start");
int a[] = {10,20,30};
[Link](a[0]);
[Link](a[1]);
[Link](a[2]);
[Link](a[3]);//ARRAY INDEX OUT OF BOUNDS EXCEPTION
[Link]("main end");
}
}

3) STRINGI NDEX OUT OF BOUNDS EXCEPTION:-

package Exception;
public class Test2 {
public static void main(String[] args) {
[Link]("main start");
String a = "Hello";
[Link]([Link](5));//StringIndexOutOfBoundsException
[Link]("main end");
}
}

4) Null Pointer Exception:-


package Exception;
public class Test3 {
public static void main(String[] args) {
[Link]("Main String");
String a = null;
Page No
 JAVA NOTES 
Date

[Link]([Link]());//NullPointerException
[Link]("Main end");
}
}

5) CLASS CAST EXCEPTION :-


{
[Link]("Main String");
Scanner sc = new Scanner ([Link]);
int a = [Link]();
[Link](a);//Class cast Exception
[Link]("Main end");
}
}
6) INPUT MISMACH EXCEPTION:-

 TROWABLE CLASS:-

Throwable class is defined in java lang package


Throwable class is a parent class is all the exception classes

In all the exception classes to string method is already overridden such that it will return the fully callefied
name of the exception class

 IMPORTANT METHOD OF THROWABLE CLASS:-

getMessage():- return type is string

printstckTrace():-return type void


There are two type of exception

1) Checked
2) Unchecked exception

1) CHECKED EXCEPTION:-

The compiler aware exception is known as check exception

In checked exception compiler known the statement which is responsible for abnormal situation (exception)
There for compiler forces the programmer to either handle or declare the exception if it is not done we will

get compile time error

Eg:- file not bound exception


Page No
 JAVA NOTES 
Date

2) UNCHECKED EXCEPTION:-

The compiler unaware exception is known as the unchecked exception

In unchecked exception compiler doesn’t know the statement which is responsible for abnormal situation
(exception) hence compiler does not force the programmer to either handle or declare the exception

Note:-
In throw able hierarchy error class and sub classes runtime exception class and it sub classes are all consider as

a unchecked exception
All the subclasses of exception class except runtime exception is considered as checked exception

Throw able and exception class is partially check and partially unchecked

 EXCEPTION HANDLING:-
Exception handling is a mechanism used in java which is used to continue the normal flow of exception occur

during runtime

we can handle the exception using tray and cache block

Syntax:-

Try
{

Responsible statement

Cache (name Varname)

{ instruction

}
Page No
 JAVA NOTES 
Date

 Try:-

The statement which are responsible for exception should be return inside tray black

When an exception occurs


Execution of tray block is paused of

Throw able tip object is created


The reference of throw able tip of object is pass to the catch block

 CATH BLOCK:-

The catch block is used to catch the throw able tip reference thrown by the tray block

If it catches we say the exception is handle and the statement inside catch of program will continue

If it doesn’t catch we say the exception is catch block well not get execution and again program will slop
abstractly

package Exception;
import [Link];
public class Test4 {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
String s1 = null;
try {
[Link]([Link]());
}
catch(NullPointofException k ) {
[Link]("somthing went wrong");
}
}
}

When do we say exception is handled?

We say exception is handled only if exception is caught by catch block


Case 1:- exception occur not caught
Page No
 JAVA NOTES 
Date

Case 2:-Exception occur and caught

Try with multiple catch block:-

Try block can be associated with multiple catch block

Try
{
}

Catch()
{

Catch()
{

Note:-

The exception type object thrown from top to bottom order

 WORK FLOW:-

Try
{
Page No
 JAVA NOTES 
Date

Catch(----) 

{
}

Catch(----) If the exception is caught by the catch block then try block does not throw the exception
{ Object to the below catch block

Catch(---) 

The order of catch block should be maintained such that child type should be an the top and parent type at the
Bottom

Case1 Case 2

Try Try

{ 10/0; {10/0;
} }
Catch(exception e) Catch (arithmetic exception e)
{ {

} }
Catch(Arithmetic exception e ) Catch (exception e)

{ {

} }
CTE:- parent type is declare on the tip and CTE:- parent type declare on try bottom and child type is the top

Child top is on bottom

 EXCEPTION OBJECT PROPOGETION:-


The moment of exception from called method to calling method when it is not handle is known as exception

object program
Page No
 JAVA NOTES 
Date

 THROWS KEYWORD :-

Throw keyword is used to declare and exception to be thrown to the called throws keyword should be used in

Method declaration
Note:-

If methods declares and exception using throw keyword

Then caller of the method must handle or throw the exception if will not get compile time error
Program:-
package Exception;
public class Test5 {
public static void main (String[]args)
{
div ();
}
public static void div() throws RuntimeException
{
int a = 3;
int b =0;
int r =a/b;
[Link](r);
}
}

 FINALLY BLOCK:-

Syntax:-

Try

Catch()

{
Page No
 JAVA NOTES 
Date

Finally

1. Finally is a block which is used along with try and catch block

2. It will execute even the exception is handle and it will execute even the exception is not handle

 THROW KEYWORD:-

It is used to throw and exception manually

By using throw we can throw cheeked exception unchecked throw exception it is manly used to customize

Exception
Ex (Program):-
package Exception;
public class AlreadLogedInException extends RuntimeException {
public String getMassage() {
return "cannot login again...." ;
}
}
public void login(user u)
{
if(this.u==null)
{
this.u=u;
[Link]("login successfully");
}
else
{
throw new AlreadyLoggedInException ();
}
}

package Exception;
public class Test6 {
public static void main (String[]args){
[Link]("main Start");
String s1 = null;
if (s1 ==null){
throw new NullPointerException();
}
else{
[Link]([Link]());
}
}
}
Page No
 JAVA NOTES 
Date

 WRAPPER CLASS:-

The wrapper class in java provides a mechanism to wrap primitive in to an object

For avery primitive data type corresponding wrap class is declared


There are total 8th wrapper class declared in java long package

Primitive data type Wrapper Class


byte  Byte

short  Short

int  Int

long  Long

float  Float

double  Double
boolean  Boolean
char  Char

 BOXING:-

The process of wrapping primitive value in to corresponding wrapper class is known as boxing

 METHOD DECLARATION OF VALUE OF METHOD:-


Value method we help us to wrap primitive in to an object

Public static wrapper object value of (primitive value)


package Exception;
public class Test6 {
public static void main(String[] args) {
int a = 45;
[Link](a);//45
Integer i =[Link](a);
[Link](i);//45
[Link]("__________________________");
char ch = 'E';
[Link](ch);//E
Character j = [Link](ch);
[Link](j);//E
[Link]("----------------------");
boolean b1 = false;
[Link](b1);//false
Boolean b2 = [Link](b1);
[Link](b2);//false
}
}
Page No
 JAVA NOTES 
Date

 UNBOXING:-

The process of un-wrapping the wrapper clad object in to the primitive value

 VALUE METHOD:-

Value method with help us to un-wrapper the wrapper class object in to primitive value

Public int intvalue()

Public byte bytevalue()

Pubic short shortvalue()

Public long longvalue()


Public float floatvalue()

Public double doublevalue()

int a2 = [Link]();
[Link](a2);
char ch1 = [Link]();//un-boxing
[Link](ch1);

 PARSING:-
It is a process converting given string into primitive

Perform parsing we need to take a help of parse method which is present in all the 7th wrapper classes except
Character

 METHOD DECLARATION OF PARSE METHOD:-

PUBLIC STATIC VOID INT PARSEINT(STRING);


PUBLIC STATIC DOUBLE PARSEDOUBLE(STRING);

package WrapperClass;
public class Test {
public static void main(String[] args) {
String s1="10";
[Link](s1);
int a1 = [Link](s1);
[Link](a1);
}
}
Page No
 JAVA NOTES 
Date

Note:-

In parsing parse boolean method string should be in no format.

Else we will get no format exception.


package WrapperClass;
public class Test1 {
public static void main(String[] args) {
String s1="True";
[Link](s1);
boolean a1 = [Link](s1);
[Link](a1);
}
}

Note:-
If any data pass other than true we will get output as a false

AUTO BOXING:-

The process of implicitly converting a primitive value in to corresponding wrapper class object is known as auto

boxing

AUTO UNBOXING:-

The process of implicitly converting object in to primitive value is known as auto unboxing

 COLLECTION :-
PURPUS OF COLLECTION:-

Collection is used to store group of object together


To store group of object we generally use array but array has sum limitation which has as follow

The size of array is fixed we cannot reduce and increase the size of array dynamically during execution of

program

Array is collection of homogenous element array manipulation such as


Removing an element from array adding the element in-between array require complex logic to solve

There for to avoid limitation to array we can store in deferent data structure ex:- list, set, queue, map

COLLECTION FRAMWORK:-
Collection framework is a set of class of collection which provides mechanism to store group of object

(element)
Page No
 JAVA NOTES 
Date

It also provide mechanism to perform action

1. Create or add element

2. Access the element


3. Remove or delete the element

4. Search element
5. Update element

6. Sort element

There are two deferent hierarchy of collection interface

1. Collection hierarchy

2. Map hierarchy

COLLECTION INTERFACE:-
Collection interface is defined in java utill package

Collection interface provide sum mechanism to store group of object together

All the element in collection of stored in from of object (only non-primitive alive )
Which help to programmer to perform following task

1. Add or element in collection

2. Search the element in collection

3. Remove in element in collection


4. Access the element from collection
Page No
 JAVA NOTES 
Date

METHOD OF COLLECTION INTERFACE:-

Purpose Return type Description

Add an element Add (object)


Add All(collection)

Search an element Contains (object)


Contains All(collection)

Remove element Remove(object)

Remove All(collection)

Retain All(collection)

Clear()

Access element Iterator Iterator()


We can access element with the help of loop
Miscellaneous Size()

IsEmpty()

Hash code ()
Equals()

1. LIST:-

List is interface which is defined java utill package


It is a sub interface of collection interface of collection interface hence all the method in collection interface are

Inherit to list interface

CHARACTERSTIC:-
List is collection of object

Insertion order is mention in list

Indexing called in list hence we list adding, accessing, removing element using index

In list duplicates are allowed

METHOD OF LIST INTERFACE:-


Page No
 JAVA NOTES 
Date

Purpus Return type Method significands

Add an element 1. Add (object)

2. Add All(collection)

=================

3. Add(int index, object)

4. AddAll(int index,object)

Search an element 1. Contains(object)

2. ContainsAll(collection)

===================

3. Iindexof(object)

Remove an element 1. Remove(object)

2. RemoveAll(collection)

3. RemoveAll(collection)

4. Clear()

========================

5. Remove(int index)

Access an element Iterator 1. Iterator()

=====================

2. List iterator()

3. Get (int index)

Note:- we can access with the help of for each loop

Misscelle 1. Size()

2. Is Emty()
3.

4. hashCode()

5. equal()
package collectio;
import [Link];
public class Test {
public static void main(String[] args) {
ArrayList a1 = new ArrayList <>();
Page No
 JAVA NOTES 
Date

[Link](10);
[Link]("ok");
[Link](true);
[Link]('e');
[Link](10);
[Link](null);
[Link](a1);//[10,ok,true,e,10,null]
[Link](2, 8.5);
[Link](a1);//[10,ok,8.5,true,e,10,null]
ArrayList a2 = new ArrayList<>();
[Link](false);
[Link](5.4);
[Link](1, a1);
[Link](a2);//[false, 10, ok, true, e, 5.4]
[Link]([Link]("Ok"));//false
[Link]([Link](a1));//true
[Link]([Link]("true"));//-1
[Link]([Link]("ok"));//true
[Link](a1);
[Link](a2);//[false,ok,5.4]
[Link](a1);
[Link](a2);//[10,ok,true,e]
[Link]();
[Link](a1);//[]
[Link](1);
[Link](a1);//[10,true,e,10,null]
}
}

It is a concrete implement class at list interface

The characteristic of a array list is same as list

Array list is defined in java utill package


All the abstract method of list and collection interface is implemented

We can create the instance of array list and use all the method

CONSTRUCTER OF ARRAY LIST:-

It create an empty array list object

Array list(collection):-create an array list object and copy all the values from one collection another collection

Note:-
In array list to string method is over ridden instead of string return of array list it will return array list

ITERATOR :-

Iterator method belongs to iterator interface

Iterator method create iterator type object and return the reassurance
Page No
 JAVA NOTES 
Date

Iterator interface has two interface

1) hashnext()

This method is use to chaek whether there is element to be access from collection is present or
not

If present it will return true else it will return false


2) next()

This method is use to access the element and move the cursor to next element
package collectio;
import [Link];
import [Link];
public class Test1 {
public static void main(String[] args) {
ArrayList a1 = new ArrayList <>();
[Link](10);
[Link]("ok");
[Link](true);
[Link]('e');
[Link](a1);
Iterator i = [Link]();
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
[Link]([Link]());
}
}
NO SUCH ELEMENT EXEPTION:-
In the exception itratore when we tag to access the element using next method and it there is no element

present then we will get no such element exception

DISADVANTAGE:-

We can iterate only one we cannot access the element in-reverse order to overcame this this advantage we go

for list iterator

LIST ETRATOR:-
List iterator is a method which belongs to list interface

List iterator method create an object of list iterator type


Page No
 JAVA NOTES 
Date

LIST ITERATOR INTERFACE:-

Is a sub interface of iterator it is declared in java utill package

METHOD OF LIST ITERATOR:-


hasNext():-this method is used to cheak wheter next element to be excessed is present or not

Next():-this method gives the element from current position and move thecursal forward
has Privies():-this method is used to cheak wheter the priviuse element to be accessed is present or not

Privies():-gives the priviuse element of the curser and more the curser backword
package collectio;
import [Link];
import [Link];
import [Link];
public class Test2 {
public static void main(String[] args) {
ArrayList a1 = new ArrayList <>();
[Link](10);
[Link]("ok");
[Link](true);
[Link]('e');
[Link](a1);//[10, ok, true, e]
ListIterator l1 = [Link]();
[Link]([Link]());//true
[Link]([Link]());//10
[Link]([Link]());//true
[Link]([Link]());//ok
[Link]([Link]());//true
[Link]([Link]());//ok
[Link]([Link]());//true
[Link]([Link]());//10
[Link]([Link]());//false
[Link]([Link]());//NoSuchElementException
}
}

get(int index):-

package collectio;
import [Link];
public class Test3 {
public static void main(String[] args) {
ArrayList a1 = new ArrayList <>();
[Link](10);
[Link]("ok");
[Link](true);
[Link]('e');
[Link](a1);//[10, ok, true, e]
[Link]([Link](2));//true
}
}
Page No
 JAVA NOTES 
Date

For Each Loop():-

public class Test4 {


import [Link];
package collectio;
}

main(String[] args) {
public static void
}
0);
[Link](
for (object 0:a1){
true, e]
a1);//[10, ok,
[Link](
[Link]('e');
[Link](true);
[Link]("ok");
[Link](10);
ArrayList <>();
ArrayList a1 = new
Size():-

[Link]( [Link]() );

isEmpty():-

[Link]( [Link]() );

has Code():-

[Link]([Link]());

Equals():-

[Link]([Link]( a1 ));

We can classified the collection into two category


1. generic collection

2. non-generic collection

NON-GENERIC COLLECTION:-
Is a hetorogeneus (defferent type )collection of element every element is converted and stored as an inside

Non-generic collection

GENERIC COLLECTION:-
Is a homogeneus collection of element
package collectio;
import [Link];
public class Test4 {
public static void main(String[] args) {
ArrayList <Integer> a1 = new ArrayList <Integer>();
[Link](10);
[Link]("ok");//CTE
Page No
 JAVA NOTES 
Date

[Link](38);
[Link](89);
[Link](a1);
}
}

 LINK LIST:-

Link list is usre to store multiple value or group of value togather


Link list stors the data in the form of nodes where each node is longicaly connected to another node with the

help of address

We can add the element or remove the element in between the list very easily
CHARACTERISTIC OF LINK LIST:-
Inside order duplicate values

We can have duplicate values


We can add a null value

We can use indexing


Add exivision node Add next node
null object

package collectio;
import [Link];
public class Test5 {
public static void main(String[] args) {
ArrayList a1 = new ArrayList <Integer>();
[Link](10);
[Link]("ok");
[Link](true);
[Link]('e');
[Link](a1);
[Link](2, 7.5);
[Link](a1 );
}
}
0x1

null object 0x2


null

0x2

Null object 0x5


0x1 0x3
null
Page No
 JAVA NOTES 
Date

0x3

0x5 object 0x4


0x2 null

0x4

0x3 object
null

0x5

0x2 object 0x3

package collectio;
public class student {
int id;
String sName;
int std;
public student (int id,String sName,int std) {
[Link] = id;
[Link] = sName;
[Link] = std;
}
public String toString() {
return "Student id : " + id + "\nStudent Name : " + sName + "\nstd : " + std;
}
}
package collectio;
import [Link];
import [Link];
public class School {
student s;
Scanner sc = new Scanner ([Link]);
ArrayList<student> a = new ArrayList<student>();
String schoolName = "S. N. R. Highschool";
public void takeAdmission () {
[Link]("Enter the id for Admission");
int id = [Link]();
[Link]("Enter Student Name for Admission");
String sName = [Link]();
[Link]("Enter Standard");
int std = [Link]();
s=new student(id, sName, std);
[Link](s);
[Link]("Admission Are Done Successfully...");
}
public void cancelAdmission() {
[Link]("Enter the id For Cancel the Admission");
int id = [Link]();
for (student m : a) {
if (id==[Link]) {
Page No
 JAVA NOTES 
Date

[Link]([Link](s));
[Link]("Admission Cancelled Successfullyyy...");
return;
}
}
[Link]("its Id Does Not Exist");
}
public void displayDetails () {
[Link]("Enter the id For Access Details Of Student Admission");
int id = [Link]();
for (student m : a) {
if (id==[Link]) {
[Link]("School Name :--->>>"+schoolName);
[Link](m);
return;
}
}
[Link]("its Id Does Not Exist");
}
public void UpdateDetails () {
[Link]("Enter Id For Update Details");
int id = [Link]();
for (student m : a) {
if (id==[Link]) {
[Link]("What you Want To Update..\n1. Id\n2. Name\n3. Std\n4.
All");
int i = [Link]();
switch (i) {
case 1 : {
[Link]("Enter New Id");
int newId = [Link]();
[Link]=newId;
[Link]("Id succefully updated");
}
break;
case 2 : {
[Link]("Enter New Name");
String newName = [Link]();
[Link]=newName;
[Link]("Name succefully updated");
}
break;
case 3 : {
[Link]("Enter New Std");
int newStd = [Link]();
[Link]=newStd;
[Link]("Std succefully updated");
}
break;
case 4 : {
[Link]("Enter New Id");
int newId = [Link]();
[Link]=newId;
[Link]("Enter New Name");
String newName = [Link]();
[Link]=newName;
[Link]("Enter New Std");
Page No
 JAVA NOTES 
Date

int newStd = [Link]();


[Link]=newStd;
[Link]("All Details updated Successfully....");
}
default : {
[Link]("Enter Valid Choice");
}
}
return;
}
}
[Link]("its Id Does Not Exist");
}
}

package collectio;
import [Link];
public class SchoolDriver {
public static void main(String[] args) {
Scanner sc = new Scanner ([Link]);
School ref = new School ();
boolean condition = true;
while (condition) {
[Link]("Enter The Choice\n1. Take Admisssion\n2. Cancel Admission\n3.
Display Details\n4. Update Details\n5. Exit");
int choice = [Link]();
switch(choice) {
case 1 : [Link]();
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : {
condition = false;
[Link]("Its Closed Now :)");
}
break;
default : {
[Link]("Enter valid choice :(");
}
}
}
}
}

package collectio;
public class Account {
String name;
long acno;
String branch;
Page No
 JAVA NOTES 
Date

long cno;
double balance;
int pswd;
public Account(String name, long acno, String branch, long cno, double balance,int
pswd) {
[Link] = name;
[Link] = acno;
[Link] = branch;
[Link] = cno;
[Link] = balance;
[Link] = pswd;
}
public String toString() {
return "Account Holder Name : " + name + "\nAccount Number : " + acno + "\nBranch :
" + branch + "\nContact Number : " + cno;
}
}

package collectio;
import [Link];
import [Link];
public class Bank {
Account a;
Scanner sc = new Scanner ([Link]);
ArrayList<Account> ar = new ArrayList<Account>();
String bankName = "Indian Bank";
public void createAccount() {
[Link]("Enter The Name : ");
String name = [Link]();
[Link]("Enter The Account Number : ");
long acno = [Link]();
[Link]("Enter The Branch : ");
String branch = [Link]();
[Link]("Enter The Contact Number : ");
long cno = [Link]();
[Link]("Enter The Balence : ");
double balence = [Link]();
[Link]("Enter The Passward/Pin : ");
int pswd = [Link]();
a = new Account (name,acno,branch,cno,balence,pswd);
[Link](a);
[Link]("Account Created Successfully...");
}
public void cancelAccount() {
[Link]("Enter the Name And Passward For Cancelling Account");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]([Link](a));
[Link]("Admission Cancelled Successfullyyy...");
return;
}
Page No
 JAVA NOTES 
Date

}
[Link]("its Name/Passward Does Not Exist :(");
}
public void updateDetails() {
[Link]("Enter the Name And Passward For Update Account Details");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("Enter New Branch");
String newBranch = [Link]();
[Link] = newBranch;
[Link]("Enter New Contact Number");
int newCno = [Link]();
[Link] = newCno;
[Link]("Details Updated Successfully :)");
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
public void displayDetails () {
[Link]("Enter the Name And Passward For Display Account Details");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("Bank Name --->>>> "+bankName);
[Link](m);
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
public void changePassward () {
[Link]("Enter the Account Name And Old Passward For Change The
Passward");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("Enter new Passward");
int newPswd = [Link]();
[Link] = newPswd;
[Link]("Passward Changed Successfully :)");
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
public void withdrawAmount () {
Page No
 JAVA NOTES 
Date

[Link]("Enter the Name And Passward For Withdraw Amount");


[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("Enter Withdraw Amount");
double amt = [Link]();
if (amt <= [Link]) {
double remainingAmount = [Link] - amt;
[Link] = remainingAmount;
[Link]("Withdraw Successull....");
[Link]("-------------------------");
}
else {
[Link]("Insuficient Balance");
[Link]("-------------------------");
}
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
public void depositeAmount () {
[Link]("Enter the Name And Passward For Deposite Account");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("Enter Deposite Amount");
double depositeAmt = [Link]();
double remainingAmount = [Link] + depositeAmt;
[Link] = remainingAmount;
[Link]("Deposition Successull....");
[Link]("-------------------------");
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
public void displayBalance () {
[Link]("Enter the Name And Passward For Display Account Balance");
[Link]("Name : ");
String name = [Link]();
[Link]("Passward : ");
int pswd = [Link]();
for (Account m : ar) {
if ([Link]([Link]) && pswd==[Link]) {
[Link]("The Total Balance is : "+[Link]);
return;
}
}
[Link]("its Name/Passward Does Not Exist :(");
}
}
Page No
 JAVA NOTES 
Date

package collectio;
import [Link];
public class BankDriver {
public static void main(String[] args) {
Bank ref = new Bank();
Scanner sc = new Scanner ([Link]);
boolean condition = true;
while (condition) {
[Link]("Enter the choice\n1. Creat Account \n2. Cancel Account\n3.
Update Details\n4. Display Detalis\n5. Change Passward\n6. Withdraw Amount\n7.
Deposite Amount\n8. Display Balance\n9. Exit ");
int choice = [Link]();
switch(choice) {
case 1 : [Link]();
break;
case 2 : [Link]();
break;
case 3 : [Link]();
break;
case 4 : [Link]();
break;
case 5 : [Link]();
break;
case 6 : [Link]();
break;
case 7 : [Link]();
break;
case 8 : [Link]();
break;
case 9 : {
condition = false;
[Link]("Application Closed.....");
}
break;
default : {
[Link]("Something Went Wrong !!....Please Try Again");
[Link]("-------------------------------------------");
}
}
}
}
}

 VECTOR:-
Vector class is declear inside java utill package

It is implementation class of list interface

Vectore class internaly uses dynamic array to store the data

Vectore class is similar to array list class

Since vector is a implementation class of list interface data will be stored in to sequential manner and we can

store null as well as duplicate value


Page No
 JAVA NOTES 
Date

STACK:-

Stack is sub class of vector class

Stack is decleard inside java utill package


Stack internaly follows stack data structure

Stack works on first in last out principle


IMPORTANT METHODS OF STACK CLASS:-

Puss(object o) This method is use to add the new element at the top of the stack

Pop() This method is use to remove the and element from the top of stack

Search() This method is use to search the element position of an object the position will

allocated then from top


Is Empty() This method is use to cheak whether the stack is empty or not
Peek() This method is display the element which is present top of stack

package Stack;
import [Link];
public class Test {
public static void main(String[] args) {
Stack s1 = new Stack ();
[Link](false);
[Link](34);
[Link]("ok");
[Link]('f');
[Link](s1);
[Link]();
[Link](s1);
[Link]([Link]("ok"));
[Link]([Link]());
[Link]([Link]() );
}
}

 SET:-

Set is interface and it is a sub interface of collection interface therefor all the method of collection are inheret

to set interface

Set is defined in java utill package

CHARACTER OF SET:-
Set does not allow duplicate element
Page No
 JAVA NOTES 
Date

Set does not have indexing therefor

we cannot access insert or remove the element based on index

We can access the diamond of set by using


i. Iterator

ii. For each loop


HASH SET:-

It is a concrete implementing class of set interface

It has all the method inherited from collection as well as set interface

CHARACTER:-

In hash set inserted order is not men tend

Duplicate are not allow in hash set


We cannot access search remora and add element with help of index in hash set
In has set only one null is allow

CONSTRUCTERS OF HASH SET:-

HASH SET():-

This constructer is use to create empty object of hash set


HASH SET(COLLECTION):-
This constructer is use to copy all the value from one collection to another

package Stack;
import [Link];
public class Test1 {
public static void main(String[] args) {
HashSet h1 = new HashSet<>();
[Link](23);
[Link](false);
[Link]('f');
[Link]("Hello");
[Link](false);
[Link](null);
[Link](null);
[Link](h1 );
}
}

Note:-

Set a identify duplicate based on equals method


Page No
 JAVA NOTES 
Date

LINK HASH SET:-

It is concrete implementing class of set interface

It has all method inherited from collection Interface as well as set interface
CHATRACTERISTICS OF LINK HASH LIST:-

The insershion is mentained in link hash set


In link hash set we cannot add duplicate

No indexing therefor we cannot access the element using index

Only one null is allow

package Stack;
import [Link];
public class Test2 {
public static void main(String[] args) {
LinkedHashSet l1 = new LinkedHashSet<>();
[Link](45);
[Link](true);
[Link]('r');
[Link]("ok");
[Link](null);
}
}

TREE SET:-
Tree set is a concrite incrementing class of set interface

Tree set will also have all the method of collection interface
CHARACTER:-

The element will be sorted by defolt in tree set the element to be add in the tree set must be comparable type

else we will get class cast exception

All element in tree set should be of same type (homogineus)

Duplicate element are not allow in tree sate we cadn not use index in tree
We cannot add null value in tree set or else we will get null pointer exception

CONSTRUCTER:-

TREESET():-

It create empty object of tree set

TREEESET(COLLECTION):-

This constructer is use to copy all the value from one collection to tree set
Page No
 JAVA NOTES 
Date

package Stack;
import [Link];
public class Test3 {
public static void main(String[] args) {
TreeSet l1 = new TreeSet<>();
[Link](45);
[Link](true);
[Link]('r');
[Link]("ok");
[Link](null);
[Link](l1);
}
}

 QUEUE:-
Queue injterface is a type of collection interface

Queue interface can be used to perform opration first in first out


Queue interface is having two implementation

i. Link list

ii. Priority queue


METHOD OF QUEUE:-

Offer(object o) This method is use to add dimend in the queue


Peek() This is method will return the head of queue first object if the queue is empty it will
return the null value

Element() This method is used to return the head of queue if queue is empty it will return null

value

Remove() This method is use to remove the head of the queue if the queue is empty it will return

Nosuch element [Link]


PRIORTY QUEUE:-

Priority queue is a implementation of class of queue interface

Priority queue can be used to perform operation in such maner which mines smallest element will be remove

first

We can add duplicate element in the queue

We cannot add null value if we try to add will get null pointer exception
Page No
 JAVA NOTES 
Date

In priority queue insertion order is not maintained

package collectio;
import [Link];
public class Test7 {
public static void main(String[] args) {
PriorityQueue q1 = new PriorityQueue<>();
[Link](10);
[Link](78);
[Link](45);
[Link](56);
[Link](q1);
[Link]();
[Link](q1);
[Link]();
[Link](q1 );
}
}

 MAP:-

Map is an interface which belongs to java. util Package


With the help of Map we can store the data in the form of key and value

pairs.
Key cannot be duplicate.

Value can be duplicate.

Method Signature Task

put(key,value) It is use to add an entry into the Map. If key is already present the old value will

be replaced with new value.

putAll (Map) This method is used to add entries in the existing Map into the current Map

Get(key) This Method will return the value associated with a particular key.

keySet( ) This Method returns a set of keys


Page No
 JAVA NOTES 
Date

values( ) This method returns a list of values .

containsKey() It will return true or false (boolean return type).

containsValue() It will return true or false Value is present -> true Value is not Present -> false
entrySet() It will return a set of key = Value pairs

size() It will return number of entries in a Map.


clear() It is use to remove all the entries from Map.

HASHMAP :

It is a concrete implementing class of Map interface

It is defined in java . util Package.


All the methods of Map interface will be inherited to HashMap.

The order of insertion is not maintained.

The data will be stored in the form of key=value pairs


Key cannot be duplicate.
Value can be duplicate.

Key can be null.


Value can be null

CONSTRUCTORS OF HASHMAP :
HashMap It will create empty HashMap object

HashMap() It will create HashMap object and copies all the entries from passed Map into newly created

Map.

Note : We can create generic Map by specifying the type of key end value.

TREEMAP:-
It is a concrete implementing class of Map interface.

The order of insertion is not maintained.

The entries will be sorted in ascending order with respect to keys.

Keys must be of same type else we will get ClassCastException.

Key cannot be null or we will get NullPointerException.

Value can be null.


CONSTRUCTORS OF HASHMAP :
Page No
 JAVA NOTES 
Date

TreeMap It will create empty TreeMap object

TreeMap() It will create TreeMap object and copies all the entries from passed Map into newly

created Map.

HASHTABLE :

It is concrete implementing class of Map interface.

Order of insertion is not maintained.

Key as well as value cannot be null or we will get NullPointerException.

CONSTRUCTORS OF HASHTABLE :

HashTable It will create empty HashTable object

HashTable() It will create HashTable object and copies all the entries from passed Map into newly

created Map.

 MULTI-TREADING:-

Exicuting multiple sub tasking and sub process simaltaniusly by multiple thread is known as multi treading

A thread is a light waight sub-process and small unit processing

MULTI-PROCESSING:-

Exicution multiple processing symelteniusly by using multiple processor is known as multiprocessing

Multiprocesing can be done as os level

THREAD CLASS:-

Thread class is declear inside java lang package

Multithreading in java declear inside java lang on thread class

Thread class provide sevral method to achive multi-threading

RUNNEBLE INTERFACE:-

Runnable interface is also declared in java lang package it is a functional interface which content only one

abstraction method

Thread class interface runnable interface we can create a thread by using two way

1. Using runnable interface

2. Using thread class


Page No
 JAVA NOTES 
Date

THREAD LIFE CYCLE:-

NEW :-

If develop create new thread then respected thread will be presented at new state

RUNEBLE:-

If developer calls start method and thread will enter in to runnable state it means thread is ready for

execution but not get execution

Thread scheduler will be reuses

RUNNIG:-

Thread scheduler select one thread for execution and thread will inter in running state

At a time only one thread will be available in running state

NON-RUNNABLE:-

The thread execution is suspended by thread scheduler for particular time period

Then thread will inter in to non-runnable state

DEAD:-

After successful execution thread will enter into dead state

In other word the thread will successfully execution JVM is automatically terminated into specific thread

THREA SHEDULAR:-

Thread scheduler is important mechanism for multi-threading

Thread scheduler is responsible to declare the execution flow of an threads.

Thread scheduler randomly select only one thread for execution

MAIN THREAD :-

Avery java programmer will be execution by thread

JVM create the thread to start the execution of java programing


Page No
 JAVA NOTES 
Date

Thread create by JVM is known as main thread and it will automatically created

Execution is other thread pearly depend on main thread

Developer can create only number of executional thread with the help of main thread

Developer can create only number of execution thread with the help of main thread

IMPORT METHOD OF THREAD CLASS:-

Run():- perform the task of thread which is return inside run method

State():-it invers the run method

Sleep():-this method will pass execution for given mile-second

Stop():-it will stop the execution of thread

Current thread():- this method will return the object current thread

Getname():- this method return the name of thread

Setname():- this method can modify the name of a current thread

Getid():- this method return the id of thread

You might also like