0% found this document useful (0 votes)
38 views78 pages

Notes Batch 1215 Lyst1738575352991

The document outlines a series of lessons on Java programming, covering topics such as the definition of software and hardware, features of Java, keywords, data types, variables, operators, and control statements. It includes explanations of object-oriented programming principles, Java's syntax, and the use of the Eclipse IDE. Each session emphasizes attendance marking and provides examples to illustrate the concepts discussed.

Uploaded by

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

Notes Batch 1215 Lyst1738575352991

The document outlines a series of lessons on Java programming, covering topics such as the definition of software and hardware, features of Java, keywords, data types, variables, operators, and control statements. It includes explanations of object-oriented programming principles, Java's syntax, and the use of the Eclipse IDE. Each session emphasizes attendance marking and provides examples to illustrate the concepts discussed.

Uploaded by

Sidra Kalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 78

/*-----------------------------------------*/

13-11-2024

- IT -> Information Technology

- Software / Application

- Coding - Flow of Application


- Program - Set of Instructions - (Procedure / Receipe) - Step By Step -
(Algorithm)
- Software / Application - Collection of Programs - Group of Programs
- the things which you can not touch
physically but you can used it.
- Hardware - the things which you can touch physically but you can used it.
- Developer / Programmer - who writes a program
- Tester - who test the program
- Editor / IDE - Integrated Developement Environment - Eclipse
- Language - Communication - System - (Java)
- Grammar - Rules - S + V + O - Syntax
- Speak()
- Read()
- Write()

/*--------------*/

14-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Features of Java

- Language - Communication - System - Java


- Grammar - Rules - Syntax
- Speak(), Read(), Write();
- S + V + O
- Syntax
class {

e.g
class Student{

- Features of Java
a) Simple
- Mayur - English - String, out, Runnable , System
b) Platfform Independent
- Write Once Run AnyWhere
- Platfform - Operating System (OS)
- Windows, Linux, IOS
- Extension - by which the operating system can identify the type of file
c) Portable
-
d) Object Oreineted Programming
e) Secure
f) Robust
g) High Performance
h) Multi-Threading
i) Dynamic
j) Distributed
k) Architecture Neutral
l) Open Source
-
m) Free
-
/*-------------------*/

15-11-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Features of Java

a) Simple
b) Platfform Independent
c) Portable
d) Free
e) Open Source

1) Dynamic
2) Multi-Threading
3) Robust - Grabage Collector
4) Object Orieneted Programming (OOPs)
5) Secure

-: Features of OOPs

a) class
- It is a logical entity.
b) Object
- It is a real world entity.
c) Encapsulation
- To secure the data
d) Inheritance
- To access other class properties
e) Polymorphism
- To change behaviour as per the requirement
- Method Overloading
- Method Overriding
f) Abstraction
- To hide data show required things
g) Dynamic
- To import other language program
h) Multi-Threading
- To execute many parts of a code of one program at a same time
i) Message Passing
- By using object you can pass message to method

-: JDK - Java Developement Kit


- libraries
- documents
-: JRE - Java Runtime Environment
- libraries
-: JVM - Java Virual Machine (interpreter)

/*-----------------*/

18-11-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Keywords In Java

-: JIT Compiler
- Just In Time Compiler
- It introduce in java-1.2
- It will help JVM to execute native code fastly

-: Keywords
- It is a predefine words
- you can not change the meaning of those words
- you can not used those words anywhere else
- total 53 keywords in java

-: Userdefine Words

1) It will starts with letter only


e.g
int y; double price;

2) You can not used special symbols - except underscore [ _ ] and dollar [$]
e.g
int y_4; double book$price;
long w%t; // Error

3) It will not starts with number.


e.g int age_123;
long 123_price; //Error

4) You can used number as suffix.


e.g
int age_123;
long 123_price;//Error

5) No limit for length of characters


e.g
long dddddddddddddddddddddd=1;
print(dddddddddddddddddddddd);

6) Used short and meaningful name;


e.g
int d=30;
int student_age=30;

7) Java is a case sensitive language.


e.g
int time; int Time; int TIME;

8) Java is UNICODE based language.


ASCII - 0 to 255 (256)
Unicode - 0 to 65535
a - 97
A - 65

z - 122
Z - 90

0 - 48
- 32

/*--------------*/

19-11-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Eclipse Installation

/*--------------*/

20-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Data Type

/*--------------*/

21-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Data Type

- Data - Information
- Type - Format

- Source Code - *.java


- Byte Code - *.class

- *.pdf - Portable Document Format


- Word - *.docs
- Photo - *.jpeg, *jpg, *.png, *.csv
- Video - *.mp4
- Audio - *.mp3

/*--------------*/

-: https://thekiranacademy.com/tutorials/corejava/java-language.php#gsc.tab=0

-: https://thekiranacademy.com/test/

22-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Variables

Building No-2, 1260 Deccan, J M Road, 2nd Floor, Near Modern Collage, The Kiran
Academy

-: Name of Building

-: Variable
- it is a name of memory location, which is used to access and update the value

-: syntax
data_type variable_name=value;
e.g
int y=1000;

data_type variable_name;

variable_name=value;
e.g
long h;
h=5000;

a) primitive variable
- byte b1=100;
- boolean g1=false;
- double dd=55.11;

b) non-primitive variable (reference variable)


- class Demo{
Demo d1=new Demo();
Demo d2;
}

class Demo{
byte b1;
long h1;
int y1;
String s1;
Demo d3;
double dd;
boolean ss;
short aa;
Demo dc;
char t1;
float z1;
}

WorkSpace -> Project -> Src -> package -> class

-: Question
a) what is difference between primitive variable and reference variable

/*-------------------*/
- javabykiran tutorials
-: https://thekiranacademy.com/tutorials/corejava/java-language.php#gsc.tab=0

- javabykiran test
-: https://thekiranacademy.com/test/

25-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Variables

-: Data Type

a) primitive variable
b) reference variable

-: position

a) instance variable
- the variable which is declare inside the class and outside the method,
constructor and block is called as instance variable
- it is an object level variable
- it has different copy for each object
- the memory alocation done when object is created
- memory dealocation done when object will destroy
- all access_modifiers are applicable
- final modifier is applicable
- compiler will give default value to the variable if not assign the value while
declare
- e.g
class A{
int y=100;
public static void main(String []args){
A a1=new A();
System.out.println(a1.y);
}
}

-> name,city,course,age

b) static variable
- the variable which is declare inside the class and outside the method,
constructor and block but having a prefix as static is called as static variable
- it is an class level variable
- it has single copy for a class and that copy will share to all resources of a
class
- the memory alocation done when class is loaded into memory
- memory dealocation done when class will unloaded from memory
- all access modifiers are applicable
- final modifier is applicable
- compiler will give default value to the variable if not assign while declare
- e.g
class A{
static int y=100;
public static void main(String []args){
System.out.println(A.y);
}
}

- Note -: it is recommended that to access static variable and method by using


class_name
c) local variable
- the variable which is declare inside the method, constructor and block is called
as local variable
- it is an block level variable
{

}
- the memory alocation done when method is execution start
- memory dealocation done when method execution will terminate
- only final modifier is applicable
- compiler will not give default value to the variable if not assign while declare
- e.g
class A{
public static void main(String []args){
int y=100;
System.out.println(y);
}
}

- method parameters are local variable to the method

d) final variable
- the final modifier is used to declare the variable is called final variable
- if variable is final then you can not change its value
- it is only modifier which is applicable to local variable
- e.g
class A{
final String s1="Mango";
public static void main(String []args){
final int y=100;
System.out.println(y);
A a1=new A();
System.out.println(a1.s1);
}
}

public class Demo{


int y=100;//instance and primitive variable

static String d1="Mango"; //static and reference variable

final static char ch1='T';//final, static and primitive variable

static double d2=33.11l//static and primitive variable

boolean b1=false; //instance primitive variable

final long ss=3000;//final, instance and primitive variable

public static void main(String []args){


String s1="Apple"; //local and reference variable

final int tt=500; //local,primitive and final variable

final String sd="Banana"; //final, reference and local variable

short s1=5;//local and primitive variable


}
}

/*---------------*/

26-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Operators in Java

-: Operators
- who perform some action on variable or constant value
-: Operand
- on which the operator perform some action
-: Types of Operators

a) Arithmetic Operator (5)

1. Addition [+]
2. Subtraction [-]
3. Multiplication [*]
4. Division [/] - it will divide a number
5. Moduls - Mod [%] - it will give remainder - it will not divide a number

BODMAS

- all arithmetic operator is applicable to all numerical data type


- even it is also applicable to char data type
- it is not applicable to boolean data_type
- [+] - Only this operator you can used for to join the String

->
b) relational operator (comparison operator) (6)

1. less than - [<]


2. greater than - [>]
3. less than equal to - [<=]
4. greater than equal to - [>=]
5. equal to - [==]
6. not equal to - [!=]

- result type -: boolean (true/false)


- this relational operator is applicable to all numerical data_type and character
also
- only == and != operator is applicable to String and boolean data_type
- it is used to make a condition

c) logical operator (3)


- it is used to join more than one condition

1. and - [&&]
2. or - [||]
3. not - [!]

- and [&&]
T T -> T
F T -> F
T F -> F
F F -> F

- or [||]
T T -> T
F T -> T
T F -> T
F F -> F

- not [!]

T -> F
F -> T

d) assignment operator (6)

1. assignment operator - [=]


int y=10;
int h=y;
print(h);

2. int g=4;
print(g);
//g=g+5;
g+=5;//=> g=g+5;
print(g);

3. int y=10;
//y=y-4;
y-=4;//=> y=y-4;

4. int h=6;
h*=5;//h=h*5;

5. long d=600;
d/=10;//d=d/10;

6. int b=15;
b%=2;//b=b%2;

e) increment / decrement operator (2)


(++) (--)

- increment - the value will increment by 1


- post increment -: first used the value and then increment it
int y=10;
print(y);
y++;//y=y+1;
print(y);

- pre increment -: first increment the value and then used it


int h=5;
print(h);
++h;
print(h);

- decrement - the value will decrement by 1


- post decrement -: first used the value and then decrement it
int f=5;
print(f);
f--;
print(f);

- pre decrement -: first decrement the value and then used it


long h=10;
print(h);
--h;
print(h);

e.g
int h=100;
print(h);//100
h--;
print(h);//99
h++;
print(h);//100

int a=10,b=5,c=8;

int d=a+b+c;
print(d);//23

a=10;b=5;c=8;
d=(a+b)*2-c;
print(d);//22

a=10;b=5;c=8;
d=(a+b--)-c+b;
print(d);//2 , 11, 1,

a=10;b=5;c=8;
d=a+(++b)/2*10- --b+ ++c;
print(d);//91, 35, 44

long d=55;
print(d);//55
print(d--);//54
print(--d);//54

int h=22;
print(h);//22
print(++h);//23
print(h++);//23,24

f) conditional operator (Ternary Operator)


-syntax
result=(condition)?expression_1:expression_2;
e.g
String s=(100==55)?"Apple":"Cherry";
print(s);

g) bitwise operator

1. and -: &
2. or -: |
3. xor -: ^
4. left shift -: <<
5. right shift -: >>
6. not -: ~
int a=10,b=5,c=8;
d=a+(++b)/2*10- b-- + ++c;

/*--------------*/

27-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Control Statements in Java

-: Scanner class
- it is final class
- it is present in java.util package
- it is used to accept the value from user or read the text file
- object
Scanner scan=new Scanner(System.in);
- it introduce in java-1.5

- following method is used to accept value from user


a) byte -> nextByte();
b) short -> nextShort();
c) int -> nextInt();
d) long -> nextLong();
e) float -> nextFloat();
f) double -> nextDouble();
g) char
h) boolean -> nextBoolean();
i) String -> next() /nextLine();

-> Control Statement


- it is used to control the flow of execution of program
- types of control statement
a) selection control statement
b) looping control statement
c) transfer control statement

a) selection control statement

- if...else
- syntax
if(condition){
//if block
}else{
//else block
}

1. check the number is +ve or -ve


2. check the number is even or odd
3. check the number is divisible 3 or not
4. check the number is divisible 3 and 5

- else..if ladder

if(condition){

}else if(condition)
else{

--
if(condition){

}else{
if(condition)
}

double per=70;
per >= 75 - "A1";
per < 75 and per >=65 - "A2";
per < 65 and per >=55 - "B1";
per < 55 and per >=45 - "B2";

- switch...case
- syntax
switch(expression){
case 1:

break;
case 2:

break;
case 3:

break;
default:

break;
}
- expression - int ,char, String
/*--------------*/

28-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Control Statements in Java

b) looping control statement

- it is used to repeat the block of code till the condition is true

- initialization
- condition
- update_value

1) for loop
-syntax
for(initialization; condition; update_value){
//for loop block
}
e.g
int k=1;
for(k=1; k<=10; k++){
print(k);
}

2) while loop
initialization
while(condition){
//while loop block
update_value
}

e.g
int g=14;//initialization
while(g<=34){
print(g);
g++;
}

3) do while loop

initialization
do{
//do while loop block
update_value
}while(condition);

e.g
int d=6;
do{
print(d);
d++;
}while(d<=16);

1. print the number from 2 to 44 used for loop


2. print the number from 55 to 11 used while loop
3. print the number 33 to 11 used do while loop
4. print the number from 1 to 50 used for loop increment by 4
5. print the number 33 to -11 used do while loop decrement by 3

c) transfer control statement

1. break
- it will terminate the loop - if condition is true
2. continue
- it will skip the current iteration of loop - if condition is true

- position
-: code before the statement
-: condition for the statement
-: code after the statement

6. print the number from 44 to 88 and stop loop at 57 - used for loop
7. print the number from 101 to 145 and do not print number divisible by 4 - used
while loop
8. print the square from 1 to 10
for(int k=1;k<=10;k++){
int c=k*k;
print(c);
}

9. print the cube from 1 to 10


10. print the square of even number from 1 to 10
for(int k=1;k<=10;k++){
if(k%2==0){
int c=k*k;
print(c);
}
}

11. print the cube of even number from 1 to 10


12. print the sum of 1 to 10 number

int sum=0;
for(int k=1;k<=10;k++){
sum=sum+k;
}
print(sum);

13. print the product of 1 to 10 number


14. print the sum of even number from 1 to 10
15. print the product of even number from 1 to 10

/*--------------*/

29-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Practical of Loop

-: Pattern in Java

a)
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

R-5
C-5
R-C-5

for(int r=1;r<=5;r++){
for(int c=1;c<=5;c++){
print("*");
}
println();
}

b)
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5

c)
A B C D E
A B C D E
A B C D E
A B C D E
A B C D E

R-5
C-5
R-C-5

char ch='A';
for(int r=1;r<=5;r++) {
ch='A';
for(int c=1;c<=5;c++) {
System.out.print(ch+" ");
ch++;
}
System.out.println();
}

d)
# * * * #
# * * * #
# * * * #
# * * * #
# * * * #

R-5
C-5
R-C-5

for(int r=1;r<=5;r++){
for(int c=1;c<=5;c++){
if(c==1 || c==5){
print("#");
}else{
print("*");
}
}
}

e)
# # # # #
* * * * *
* * * * *
* * * * *
# # # # #

R-5
C-5
R-C-5
f)
# # # # #
# * * * #
# * * * #
# * * * #
# # # # #

R-5
C-5
R-C-5

g)

*
* *
* * *
* * * *
* * * * *

R-5
C-5
R-C-> R=C

for(int r=1;r<=5;r++){
for(int c=1;c<=r;c++){
print("*");
}
println();
}

h)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

i)

A
A B
A B C
A B C D
A B C D E

j)

*
* *
* * *
* * * *
* * * * *

k)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
l)
A
A B
A B C
A B C D
A B C D E

m)

*
* *
* * *
* * * *
* * * * *

R-5
C-5
R-C-> R=C

int space=5;
for(int r=1;r<=5;r++){
for(int k=1;k<=(space-r);k++){
print(" ");
}
for(int c=1;c<=r;c++){
print("*");
}
println();
}

n)
A
A B
A B C
A B C D
A B C D E

o)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

p)
* * * * *
* * * *
* * *
* *
*

R-5
C-5
R-C- R!=C

for(int r=5;r>=1;r--){
for(int c=1;c<=r;c++){
print("*");
}
println();
}

q)

# * * * #
# #
# #
# #
# * * * #

------>>------

->
*
* *
* * *
* * * *
* * * * *

int space=5;
for(int r=1;r<=5;r++){
for(int k=1;k<=(space-r);k++){
System.out.print(" ");
}
for(int c=1;c<=r;c++){
System.out.print("* ");
}
System.out.println();
}

/*--------------*/

30-11-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Number Program In Java

int n=1234;
print(n);//1234
int y=n%10;
print(y);//4
n=n/10;
print(n);//123

y=n%10;
print(y);//3
n=n/10;
print(n);//12
y=n%10;
print(y);//2
n=n/10;
print(n);//1

y=n%10;
print(y);//1
n=n/10;
print(n);//0

1. print the each digit of number


int n=1234;
int y=0;
while(n>0){
print(n);
y=n%10;
print(y);
n=n/10;
}

n y
1234 4
123 3
12 2
1 1
0

2. print the square of each digit of number


3. print the cube of each digit of number
4. print the even digit of number
int n=1234;
int y=0;
while(n>0){
y=n%10;
if(y%2==0)
print(y);
n=n/10;
}
5. print the odd digit of number
6. print the number in reverse
int n=1234;
int y=0;
O/P -> 4321
int rev=0;
while(n>0){
y=n%10;
rev=(rev*10)+y;
n=n/10;
}
print(rev);

n y rev
1234 4 4
123 3 43
12 2 432
1 1 4321
0
7. write a program to check the number is palindrome or not
int n=212;
int y=0;
int t=n;
while(n>0){
y=n%10;
rev=(rev*10)+y;
n=n/10;
}
if(t==rev)
print("palindrome");
else
print("not palindrome");

8. write a program to check the number is prime number or not


int n=5;
n%1=0
n%2=1
n%3=2
n%4=1
n%5=0
int count=0;

for(int k=1;k<=n;k++){
if(n%k==0)
count++;
}
if(count==2)
print("prime number");
else
print("not prime number");

9. Fibo Series
0 1 1 2 3 5 8 13.....

int n1=0,n2=1,n3=0;
print(n1+" "+n2);
for(int k=1;k<=5;k++){
n3=n1+n2;
print(n3);
n1=n2;
n2=n3;
}

n1 n2 n3 k
0 1 1 1
1 1 2 2
1 2 3 3
2 3 5 4
3 5 8 5
5 8 6

/*--------------*/

02-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Method In Java

public static void main(String []args){

- it is a sub program
- it will divide a large program into a small program
- syntax / method_proptotype / method_signature

access_modifiers return_type method_name(parameter_list){

}
e.g
public void total(int a,int b){

- access_modifiers - public
- return_type - void
- method_name - total
- method_name is identifier
- parameter - int a,int b

- types of method
a) instance method
b) static method

1. write a method to check number is even or odd - pass number as parameter


2. write a method to check number is divisible by 3 and 5 - pass number as
parameter

public void m1() {

- void means nothing - not even 0 and null

3. write a static method to print even number from 1 to 10


4. write a static method to print cube number from 30 to 10

-: Note - it is recommended that to access static variable and static method by


using class_name

5. write a static method to perform cube of number - pass number as parameter


6. write a static method to return square of number - pass number as parameter
7. write a method to print sum of 1 to 10 number
8. write a method to return product of 1 to 10 number
9. write a program to accept option and perform task (menu-Driven)
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Mod

-: Question
a) what is method
b) explain types of method and variables
/*--------------*/

03-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Methods in Java

1. write a method to calculate sum from 1 to 10


2. write a static method to return product from 1 to 10;
3. write a method to print count a digit of number - pass number as parameter
public void countDigit(int a){
int count=0,n=0;
while(a>0){
n=a%10;
count++;
a=a/10;
}
print(count);
}
4. write a method to print cube of each digit of number - pass number as parameter
5. write a static method to return calculate power - pass number as parameter
e.g
int base=4;
int power=5;
public static int getPower(int base,int power){
int result=1,k=1;
while(k<=power){
result=result*base;
k++;
}
//print(result);
return result;
}

6. create a class Student


- define property of student - name and age
- define a method to accept student properties
- define a method print properties of student

- create a class StudentDemo


- define a main() method
- call Student class method

7. create a class Book


- define property of book - book_name, book_price;
- define a method to accept book properties
- define a method print properties of book

- create a class BookDemo


- define a main() method
- call Book class method

/*--------------*/

04-12-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: package in Java

-: package
- it is a collection of classes and interfaces
- it is a folder (directory)
- syntax
package package_name;
e.g
package demo;
package com.jbk.test;
- com - it is a root package
- jbk.test - it is a sub package
- package will not create a class
- generally package_name define in lower case letter
- only one package statement in one java file
- it should be the first statement of java file
- you can create many package in one project
- you can create many classes and interfaces in one package
- advantage
a) it is used to avoid naming confusion of classes or interfaces
b) it will help to maintain the code
c) it will increase the reusability of code
d) so it will reduce time consumption

-: import
- it will import class or interface
- it will not import package
- syntax
import package_name.class_name;
or
import package_name.interface_name;

e.g
import org.jbk.test1.A;
- you can define many import statements in one java file
- it will not import sub package
- ways ti import
a) import package_name.*;
- * means all clasess or interfaces
b) specific path
e.g
import package_name.class_name;
or
import package_name.interface_name;

- java.lang
- java.util
- java.io
- java.sql

-> Question
a) can import class or interface without import statement
b) what is package
c) explain import statement
1. create a class Student
- define a property of Student
- name,age,roll_no, sub1,sub2,sub3,sub4,sub5
- define a method to accept properties of Student
- define a method print properties of Student

- create a class StudentTest


- define main() method
- call method from Student class

- define a method to calculate total marks and print it


- define a method to calculate percentage of student and print it
- define a method to calculate grade of student and print it

/*------------------*/

05-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Practical

1. create a class DoIt


- define a method to return power of number - pass number as parameter
e.g
int base=4;
int power=6;

int cal=1;
public int m1(int base,int power){
for(int i=1;i<=power;i++){
cal=base*cal;
}
return cal;
}

- define a method to return a count of digit of number - pass number as


parameter
e.g
int y=4135;
int count=0,r=0;
public int count_digit(int num){
while(num>0){
r=num%10;
num=num/10;
count++;
}
return count;
}

- Armstrong Number
int y=153;
e.g
int a=(1*1*1)+(5*5*5)+(3*3*3);
= 1 +125 + 27
= 153
if(y==a)
print("Armstrong Number");
else
print("Not Armstrong Number");

public void checkArmstrong(int a){


int count=count_digit(a);
int t=a,n=0,sum=0;
while(a>0){
n=a%10;
sum=sum+m1(n,count);
a=a/10;
}
if(t==sum)
print("Armstrong Number");
else
print("Not Armstrong Number");
}

- create a class DemoIt


- define a main() method an call DoIt class method

2. create a class Employee


- define a property of Employee
- id,name,post
- define a method to accept Employee properties
- define a method to show Employee properties

- create a class EmployeeTest


- define a main() method - call Employee class method

/*------------------*/

06-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: class and object

-: class
1. it is blue print of object
2. it is virtual entity
3. it is logical entity
4. syntax
access_modifier class class_name{

}
e.g
public class Student{

5. class_name is identifiers
6. class_name is reference data_type
7. class will tell the status and behaviour of object
8. class contain 5 elements
a) int y=100; - variable
b) method
public void m1(){

}
c) object
Student s1=new Student();
d) constructor
e) block - (static / instance)
9. class does not required memory

-: object
1. it is instance of a class
2. it is real world entity
3. it is physical entity
4. syntax
class_name object_name=new class_name();
e.g
public class Book{
Book b1=new Book();
int y=100;
new Book();
}

5. object_name is reference variable


6. object_name is identifiers
7. object required memory
8. you can create many object of one class
9. every object have different memory location
10. object will implements status and behaviour of class

Note -:
a) you can not create object without a class
b) you can create class without object

-> Question
a) what is class
b) what is object

1. create a class Maths


- define a method to return sum of 2 int - pass number as parameter
- define a method to return subtraction of 2 int - pass number as parameter
- define a method to return multiplication of 2 int - pass number as
parameter
- define a method to return division of 2 int - pass number as parameter
- define a method to return mod of 2 int - pass number as parameter

- create a class MathsDemo


- define main() method call Maths class method
- accept int value from user

2. create a class Book


- define Book's properties
- book_name, book_price, book_qnty, book_author,book_pages,total
- define a method to accept properties - accept int value from user
- define a method to calculate total
- define a method to show properties

- create a class BookDemo


- define main() method and call Book class method
3. print the following series
a) 1 4 9 16 25 ....
b) 1 8 27 64 125 ....
c) 1 5 10 17 26 ....

for(int k=1;k<=10;k++){
if n=0;
if(k==1)
n=k*k;
else
n=(k*k)+1;
print(k);
}

/*------------------*/

09-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Test-1 (Theory)

/*------------------*/

10-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Access Modifier

-: Access Modifier
- the access modifier will tell you the scope of elements
- they will not tell you how to access that elements
- java has 4 access modifier
- types of access modifier
a) private
b) default
c) protected
d) public

- all access modifier are applicable to instance and static method


- all access modifier are applicable to instance and static variable
- all access modifier are applicable to the constructor
- all access modifier are not applicable to local variable
- public and default access_modifier are applicable to outer class
- all access_modifier are applicable to inner class

a) private
- the scope of private access modifier is within a class

b) default
- the scope of default access modifier is within a package
- it is the by default access modifier in java

c) protected
- the scope of protected access modifier is within a package and outside the
package only in a child class

d) public
- you can access it from anywhere

-: Encapsulation
- it is a concept of OOPs
- to bind a data into a single entity is called as encapsulation
e.g class
- to achieve the encapsulation by declaring data members or functions (methods) as
private
- to access those private members or functions by using public getter and setter
method
- POJO class - Plain Old Java Object class

- it is not complusory to declare getter and setter method public


- you can define getter and setter method as protected, default and private
- not only private variable have getter and setter method
- you can declare getter and setter method for public, protected and default
variable
- not only every private variable have getter and setter method
- advantage
a) it will provide a data security

private < default < protected < public

-: Question
1) what is access modifier
2) explain scope of each access modifier
3) what is advantage of encapsulation
4) how to achieve encapsulation

/*----------------*/

11-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Constructor

1. it is a special method
2. it has same name that class have
3. it does not have return_type - even void also not allowed
4. it will execute immediately when object is created
5. all access_modifier are applicable to the constructor
6. you can create a private constructor
7. you can not declare constructor as static, final and abstract
8. you can pass argument to the constructor
9. you can create many constructors in one class
10. you can create many object of one class
11. one object can call only one constructor
12. it is used to initialized the object and instance variable
13. without a constructor you can not execute the program
14. types of constructor
a) default constructor
- when the programmmer will not define any type of constructor then compiler will
generate default constructor
- you can not pass argument and define custom code into default constructor
- public and default access_modifier is applicable to the default constructor
e.g
public class A{
public A(){
super();
}
}

b) parameterized constructor
- this constructor define by programmer
- you can pass argument and define custom code into parameterized constructor
- all access_modifier are applicable to the constructor
e.g
public class A{
public A(int d){
print(d*d);
}
}

c) non-parameterized constructor
- this constructor define by programmer
- you can not pass argument to non-parameterized constructor but you can define
custom code into non-parameterized constructor
e.g
public class A{
public A(){
print("Hello");
}
}

15. you can not override the constructor


16. you can overload the constructor
17. private constructor is used to create a singleton class - singleton class means
you can create only one object of that class is called singleton class
- syntax
access_modifier class_name(parameter_list){

18. you call method inside the constructor

-: Question

a) what is constructor?
b) what is used fo constructor?
c) explain types of constructors.

-: create a class Book


- define a properties of Book
- book_name,book_author,book_price,book_qnty,total
- define non-parameterized constructor - assign initial value to the
properties
- define a method to print properties

- create a class BookDemo


- define main() method

/*-------------------*/
12-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Practical

1. Default Constructor:
Write a Java program to create a class called "Cat" with instance variables name
and age. Implement a non-parameterized constructor that initializes the name to
"Unknown" and the age to 0. Print the values of the variables.

2. Parameterized Constructor:
Write a Java program to create a class called Dog with instance variables name and
color. Implement a parameterized constructor that takes name and color as
parameters and initializes the instance variables. Print the values of the
variables.

3. Chaining Constructors
Write a Java program to create a class called Student with instance variables
studentId, studentName, and grade. Implement a non-parameterized constructor and a
parameterized constructor that takes all three instance variables. Use constructor
chaining to initialize the variables. Print the values of the variables.

4. Create a class Employee


- define properties of Employee
- name,post,id,city,phone,qualification
- basic_salary;
- used encapsulation concept
- create a non-parameterized constructor
- create a parameterized constructor
- define a method to print Employee properties

- create a EmployeeTest
- define main() method
- call Employee class method

4. write a program - create a while loop - accept number from user and loop will
terminate when user will 7
/*-------------------*/

14-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Test Paper Discussion

1) print the following pattern


* * # * *
* * # * *
# # # # #
* * # * *
* * # * *

R-5
C-5
R-C-5
for(int r=1;<r<=5;r++){
for(int c=1;c<=5;c++){
if(r==3 || c==3)
print("#");
else
print("*");
}
}

2) print the sum of square of even digit of number

int y=1234;
int n=0,sum=0;
while(y>0){
n=y%10;
if(n%2==0){
sum=sum+(n*n);
}
y=y/10;
}

3) print the product of number divisible by 3 and 5 from 244 to 350;


int p=1;
for(int k=244; k<=350;k++){
if(k%3==0 & k%5==0)
p=p*k;
}
print(p);

4) write a method that will return product of digit of number - pass number as
argument
e.g. int y=4351= 4*3*5*1;

public int productOfDigit(int y){


int n=0,p=1;
while(y>0){
n=y%10;
p=p*n;
y=y/10;
}
return p;
}

5) print the following series print 10 number of each series


a) 1 -2 3 -4 5 -6...

for(int k=1;k<=10;k++){
if(k%2==0)
print(-1*k);
else
print(k);
}

6) write a method to print Fibonacci series


public void fiboSeires(){
int n1=0,n2=1,n3=0;
print(n1+" "+n2);
for(int k=1;k<=5;k++){
n3=n1+n2;
print(n3);
n1=n2;
n3=n2;
}
}

7) write a method to calculate the power of number - pass base and power as
argument
e.g. base=3 and power=5
Ans=3*3*3*3*3;

public void getPower(int b,int p){


int power=1;
for(int k=1;k<=p;k++){
power=power*b;
}
print(power);
}

8) print the product of cube of odd digit of number

int y=1234;
int n=0,p=1;
while(y>0){
n=y%10;
if(n%2!=0){
p=p*(n*n*n);
}
y=y/10;
}

9) create a class Student


- define property of Student
- define 2 constructor - non-argument and argument
- pass argument to constructor
- print the property of Student

public class Student{


String name;
int age;
public Student(){

}
public Student(String n,int a){
name=n;
age=a;
}
public void printValue(){
print(name);
print(age);
}
}
public class DemoStudent{
main(){
Student s1=new Student("Rohan",23);
}
}

10) write a program to check number is divisible 4 and 7


public class Demo{
main(){
int y=28;
if(y%4==0 && y%7==0)
print("number divisible");
else
print("number is divisible");
}
}

/*--------------*/

16-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Array In Java

-: Array

- it is a collection of homogenous(similar) data type and having a continous memory


locations
- you can store many values under one variable name
- syntax
data_type array_name[]=new data_type[size];
e.g
long h1[]=new long[5];
String a1[]=new String[10];

class Student{
Student s1=new Student();
Student s[]=new Student[5];
//int age[]=new int[5];
//String name[]=new String[5];
}

- you can perform CRUD operation on Array


C -: Create
R -: Read
U -: Update
D -: Delete
- Array has index
- Array will reduce a length of code
- Array will reduce the time consumption
- Array index starts from zero [0]
int y[]=new int[5];
- last index=size-1;
- Array index is always integer
- you can store primitive and reference value in Array
- types od Array
a) one dimensional
int y[]=new int[5];
b) two dimensional
long h[][]=new long[5][3];
c) multi dimensional
String s[][][]=nwe String[3][4][2];
{} - class, interface, method, block, enum, array
() - method parameter, condition, expression, constructor parameter
[] - Array

a) declaring array

1. int y[]=new int[5];


2. String s[];
s=new String[7];
3. long h[]={66,11,22,78,90};

-
int y[]=new int[3];
int a=10;
System.out.println(a);
//System.out.println(y);
y[0]=20;
//y[3]=11;//Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
y[2]=100;

-
int y[]=new int[-1];//Exception in thread "main"
java.lang.NegativeArraySizeException
y[-1]=333;

-
int h[]=new int[0];
//h[0]=100;//Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

-: Question
1) what is Array
2) explain type of Array
3) what is advantage of Array
4) what is dis-advantage of Array

- write a program to accept String value in array


- write a program to accept double value in array
- write a program to accept byte value in array

-:
package com.tka.array1;

import java.util.Scanner;

public class G {
public static void main(String[] args) {
String s1[]=new String[5];
G g1=new G();
g1.acceptValue(s1);
g1.showValue(s1);
System.out.println();
g1.printReverse(s1);
}
public void printReverse(String t[]) {
for(int k=t.length-1;k>=0;k--) {
System.out.print(t[k]+" ");
}
}
public void showValue(String h[]) {
for(int k=0;k<h.length;k++) {
System.out.print(h[k]+" ");
}
}
public void acceptValue(String y[]) {
System.out.println("Enter String");
Scanner sc=new Scanner(System.in);
for(int k=0;k<y.length;k++) {
y[k]=sc.next();
}
}
}

/*-------------*/

17-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Array Program In Java

1. write a program to acceptValue in int array and print those value


2. write a program to print array in reverse
3. write a method to print even element of array
4. write a method to print cube of odd element of array
5. write a method to square of even element of array

-: write a program to swap 2 int


int a=10,b=20;
print(a);//10
print(b);//20
print();
int c=0;
c=a;
a=b;
b=c;
-: output
print(a);//20
print(b);//10

-: Sort Array
int y[]={10,1,23,2,4};
for(int k=0;k<y.length;k++){
for(int j=k+1;j<y.length;j++){
if(y[k]>y[j]){
int h=y[k];
y[k]=y[j];
y[j]=h;
}
}
}

-: Find Max element


int y[]={10,1,23,2,4};
int max=y[0];
for(int k=0;k<y.length;k++){
if(y[k]>max)
max=y[k];
}
print(max);

6. write a method to print lowest element of array

/*-------------*/

18-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Array Program In Java

1. write a method to print sum of array element


2. write a method to print product of array element

-: 2D array

3. create a class Student


- define properties of Student - name,age
- define a method to accept the properties
- define a method to show the properties
- define main() method

a. write a method to print 2nd lowest element of array


int y[]={10,1,23,2,4};
for(int k=0;k<y.length;k++){
for(int j=k+1;j<y.length;j++){
if(y[k]>y[j]){
int h=y[k];
y[k]=y[j];
y[j]=h;
}
}
}
int y[]={1,2,4,10,23};
print(y[length-2]);//2nd highest
print(y[1);// 2nd lowest

b. write a method to print 2nd highest element of array

/*-------------*/

19-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Activity

Name -:

Hobbies -:

One Thing that you like yourself -:

Dream -:
Ambition -:

/*------------------*/

20-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Inheritance In Java

-: Inheritance
1. it is a concept of OOPs
2. one class can access the property of another class
3. child class can can access the property of parent class
e.g
class Loan{
personal_details();
}
class CarLoan extends Loan{
car_details();
}
4. 'extends' keyword is used for inheritance
- CarLoan can access the property of Loan class
5. parent class can not access the property of child class
6. private property of parent class can not inherited to child class
7. inheritance shows 'Is-A' relationship
8. parent class have general(common) property
9. child class have specific property
10. Object is the parent class of all clasess of Java
- it has 11 methods
- it is present in java.lang package
e.g
public String toString(), public boolean equals(), protected void finalize() etc.
- it is present in java.lang package
11.
-: without inhertiance

a) repeatation of code
b) to repeat the code it will take a time
c) maintainace of code is not easy
d) it will increase the length of code

12.
-: with inheritance

a) no repeatation of code
b) it will reduce a time
c) maintainace of code is easy
d) it will not increase the length of code
e) it will increase the reusability of code

13. in inheritance both parent and child class thightly coupled with each other
14. 'Has-A' relationship
- it is the assocciation between 2 classes
- Composition

- Aggreegation
e.g
class University{
Department d=new Department();//composition
Teacher t=new Teacher();//aggreegation
}
class Department{
//University u=new University();
}
class Teacher{

-: Question
a) what is different between 'is-a' and 'has-a' relationship
b) what is inheritance

/*-------------*/

24-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Inheritance In Java

-: types of inheritance
1. single inheritance
2. multiple inheritance
3. multi-level inheritance
4. hirarchical inheritance
5. hybrid inheritance
6. cyclic inheritance

-: multiple,hybrid and cyclic inheritance will not support by java


-:

a) single inheritance
class A{
void m1(){
print("Apple");
}
}
class B extends A{
void k1(){
print("Mango");
}
}
class Demo{
main(){
A a1=new A();
a1.m1();
a1.k1();//Error
B b1=new B();
b1.k1();
b1.m1();
}
}

-: one parent class have only child class


b) multi-level inheritance
class A{
void m1(){
print("Apple");
}
}
class B extends A{
void k1(){
print("Mango");
}
}
class C extends B{
void d1(){
print("Banana");
}
}
class Demo{
main(){
A a1=new A();
//a1.k1();
//a1.d1();
a1.m1();
System.out.println();
B b1=new B();
b1.k1();
//b1.d1();
b1.m1();
System.out.println();
C c1=new C();
c1.k1();
c1.d1();
c1.m1();
}
}

c) hirarchical inheritance
-: one parent class have many child classes
-: one child class have only one parent class

d) multiple inheritance
-: java does not support multiple inheritance
class A{
void m1(){
print("Apple");
}
}
class B{
void m1(){
print("Mango");
}
}
class C extends B,A{//Error
void d1(){
print("Banana");
}
}
class Demo{
main(){
C c1=new C();
c1.d1();
c1.m1();
}
}
-: because of ambiguity error java does not support multiple inheritance
-: in java one child class do not have many parent classes
-: by using interface you can achieve multiple inheritance

e) hybrid inheritance

f) cyclic inheritance
public class A extends A{//Error

-:
class A{
A(){
print("Banana");
}
}
class B extends A{
B(){
print("Cherry");
}
}
class Demo{
main(){
//A a1=new A();
//println();
B b1=new B();
}
}

-: when you create child class object it will execute (call) parent class
constructor first
-: Question
1. explain types of inheritance
2. why java does not support multiple inheritance

-:
1. create a class Person
- define Person's Properties
- define a method to accept Person's properties
- define a method to show Person's properties

- create a class Student


- it is a child class of Person
- define Student's Properties
- define a method to accept Student's properties
- define a method to show Student's properties

create a class DemoStudent


- define main() method
- create a Student class object
- and accept Person and Student property
- and show Person and Student property

/*-------------*/
25-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: this and super

1. create a class A
- define non-parameterized constructor
- define parameterized constructor - int
- call both constructors

2. create a class B
- define non-parameterized constructor
- define a method to call product from to - pass 2 int as parameter

3. create a class C
- define non-parameterized constructor
- define a method to call sum from to - pass 2 int as parameter
e.g.
public void sum(int a,int b);

4. create a class D
- define non-parameterized constructor
- define parameterized constructor - pass 1 int as parameter
- define a method to return no.of digit in number

5. create a class E
- define parameterized constructor - pass 1 int as parameter
- define a method to print number in reverse

6. create a class F
- define parameterized constructor - pass 1 int as parameter
- define a method to check number is palindrome or not

/*-------------*/

26-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: this and super

-: this keyword
- it is a keyword
- it is used to refere current class object
- it is used to access current class instance or static property (variable/method)
- generally it is used to make difference between local variable and current class
instance or static property
(variable/method)
- because some times local variable or instance and static variable have same name
- you can used this keyword only in instance area
1. instance block
2. instance method
3. constructor

- you can not used this keyword in static area


1. static block
2. static method
- you can not used this keyword in main() method

-: this() constructor
- it is used to call current class constructor
- it is used only in a constructor
- it should be the first line of constructor
- you can not used more than one this() constructor in a constructor

- this keyword does not required inheritance

-: super keyword
- it is a keyword
- it is used to refere parent class object
- super keyword required inheritance
- it is used to access parent class instance or static property (variable/method)
- generally it is used to make difference between child class instance or static
property and parent class instance or static property (variable/method)
- because some times child class or parent class instance and static variable have
same name
- you can used super keyword only in instance area
1. instance block
2. instance method
3. constructor

- you can not used super keyword in static area


1. static block
2. static method
- you can not used super keyword in main() method

-: super() constructor
- it is used to call parent class constructor
- it is used only in a constructor
- it should be the first line of constructor
- you can not used more than one super() constructor in a constructor
- you can not used this() and super() constructor at a same time
- if you not define either this() or super() constructor then by default super()
constructor generated by complier

-: variable priority
1. local variable
2. current class instance or static variable
3. parent class instance or static variable

-: Question
a) what is difference between this and super keyword

1. create a class A
- write a program for enter number in loop and loop will terminate when 7
will enter

class A{
main(){
print("enter number");
scanner code;
int y=sc.nextInt();
while(y!=7){
print("enter number");
y=sc.nextInt();
}
}
}

2. create a class Demo


- define main() method
- create menu
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Mod
6. Exit
- define a separate method for each operation and take input from user
/*-------------*/

27-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Polymorphism

- poly - many
- morphism - form

1. the object have an ability to change its behaviour as per the requirement
2. types of polymorphism
a) compiletime polymorphism
- static polymorphism
- early binding
e.g
method overloading, constructor overloading
b) runtime polymorphism
- dynamic polymorphism
- late binding
e.g
method overriding

1. method overloading

absi(int);
absf(float);
absd(double);
absl(long);

abs(int);
abs(long);
abs(float);
abs(double);

- same class, same method name but having different arguments is called method
overloading
- same class,same method name but have different method_signature is called method
overloading
- inheritance does not have any role in method overloading
- access_modifier do not have any role in method overloading
- you can overload private method
- you can overload final method
- you can overload static method - means you can overload main() method
- return_type do not have any role in method overloading
- you can overload abstract method
- in method overloading the method calling is based on reference type
- method overloading is example of compiletime polymorphism
- it is also called as static polymorphism and early binding
- you can overload the constructor also

1. create a class A{
define private method and overload it
define final method and overload it
define static method and overload it
and give different return type to each method
}

2. create a class B{
show constructor overloading
}

3. create a class C{
show main() method overloading
}

- to call method
a) by its name
b) by its argument

- argument
a) no.of arguments
void m1(){
//no.of arguments -0
}
void m1(int y){
//no.of arguments -1
}
void m1(int y,int e){
//no.of arguments -2
}

b) type of argument
void m1(){
//no.of arguments -0 type-
}
void m1(int y){
//no.of arguments -1, type- int
}
void m1(int y,int r){
//no.of arguments -2 ,type- int,int
}
void m1(String s){
//no.of arguments -1, type -String
}

c) order of argument
void m1(){
//no.of arguments-0 type-
}
void m1(int y,String s){
//no.of arguments-2 type-int,String
}
void m1(String s,int y){
////no.of arguments-2 type-String,int
}

-: Question
1. what is polymorphism
2. explain type of polymorphism
3. explain method overloading

/*-----------*/

28-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Polymorphism

-: Method Overriding
- method_signature should be same but one method in parent class and another method
in child class
- inheritance is used in method overriding
- you can not override private method
- you can not override final method
- you can not override static method - main() method can not override
- access_modifier
- either you can keep same access_modifier or increase the scope of
access_modifier
- private < default < protected < public
- parent class reference can hold child class object
- it is called as dynamic dispatch
- child class reference can not hold parent class object

String s1=new String("Apple");


Object o1=new Object();

Object o2=new String("Cherry");


- parent class reference holding child class object
- it is called dynamic dispatch

String s2=new Object();//Error

-: return_type
- it is applicable to reference data_type
class_name
interface_name
enum_name
array_name

- it is not applicable to primitive data_type


- either you can keep same return_type or if you want to change the return_type of
overrided method then that return_type should be the child class of overriden
method's return_type
- it is called as co-variant return_type
- it introduce in java-1.5
-: Annotation
- @Override
- it will give more information about code
- it will apply all rules strictly regarding which concept annotation you used
- it introduce in java-1.5

-: features of java-1.5
a) for each loop
b) var arg method
c) static import
d) co-variant return_type
e) annotation
f) generic collection

1. create a class Animal


- define non-parameterized constructor
- define method foodType(), mySound()

- create a class Tiger


- it is a sub class of Animal
- define non-parameterized constructor
- override method of parent class

- create a class Deer


- it is a sub class of Animal
- define non-parameterized constructor
- override method of parent class

- create a class DemoAnimal


- define main() method
- create Tiger and Deer class object and call method

-: Question
1. what is method overriding
2. what is co-variant return type

/*--------------*/

30-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Polymorphism

1. Write a Java program to create a base class Animal (Animal Family) with a method
called Sound(). Create two subclasses Bird and Cat. Override the Sound() method in
each subclass to make a specific sound for each animal.

2. Write a Java program to create a class Vehicle with a method called speedUp().
Create two subclasses Car and Bicycle. Override the speedUp() method in each
subclass to increase the vehicle's speed differently.

3. Write a Java program to create a base class Shape with a method called
calculateArea(). Create three subclasses: Circle, Rectangle, and Triangle. Override
the calculateArea() method in each subclass to calculate and return the shape's
area.

4. Write a Java program to create a class Shape with methods getArea() and
getPerimeter(). Create three subclasses: Circle, Rectangle, and Triangle. Override
the getArea() and getPerimeter() methods in each subclass to calculate and return
the area and perimeter of the respective shapes.

5. Write a Java program to create a base class Animal with methods move() and
makeSound(). Create two subclasses Bird and Panthera. Override the move() method in
each subclass to describe how each animal moves. Also, override the makeSound()
method in each subclass to make a specific sound for each animal.

6. Write a Java program to create a base class Shape with methods draw() and
calculateArea(). Create three subclasses: Circle, Square, and Triangle. Override
the draw() method in each subclass to draw the respective shape, and override the
calculateArea() method to calculate and return the area of each shape.

7. Write a Java program to create a base class Shape with methods draw() and
calculateArea(). Create two subclasses Circle and Cylinder. Override the draw()
method in each subclass to draw the respective shape. In addition, override the
calculateArea() method in the Cylinder subclass to calculate and return the total
surface area of the cylinder.

-: toString()
- syntax
public String toString(){

- it is Object class method


- you can override toString() method
- when you print any class object toString() method will get call

/*------------------*/

31-12-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Revision

-: JBK Test
https://thekiranacademy.com/test/

/*------------------*/

02-01-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Abstraction

-: Abstraction
-
class Animal{
void mySound(){
print("No-Sound");
}
void foodType(){
print("No-Food");
}
}
class Dog extends Animal{
@Override
void mySound(){
print("Barking");
}
@Override
void foodType(){
print("Non-Veg");
}
}
------
abstract class Animal{
abstract void mySound();
abstract void foodType();
}

class Dog extends Animal{


@Override
void mySound(){
print("Barking");
}
@Override
void foodType(){
print("Non-Veg");
}
}

- abstraction means hide the implementation from user and show required services to
user
e.g GUI - Graphical User Interface
- ways to implements abstraction
a) abstract class
b) interface

-: abstract class
- it is incomplete class
- the class which have abstract keyword in the declaration is called abstract class
e.g
public abstract class A{

- this is concrete class


public class B{

- abstract class contain abstract method and concrete method also


- you can define constructor in abstract class
- you can define static and instance block in abstract class

B b1=new B();
- you can not create an object of abstract class
- you can create reference of abstract class

-: abstract method
- it is incomplete method
- the method which have abstract keyword in the method_signature is called abstract
method
e.g
public abstract void m1();

- this is concrete method


public void k1(){

- abstract method do have method body but concrete method have method body
- abstract method declare only in abstract class
- you can not declare abstract method in concrete class
- you can not declare abstract method as final, static and private
- if a concrete class inherite abstract class then it is a responsibility of child
class to give method body to all abstract method present in parent class

- you can not declare abstract class as final


- if a class is final then you can not create its child class
e.g String,Scanner and all wrapper clasess

- you can not declare constructor as abstract, final and static


- you can create empty abstract class

e.g
public class B { //outer class
static class BB{//inner class

}
}

- you can not declare outer class as static but you can declare inner class as
static
- generally abstract class consider as parent class
- you can overload abstract method

-: Question
1. what is abstraction
2. explain abstract class and method

/*------------------*/

06-01-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Intrerface

-: Intrerface
abstract class A{
static final int y=199;
abstract void m1();
}

class B extends A,D{//Error


void m1(){

}
}
class D{
void k1(){

}
}

- abstract class will not provide 100% abstraction


1. you can create empty abstract class
2. you can define constructor in abstract class
3. you can define static or instance block in abstract class
4. you can define concrete method in abstract class

-: Intrerface
- it is pure abstract class
- it provide 100% abstraction
- it is used to communicate between 2 application or system
- it is just like a contract between customer and service provider
- syntax
access_modifier interface interface_name{

}
e.g
public interface A{

- you can create empty interface


- it is called as marker interface
e.g
Serializable,Cloneable

- you can not define constructor in interface


- you can not define static or instance block in interface
- you can not define concrete method in interface

public interface A{
public abstract void m1();
public void m2();
abstract void m3();
void m4();
}

- in interface by default all methods are public and abstract

public interface A{
public static final int y2=100;
static final int y1=100;
public final int y3=100;
public static int y4=100;
static int y5=100;
final int y6=100;
public int y7=100;
int y8=3200;
}

- in interface by default all variables are public,static and final


- by using interface you can achieve the multiple inheritance

- class extends class


- class implements interface
- interface extends interface

- one interface can inherite another interface


e.g
public interface A{

}
public interface B extends A{

- one interface can extends many interfaces


e.g
public interface A{

}
public interface D{

}
public interface B extends A,D{

- class implements interface


e.g
public interface A{

}
public class TT implements A{

- class can implements many interfaces


e.g
public interface A{

}
public interface D{

}
public class TT implements A,D{

- one class can extends only one class


public class W{

}
public interface A{

}
public interface D{

}
public class TT extends W implements A,D{

- you can not create object of interface


- you can create reference of interface
- if a concrete class implements interface then it is a responsibility of
implemented class to give method body to all abstract method present in interface

1. Create a class named 'Rectangle' with two data members 'length' and 'breadth'
and two methods to print the area and perimeter of the rectangle respectively. Its
constructor having parameters for length and breadth is used to initialize length
and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with
its constructor having a parameter for its side (suppose s) calling the constructor
of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle
and a square

2. Create a class named 'Shape' with a method to print "This is This is shape".
Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape
class, both having a method to print "This is rectangular shape" and "This is
circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a
method to print "Square is a rectangle". Now call the method of 'Shape' and
'Rectangle' class by the object of 'Square' class.

3. Write a Java program to create a Animal interface with a method called bark()
that takes no arguments and returns void. Create a Dog class that implements Animal
and overrides speak() to print "Dog is barking".

4. Write a Java program to create an interface Shape with the getArea() method.
Create three classes Rectangle, Circle, and Triangle that implement the Shape
interface. Implement the getArea() method for each of the three classes.

5. Write a Java program to create an interface Playable with a method play() that
takes no arguments and returns void. Create three classes Football, Volleyball, and
Basketball that implement the Playable interface and override the play() method to
play the respective sports.

/*------------------*/

07-01-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception

-: static keyword

1. it is a keyword
2. it is a class level keyword
3. if variable is static then it will create a single copy of variable
4. all access_modifier are applicable to static variable and method
5. it is a modifier
6. to static variable memory alocation done when class loaded into memory
7. to static variable memory dealocation done when class unloaded from memory
8. final modifier is applicable to static variable and method
9. it is recommended to access static variable and method by using class_name
10. you can not declare constructor,local variable,outer class and abstract method
as static
11. you can not override static method
12. you can overload static method
13. you can declare static block
-syntax
static {
/*
static block
static block execute before the main() method
*/
}
14. in interface by default all variables are static

-: final keyword

1. it is a keyword
2. if variable is final then you can not change its value
3. if method is final then you can not override that method
4. if class is final then you can not create its child class
5. you can not declare constructor,abstract method as final
6. final modifier is applicable to local variable
7. in interface by default all variables are final
8. you can overload final method
9. static modifier is applicable to final variable and method
10. you can define main() method as final
11. you can not declare block as final
12. it is a modifier

-: create a Animal - define method is a class


- void mySound(String mysound);
- void myFood(String myfood);
- void myLifePeriod(int mylifeperiod);

- create a class Dog - it is a sub class of Animal and override the Animal class
method
- create a class Tiger - it is a sub class of Animal and override the Animal class
method
- create a class Cat - it is a sub class of Animal and override the Animal class
method

-: Override the method from parent class


create class Liquid - define correspoding properties and methods of Liquid
e.g state, boilingPoint etc.
- create class Water - sub class of Liquid - define correspoding properties and
methods of Water
- define 2 constructor - default and parameterized
- create class Milk - sub class of Liquid - define correspoding properties and
methods of Milk
- define 2 constructor - default and parameterized
e.g. subProducts of milk
- create a class HCL - sub class of Liquid - define correspoding properties and
methods of HCL
- define 2 constructor - default and parameterized
- create a class H2SO4 - sub class of Liquid - define correspoding properties and
methods of H2SO4
- define 2 constructor - default and parameterized
-: create Liquid class reference and Liquid class object - call correspoding
methods
-: create Liquid class reference and Water class object - call correspoding methods
-: create Water class reference and Water class object - call correspoding methods
-: create Liquid class reference and Milk class object - call correspoding methods
-: create Milk class reference and Milk class object - call correspoding methods
-: create Liquid class reference and HCL class object - call correspoding methods
-: create HCL class reference and HCL class object - call correspoding methods
-: create Liquid class reference and H2SO4 class object - call correspoding methods
-: create H2SO4 class reference and H2SO4 class object - call correspoding methods

/*-------------------*/
08-01-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception

-: Exception
- it is unwanted event occurs during the execution of program
e.g FileNotFoundException, SQLException
- types of exception
a) compiletime exception
b) runtime exception

a) compiletime exception
- the exception which checked at the compiletime is called as compiletime exception
- it is also called as checked exception
e.g FileNotFoundException, IOException , SQLException etc
- in program if checked exception occurs and programmmer does not define exception
handle code then compiler will not allowed to execute the program
- so if checked exception occurs in then programmmer must define exception handle
code

b) runtime exception
- the exception which does not identify by compiler and occurs during the execution
of program it is called as runtime exception
- it is also called unchecked exception
e.g ArithmeticException, NullPointerException etc
- in program if unchecked exception occurs and programmmer does not define
exception handle code then also compiler will allowed to execute the program

- Throwable is the parent class of all exception classes of java


- Error and its child classes and RuntimeException and its child classes are called
unchecked exception

-: exception
- it will occurs due to lack of logical programmming
- programmmer is responsibile for exception
- exception can be handle during the execution of program
e.g
FileNotFoundException, NullPointerException etc

-: Error
- it will occurs due to lack of hardware resources
- programmmer is not responsibile for error
- error can not be handle during the execution of program
e.g StackOverflowError, VirtualMachineError etc.

-: Exception Handle
- exception handle means to provide the alternative solution for code
- if programmmer does not define any exception handle code means neither try-catch
block nor throws keyword then JVM will handle the exception

- it will create default exception object and handle the exception


- if JVM will handle the exception the following things will happen
1. it will terminate your program abnormally
2. at which line the exception is occurs further code will not execute by JVM
3. it will show 3 things on console
a) name of exception
b) message related to exception
c) line numbers which are affected by exception

a) try-catch-finally block
-: try block
- it is a keyword
- syntax
try{

}
- generally programmmer a define code which may raised the exception
- if exception occurs in a try block following things will happen
a) at which line the exception is occurs further code will not execute by JVM
b) try block will throw the exception object

- you can define try block inside the try block


- try block must followed by either catch block or finally block
try{

}catch(exception){

try{

}finally{

try{

}catch(exception){

}finally{

-: catch block
- it is a keyword
- in catch block programmmer define exception handle code
- one try block have many catch blocks
- one catch block handle only one exception
- at a time only one exception will raised in try block so though you define many
catch blocks only one exception will handle at a time

- syntax
catch(exception obj){

- you can handle one exception only one time


try{

}catch(Exception e){

}catch(Exception e){

}catch(Exception e){

- if exception raised in try block then it will throw exception object then
- that exception object will catch by immediate catch block define after the try
- so if the catch block is able to handle the exception then execute catch block
- if it is not then it will check is any catch define after it
- if it is yes then pass that exception object to next catch block and so on....
- if it is no then JVM will handle the exception

try{
System.out.println("Line-1");
System.out.println(a);
System.out.println(b);
int c=a/b;
System.out.println(c);
System.out.println("Line-2");
}catch(ArithmeticException e){
System.out.println(e);
}catch(RuntimeException e){
System.out.println(e);
}catch(Exception e){
System.out.println(e);
}

- to define catch block in child to parent class sequence

-: Question
a) explain try-catch block
b) how JVM will handle the exception

/*-------------------*/
09-01-2024

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception

-: finally block
- it is the last block in try-catch block sequence
- syntax
finally{

- it is used to define a cleanup code for the resources that you used or open
either in try block or in catch block
- one try block have only one finally block
- you can define try-catch block in finally block
- after the finally you can not define catch block
- finally block will execute in both situation, if exception occurs then finally
block will execute and if exception not occurs then also finally block will execute

- in catch block also you can define try-catch block

try{
db.open();
db.insert();
//db.close();
}catch(SQLException e){
print(e);
}finally{
db.close();
}

-: finalize()
- it is a method
- it is present in Object class
- Object class present in java.lang package
- you can override finalize()
- it is called by garbage collector before destroying the object
- finalize() method will detach all resources from object and make ready that
object to destroy
- syntax
protected void finalize(){

-: Question
1. what is difference between final, finally and finalize();
2. explain finally block

/*-------------*/

10-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception

-: throws keyword

- it is a keyword
- it is very dangerous keyword in java
- it is a method level keyword
- it is very effective for checked exception
- it is not much effective for unchecked exception
- you can define many exception for throws keyword, you can handle many exception
by using throws keyword
-
public class D {
public D() throws ArithmeticException{
}
public static void main(String[] args) throws Exception,ArithmeticException{
D d1 = new D();
d1.v1();
}

public void v1() throws Exception,ClassNotFoundException{


System.out.println("Blue");
v2();
}

public void v2() throws IOException{


System.out.println("Pink");
v3();
}
public void v3() throws FileNotFoundException{
System.out.println("Yellow");
FileInputStream file=new FileInputStream("mayur.txt");
}
}

- if calling method throws any exception then caller method must throw either same
exception or its parent class exception
- child to parent sequence should be there
- throws keyword will delegate the responsibility of exception handling to caller
method

-: throw keyword
- it is a keyword
- it is used to throw exception object
- generally it is used to throw user define exception object

-: message printing
1) print object
try{
System.out.println(10/0);
}catch(ArithmeticException e){
System.out.println(e);
}
- it will print name of exception and message related to the exception

2) getMessage() method
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
System.out.println(e.getMessage());
}
- it will print message related to the exception
- this method is present in Throwable class

3) printStackTrace() method
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
//System.out.println(e.getMessage());
e.printStackTrace();
}
- it will print name of exception, message related to the exception and line
numbers affected by exception
- this method is present in Throwable class

4) custom message
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
//System.out.println(e.getMessage());
//e.printStackTrace();
System.out.println("The Arithmetic Exception is Raised...");
}
- you can print your own message

-: Interview Question

1. name of exception
2. which package it is present
3. type of exception
4. who is its parent class
5. who is its child class
6. when it occurs
7. in which version it introduce

1. Arithemetic
2. Runtime
3. NullPointer
4. InputMismatch
5. NumberFormat
6. IndexOutOfBounds
7. ArrayIndexOutOfBounds
8. StringIndexOutOfBounds
9. ClassNotFound
10. FileNotFound
11. IOException
12. SQLExcelption
13. Interrupted
14. llegalArgument
15. IllegalThreadState
16. StackOverFlowError
17. NoClassDefFoundError
18. NegativeArraySize
19. ExceptionInInitializerError
20. AssertionError

------------------

1. write a program to show Arithemetic Exception


2. write a program to show NullPointer Exception
3. write a program to show InputMismatch Exception
4. write a program to show NegativeArraySize Exception
5. write a program to show ArrayIndexOutOfBounds Exception

/*-------------*/

11-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception

1. Write a Java program that throws an exception and catch it using a try-catch
block.
2. Write a Java program to create a method that takes an integer as a parameter and
throws an exception if the number is odd.

3. write a custom exception program for age of student


- create a class Student
- define property of Student
- define non-parameterized constructor

- create a class AgeException


- define non-parameterized constructor
- drfine a method to print message of exception

/*-------------*/

13-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String

-: String

- it is a class in java
- it is a final class
- it is present in java.lang package
- it is a group of characters, set of characters.
- inernally it is a character array
- Object
1) String s1="Yellow";
2) String s2=new String("Pink");

- String object is immutable object


- immutable means once you assign a value you can not change it
- String class implements Serializable, Comparable<String>, CharSequence interface

-: StringBuffer and StringBuilder

- object of StringBuffer and StringBuilder are mutable

-: StringBuffer
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuffer class
- Object
1) StringBuffer sb=new StringBuffer();
2) StringBuffer sb=new StringBuffer(String str);

- it implements Serializable, CharSequence interface


- from jdk-11 it also implements Comparable interface
- it introduce in jdk-1.0
- almost all methods are synchronized
- it is thread-safe
- synchronized one thread can access a method a time
- it will perform slower than StringBuilder

-: StringBuilder
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuilder class
- Object
1) StringBuilder sb=new StringBuilder();
2) StringBuilder sb=new StringBuilder(String str);

- it implements Serializable, CharSequence interface


- from jdk-11 it also implements Comparable interface
- it introduce in jdk-1.5
- almost all methods are non-synchronized
- it is not thread-safe
- non-synchronized many threads can access a method a time
- it will perform faster than StringBuffer

/*-------------*/

14-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String

1. write a method to return count of space


2. write a method to check String is palindrome or not
3. write a method to convert String upper case to lower case
4. write a method to convert String lower case to upper case
5. write a method to convert String into char array

/*-------------*/

17-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String

- object of StringBuffer and StringBuilder are mutable


- mutable means - you can change the value of object

-: StringBuffer
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuffer class
- Object
1) StringBuffer sb=new StringBuffer();
2) StringBuffer sb=new StringBuffer(String str);

- it implements Serializable, CharSequence interface


- from java-11 it also implements Comparable interface
- it introduce in java-1.0
- almost all methods are synchronized
- it is thread-safe
- synchronized one thread can access a method at a time
- it will perform slower than StringBuilder

-: StringBuilder
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuilder class
- Object
1) StringBuilder sb=new StringBuilder();
2) StringBuilder sb=new StringBuilder(String str);

- it implements Serializable, CharSequence interface


- from java-11 it also implements Comparable interface
- it introduce in java-1.5
- almost all methods are non-synchronized
- it is not thread-safe
- non-synchronized means many threads can access a method at a time
- it will perform faster than StringBuffer

-> write a program to delete duplicate valur from String.


String s1="fjbsafnhgjjbakbafbkbagkbkb";
sb_1.deleteCharAt(14);

-: normal for loop

1. introduce in java-1.0
2. it will travel in both direction (forward and backward)
3. you can perform CRUD operation
4. syntax
for(initialization;condition;update_value){

-: for each loop


1. introduce in java-1.5
2. it will travel only in direction (forward)
3. you can not perform CRUD operation
4. you can fetch the value of array only
5. syntax
for(data_type variable_name:collection_name){

-: Note - this for each loop is used to fetch the value from collection only

-: java-1.5

a) Annotation
b) co-variant return_type
c) for each loop
d) static import
e) generic collection

-: write a program count each vowels in a String


String s1="Orange is a Color. Orange is a Fruit.";

/*-------------*/

20-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection

-: Array
- it is a collection of homogenous data_type and having continous memory locations
- syntax
data_type array_name[]=new array_name[size];
- you can perform CRUD operation
- you can store many values under one variable_name
- it will reduce length of code
- array_name is identifiers
- array comes in reference data_type
- you can store primitive and reference value

-: Disadvantage
1. array has a fixed size
2. you can not change the size of array - it is not a growable in nature
3. syntax
data_type array_name[]=new array_name[size];
e.g
int y[]=new int[5];
4. no predefine method available for CRUD operation
5. with respective memory management array is not recommended
6. no predefine data structure is available
7. you can store only homogenous elements
8. you can store primitive and reference value

-: Collection
1. it will not have a fixed size
2. you can change the size of Collection - it is a growable in nature
3. syntax
List list=new ArrayList();
4. predefine method available for CRUD operation
5. with respective memory management collection is recommended
6. predefine data structure is available
7. you can store heterogenous elements
8. you can store only reference value

-: Collection
- it is a group of individual objects - that represent as single entity is called
Collection

-: Collection Framework
- it has several classes and interfaces that used to store a group of individual
objects to represent as single entity

-: Collection
- it is a group of individual objects - that represent as single entity is called
Collection
- it is an interface
- it introduce in jdk-1.2
- it is present in java.util package
- it is a child interface of Iterable interface
- List, Queue, Set are child interface of Collection interface
- it has some common method which are applicable to List,Queue and Set

-: Collections
- it is a class
- it is present in java.util package
- it has some utility methods
e.g sort(), search() etc.
- so you can call it as utility class
- it introduce in jdk-1.2

-: List
- it is an interface
- it introduce in jdk-1.2
- it is present in java.util package
- it is a child interface of Collection interface
- ArrayList, LinkedList, Vector and Stack are implemented classes of List interface

- it is a group of individual objects - that represent as single entity - where


duplicate values are allowed and insertion order will not preserved
- by using index you can differenciate between duplicate values

10 44 55 8
- by using index you can preserved insertion order

-: Legacy class
- Vector and Stack , HashTable and Properties are legacy classes
- it introduce in jdk-1.0
- the classes which came from older version is called as legacy classes

/*-------------*/

21-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection

-: ArrayList
- it is a class
- it introduce in java-1.2
- it is present in java.util package
- it implements List interface
- internally it is an array and that is growable in nature (i.e. resizable array)
- you can insert duplicate element
- insertion order will preserved
- you can insert null value
- you can insert heterogenous elements also
- Object
1. List list=new ArrayList();
2. ArrayList list=new ArrayList();
3. ArrayList list=new ArrayList(Collection c);

-: Iterator
- it is an interface
- it is present in java.util package
- it introduce in java-1.2
- it has 3 methods
a) public boolean hasNext()
b) pulbic Object next()
c) public default void remove();
- it will move only in forward direction
- it is an universal iterator
- it is parent interface of ListIterator interface

-: Iterable
- it is an interface
- it is present in java.lang package
- it introduce in java-1.5
- it has 1 method
a) public Iterator iterator();
- it is parent interface of Collection interface

-: ListIterator
- it is an interface
- it is present in java.util package
- it introduce in java-1.2
- it has 9 methods
a) public boolean hasNext()
b) pulbic Object next()
c) public void remove();
d) public boolean hasPrevious();
e) pulbic Object previous()
f) public int nextIndex();
g) public int previousIndex();
h) public void set(Object e);
i) public void add(Object e);
- it is a child interface of Iterator interface
- it is applicable only for List interface
- it will move in both direction forward or backward direction

-: Stack
- Last In First Out (LIFO)
- First In Last Out (FILO)

-: Queue
- First In First Out (FIFO)
- Last In Last Out (LILO)

/*-------------*/

22-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection

-: LinkedList

-> ArrayList
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. it implements List interface
5. it also implements RandomAccess, Cloneable, Serializable interface
6. it has almost all methods are non synchronized
7. non synchronized means - that many threads can access one method at a one time -
so it is thread not safe
8. because it is non synchronized the performance of ArrayList is relatively high
9. it is not a legacy class
10. it is internally array - it is index
- it is underlying a data structure of resizable of growable array
11. Object
a) List list=new ArrayList();
b) ArrayList list=new ArrayList();
12. it is best to used for retrieval operation
13. it is worst to used for insertion and deletion operation in the middle

-> Vector
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.0
4. it implements List interface
5. it also implements RandomAccess, Cloneable, Serializable interface
6. it has almost all methods are synchronized
7. synchronized means - that one thread can access one method at one time - so it
is thread safe
8. because it is synchronized the performance of Vector is relatively low
9. it is a legacy class
10. it has one child class - that is Stack
11. Object
a) List vector=new Vector();
b) vector vector=new Vector();

-> LinkedList
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. it implements List interface
5. it also implements Deque, Cloneable, java.io.Serializable interface
- Deque is child interface of Queue
- Deque introduce in jdk-1.6
- Queue interface introduce in jdk-1.5
- so from jdk-1.5 LinkedList implements Queue interface
6. it is not legacy class
7. Object
a) List list=new LinkedList();
b) LinkedList list=new LinkedList();
c) Queue list=new LinkedList();
8. it best to used for insertion and deletion operation in the middle
9. it worst to used to retrieval operation
10. it not implements RandomAccess interface
11. it is underlying data structure of doubly linkedlist

-: Question
a) what is difference between array and ArrayList
b) what is difference between Iterable and Iterator
c) what is difference between ArrayList and LinkedList

-: create a class Student


- define properties of Student - name and age
- used encapsulation
- define non-parameterized constructor
- define a method to accept properties value
- define parameterized constructor - name and age
- define a method to show properties

- create arraylist of student


- when you create an object of Student class it will immediately add into
arraylist

- create a class DemoStudent


- define main() method

-: create a class Book


- define properties of Book - name, price, quantity, total
- used encapsulation
- define non-parameterized constructor
- define a method to accept properties value
- define parameterized constructor - name, price, quantity
- define a method to show properties

- create arraylist of Book


- when you create an object of Book class it will immediately add into
arraylist

- create a class DemoBook


- define main() method

/*-------------*/

23-01-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection

-: Set

-> List
1. it is allowed to insert duplicate elements
2. it will preserved insertion order
3. it has index

-> Set
1. it is interface
2. it is a child interface of Collection
3. it introduce in java-1.2
4. HashSet and TreeSet are implemented classes of Set interface
5. it is a group of individual objects to represent as a single entity where
duplicate elements are not allowed and insertion order will not preserved
6. it does not have index
7. it is present in java.util package
8. SortedSet is a child interface of Set

-> HashSet
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. Object
a) Set set=new HashSet();
b) HashSet set=new HashSet();
5. it implements Set interface
6. it also implements Serializable and Cloneable interface but not RandomAccess
interface
7. you can insert heterogenous elements
8. you can insert null as value
9. duplicate elements are not allowed
- if enter any duplicate element by add() method it will return false
10. insertion order will not preserved
11. No replace method is present

-: Question
a) explain Set interface
b) what is difference between HashSet and TreeSet

/*----------------*/

24-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection

-> TreeSet
1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. it implements Set interface
5. it also implements SortedSet and NavigableSet interface
- SortedSet is a child interface of Set
- it introduce in jdk-1.2
- NavigableSet is a child interface of SortedSet
- it introduce in jdk-1.6
- it also implements Cloneable, Serializable interface
6. Object
a) Set set=new TreeSet();
b) SortedSet set=new TreeSet();
c) NavigableSet set=new TreeSet();
d) TreeSet set=new TreeSet();
7. you can insert only homogenous elements
8. if you insert heterogenous elements then you will get ClassCastException
9. you can not insert heterogenous elements
10. you can not insert null as a value
11. if you insert null as a value then you will get NullPointerException
12. duplicate elements are not allowed
13. insertion order will not preserved
14. when you fetch the elements from TreeSet it will come according to some sorting
order
15. the elements which you insert into TreeSet must implements either Comparable or
Comparator interface

-> String and all wrapper clasess implements Comparable interface


-> String and all wrapper clasess are final classes
-> String and all wrapper clasess are present in java.lang package

-: Map
- List and Set -> both are a group of individual objects and it is used to
represent as a single entity

- Map
- it is used to store a data into key and value pair format
- if you want to represent a group of objects into key and value pair format then
you can used Map interface
- key and value pair format called as entry
- you can consider Map as a collection of Entry objects
- it is interface
- it is not a child interface of Collection
- it is present in java.util package
- it introduce in jdk-1.2
- HashMap,HashTable,TreeMap are implemented classes of Map
- SortedMap is the child interface of Map
- the data will store into key and value pair format
- key -> should be unique - duplicate key is not allowed
- value -> duplicate value is allowed
- you can insert object as key and value

-: Entry
- it is interface
- it is inner interface of Map

---
//parnet interface
public interface A{

}
//child interface
public interface B extends A{

}
---
//outer interface
public interface A{
//inner interface
public interface B{

}
}

---
- it introduce in jdk-1.2
- it has following methods
a) Object getKey();
b) Object getValue();
c) Object setValue(Object o);

-: HashMap
1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. Object
a) Map map=new HashMap();
b) HashMap map=new HashMap();
c) HashMap map=new HashMap(Map map);
5. it implements Map interface
6. it also implements Cloneable, Serializable interface
7. it is underlying a data structure of HashTable
8. insertion order will not preserved - it is based on hash-code of keys
9. duplicate key is not allowed - key must be unique
10. duplicate value is allowed
11. you can insert heterogenous elements as key and value
12. you can insert null as key and value also

/*-----------------*/

27-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: TreeMap

-: TreeMap

1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. it implements Map, SortedMap and NavigableMap interface
- SortedMap is child interface of Map
- it is present in java.util package
- it introduce in jdk-1.2

- NavigableMap is child interface of SortedMap


- it is present in java.util package
- it introduce in jdk-1.6
5. Object
a) Map map=new TreeMap();
b) TreeMap map=new TreeMap();
c) SortedMap map=new TreeMap();
d) NavigableMap map=new TreeMap();
e) TreeMap map=map=new TreeMap(Map map);
f) TreeMap map=map=new TreeMap(Comparator c);
6. it is used to represent a data into key and value pair format
7. key should be unique - duplicate key is not allowed
8. duplicate value is allowed
9. you can not insert null as key
- if you insert null as key then you will get NullPointerException
10. you can not insert heterogenous elements as key
- if you insert heterogenous elements then you will get ClassCastException
11. only homogenous elements are allowed as key
12. you can insert heterogenous elements for value
13. you can insert null as value
14. insertion order will not preserved
15. when you retrieve a data it will give in some sorting order which is based on
key

-: Comparable
1. it is interface
2. it is present in java.lang package
3. it introduce in jdk-1.2
4. it is used to provide default sorting order
- String and all wrapper classes implements Comparable interface
5. it has only 1 method
public int compareTo(Object o);
-: Comparator
1. it is interface
2. it is a Functional Interface
3. it is present in java.util package
4. it introduce in jdk-1.2
5. it is used to provide custom sorting order
6. it has 2 methods
a) public int compare(Object o1, Object o2);
b) public boolean equals(Object o);
7. Collator and RuleBasedCollator class implements Comparator interface

-: Question
a) what is difference between Comparable and Comparator
b) what is difference between TreeMap and HashMap
c) what is difference between HashMap and HashTable

-: JBK Test

/*-----------------*/

28-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Generic Collection

- without generic collection


1. it will not provide type safety
2. you can insert heterogenous elements
3. ArrayList list=new ArrayList();
4. to fetch the elements from non-generic collection you need to perform type
casting

- with generic collection


1. it will provide type safety
2. you can not insert heterogenous elements
3. you can insert homogenous elements
4. ArrayList<String> list=new ArrayList<string>();
5. it is applicable to all collection framework
6. to fetch the elements from generic collection you need not to be perform type
casting
7. it introduce in jdk-1.5

- Boxing
1. it means packaging
2. boxing means to convert primitive value into wrapper class object
3. if this convertion done by compiler automatically, it is called as auto-boxing
4. auto-boxing introduce in jdk-1.5

- Unboxing
1. it means unpackaging
2. unboxing means to convert wrapper class object into primitive value
3. if this convertion done by compiler automatically, it is called as auto-unboxing
4. auto-unboxing introduce in jdk-1.5

primitive data_type wrapper clasess

a) byte Byte
b) short Short
c) int Integer
d) long Long
e) float Float
f) double Double
g) char Character
h) boolean Boolean

- Number is the parent class of all numerical wrapper clasess.


- all wrapper clasess implements Comparable interface
- all wrapper clasess are final
- all wrapper clasess are present in java.lang package

-: utility method
a) valueOf()
- it will convert String and primitive value into wrapper class object
- this method is present in all wrapper classes
- syntax
public wrapper_class_name valueOf(argument);

b) ***Value();
- it will return value of wrapper class object
- it will convert wrapper class object into primitive value
- syntax
public primitive data_type ***Value();

- this method is available in all wrapper classes


- this method is used for unboxing

c) parse***(String s);
- this method is used to convert String into primitive value
- this method is available in all wrapper classes except character
- syntax
public primitive data_type parse***(String s);

d) toString();
- it will convert wrapper class object into String
- this method is available in all wrapper classes
- syntax
public String toString();

-: JDK-1.5
a) for each loop
b) var-arg method
c) static import
d) co-variant return type
e) annotation
f) generic collection
g) auto-boxing and auto-unboxing

-: jdk-1.7
a) binary literal
b) String as expression in switch case
c) used underscore in literal
int y=136775;
int h=13_67_75;

-: Question
a. what is generic collection
b. what is difference between non-generic and generic collection
c. explain auto-boxing and auto-unboxing

-: JBK Test

/*--------------------*/

29-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Generic Collection Practical

1. Write a Java program to create a generic method that takes a list of numbers and
returns the sum of all the even and odd numbers.

2. Write a Java program to create a generic method that takes two arraylist of the
same type and checks if they have the same elements in the same order.

3. write a java program to demostrate Comparable interface

4. Write a java program to demostrate Comparator interface

5. Write a java program to show parse***(String s),toString(), ***Value(),


valueOf() method

6. -: create a class Employee


- define properties of Employee - name and salary
- used encapsulation
- define non-parameterized constructor
- define a method to accept properties value
- define parameterized constructor - name and salary
- define a method to show properties

- create arraylist of Employee


- when you create an object of Employee class it will immediately add into
arraylist
- used generic collection

- create a class DemoStudent


- define main() method

/*----------------*/
30-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Java-1.8

1. interface
- by default all methods in interface are public and abstract
- by default all variables in interface are public, static and final

a) you can define default method in interface


- syntax
public default return_type method_name(argument_list){
//method body
}

- you can override default method


- default method means - if programmer will not provide implementation then
interface have default implementation of a method

b) you can define static method in interface


- syntax
public static return_type method_name(argument_list){
//method body
}
- you can not override static method

2. functional interface
- the interface which have only and only one abstract method
- you can not declare functional interface as empty
- if a interface is called functional interface then it should contain one abstract
method
- to create a functional interface @FunctionalInterface annotation is used
- syntax
@FunctionalInterface
public interface interface_name{
//one abstract method
}

3. lambda expression
public void m1(){
print("Apple");
}

a) no need to define access_modifier


void m1(){
print("Apple");
}

b) no need to define return_type


m1(){
print("Apple");
}

c) no need define method name


()->{
print("Apple");
}
d) no need to define curly brackets (optional)
()-> print("Apple");

- lambda expression is used to reduce the length of code


- generally is used to define a code in one line
- it will used only in functional interface

->
public int total(int a,int b) {
int c=0;
c=a+b;
return c;
}

-
int total(int a,int b) {
int c=0;
c=a+b;
return c;
}

-
total(int a,int b) {
int c=0;
c=a+b;
return c;
}

-
(int a,int b) {
int c=0;
c=a+b;
return c;
}

-
(int a,int b) ->{
int c=0;
c=a+b;
return c;
};

e) no need to define argument type


(a,b) ->{
int c=a+b
return c;
};
-
(a,b) -> return c=a+b;

f) no need to define return statement


(a,b) -> a+b;

-: Stream API

1. API - Application Programming Interface


2. it introduce in jdk-1.8
- functional interface, lambda expression, collection, method chaining
3. it is used to reduce length of code
4. it look like an assembly line - where you can perform many operation on data and
get final result
5. by using stream api you can perform many operation in one line
6. following methods are used in stream api
a) forEach()
b) filter()
c) sorted()
d) map()
e) stream()
f) collect()
g) max()
h) min()
i) sum()
j) average()
-: Question
a) explain lambda expression
b) explain features of jdk-1.8
c) what is stream api
d) what is advantage of stream api

-: create a class Employee


- define properties of Employee - name and salary
- used encapsulation
- define non-parameterized constructor
- define a method to accept properties value
- define parameterized constructor - name and salary
- define a method to show properties (Stream API)
- define a method to print details of Employee whose salary is max
- define a method to count no.of Employee whose salary is above 40000;
- define a method to sort Employee according to the salary

- create arraylist of Employee


- when you create an object of Employee class it will immediately add into
arraylist
- used generic collection

- create a class DemoStudent


- define main() method

/*----------------*/

03-02-2025

-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: File Handling

-: DATA STORE
- variable - int, String, double, boolean, char
- in variable you can store data until program is acitve
- in variable you can not store data permanently

-: File
- it is used to store a data permanently
- generally it is used to store a small amount of data
- every file has an extension
e.g
image - jpg, png
audio - mp3
video - mp4
excel - xlsx
word - docx
pdf - pdf
text file - txt

- you can perform CRUD operation on file


C - create
R - read
U - update
D - delete

- file is used to transfer the data


- steps

1. create a file
- open a file
2. write a file / read a file
3. close a file
- delete a file

- URL - Uniform Reasource Locator (path)

a) create object of a file


File file=new File(URL url);
File file=new File("C:\\Ek\\savani\\apeksha.txt");
File file=new File("apeksha.txt");
b) create a file
file.createNewFile();
c) create a directory (folder)
- directory do not have an extension
File file=new File("C:\\Ek\\sairaj");
file.mkdir();

d) write a file
String dir_path="C:\\Ek\\sairaj\\";
String file_path="aditi.txt";
File file=new File(dir_path+file_path);
try {
// FileWriter file_writer=new FileWriter(dir_path+file_path);
// FileWriter file_writer=new FileWriter("C:\\Ek\\sairaj\\
shubham.txt");
//FileWriter file_writer=new FileWriter(file,true);
FileWriter file_writer=new FileWriter(new
File(dir_path+file_path),true);
System.out.println("File Crreated....");
String data="My name is Aditi. I like an Orange.";
// file_writer.write(100);
file_writer.write(data);
file_writer.flush();
file_writer.close();
System.out.println("Data Write into File");
}catch(IOException e) {
System.out.println(e);
}

--

-: Data
-: Flower
- Rose.txt (color name)
- Lotus.txt
- Lilly.txt
-: State
- Maharashtra.txt (capital name)
- Goa.txt
- Tamilnadu.txt
-: Result

a) create a your own name directory in Result directory


b) copy Lilly.txt file into you own name directory
c) copy a data from Maharashtra.txt into Mumbai.txt - the file present in Result
directory
d) cut the Tamilnadu.txt file and paste into your own name directory

You might also like