Notes Batch 1215 Lyst1735889173989
Notes Batch 1215 Lyst1735889173989
13-11-2024
- Software / Application
/*--------------*/
14-11-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Features of Java
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
/*-----------------*/
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
2) You can not used special symbols - except underscore [ _ ] and dollar [$]
e.g
int y_4; double book$price;
long w%t; // Error
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
/*--------------*/
-: 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;
class Demo{
byte b1;
long h1;
int y1;
String s1;
Demo d3;
double dd;
boolean ss;
short aa;
Demo dc;
char t1;
float z1;
}
-: 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);
}
}
}
- 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);
}
}
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);
}
}
/*---------------*/
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
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
->
b) relational operator (comparison operator) (6)
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
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.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
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
- if...else
- syntax
if(condition){
//if block
}else{
//else block
}
- 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
- 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. 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);
}
int sum=0;
for(int k=1;k<=10;k++){
sum=sum+k;
}
print(sum);
/*--------------*/
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
n y
1234 4
123 3
12 2
1 1
0
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");
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
- it is a sub program
- it will divide a large program into a small program
- syntax / method_proptotype / method_signature
}
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
-: 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
/*--------------*/
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
/*------------------*/
05-12-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Practical
int cal=1;
public int m1(int base,int power){
for(int i=1;i<=power;i++){
cal=base*cal;
}
return cal;
}
- 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");
/*------------------*/
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();
}
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
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
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
-: 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");
}
}
-: Question
a) what is constructor?
b) what is used fo constructor?
c) explain types of constructors.
/*-------------------*/
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.
- 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
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("*");
}
}
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;
}
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;
for(int k=1;k<=10;k++){
if(k%2==0)
print(-1*k);
else
print(k);
}
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;
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;
}
}
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);
}
}
/*--------------*/
16-12-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Array In Java
-: Array
class Student{
Student s1=new Student();
Student s[]=new Student[5];
//int age[]=new int[5];
//String name[]=new String[5];
}
a) declaring array
-
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
-:
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
-: 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;
}
}
}
/*-------------*/
18-12-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Array Program In Java
-: 2D array
/*-------------*/
19-12-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Activity
Name -:
Hobbies -:
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
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();
}
}
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
/*-------------*/
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
-: 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
-: 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
-: 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();
}
}
}
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
-: return_type
- it is applicable to reference data_type
class_name
interface_name
enum_name
array_name
-: 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
-: 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(){
/*------------------*/
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();
}
- 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{
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();
- 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
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