0% found this document useful (0 votes)
34 views49 pages

Notes Batch 1215 Lyst1735889173989

The document outlines key concepts in Java programming, including definitions of IT, software, and hardware, as well as features of Java such as simplicity, platform independence, and object-oriented programming. It also discusses Java keywords, data types, variables, and operators, alongside control statements and the Scanner class for user input. The content appears to be structured as a series of lessons or sessions, providing foundational knowledge for Java programming.

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)
34 views49 pages

Notes Batch 1215 Lyst1735889173989

The document outlines key concepts in Java programming, including definitions of IT, software, and hardware, as well as features of Java such as simplicity, platform independence, and object-oriented programming. It also discusses Java keywords, data types, variables, and operators, alongside control statements and the Scanner class for user input. The content appears to be structured as a series of lessons or sessions, providing foundational knowledge for Java programming.

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/ 49

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

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

You might also like