Notes Batch 1215 Lyst1738575352991
Notes Batch 1215 Lyst1738575352991
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
/*------------------*/
06-01-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Intrerface
-: Intrerface
abstract class A{
static final int y=199;
abstract void m1();
}
}
}
class D{
void k1(){
}
}
-: Intrerface
- it is pure abstract class
- it provide 100% abstraction
- it is used to communicate between 2 application or system
- it is just like a contract between customer and service provider
- syntax
access_modifier interface interface_name{
}
e.g
public interface A{
public interface A{
public abstract void m1();
public void m2();
abstract void m3();
void m4();
}
public interface A{
public static final int y2=100;
static final int y1=100;
public final int y3=100;
public static int y4=100;
static int y5=100;
final int y6=100;
public int y7=100;
int y8=3200;
}
}
public interface B extends A{
}
public interface D{
}
public interface B extends A,D{
}
public class TT implements A{
}
public interface D{
}
public class TT implements A,D{
}
public interface A{
}
public interface D{
}
public class TT extends W implements A,D{
1. Create a class named 'Rectangle' with two data members 'length' and 'breadth'
and two methods to print the area and perimeter of the rectangle respectively. Its
constructor having parameters for length and breadth is used to initialize length
and breadth of the rectangle. Let class 'Square' inherit the 'Rectangle' class with
its constructor having a parameter for its side (suppose s) calling the constructor
of its parent class as 'super(s,s)'. Print the area and perimeter of a rectangle
and a square
2. Create a class named 'Shape' with a method to print "This is This is shape".
Then create two other classes named 'Rectangle', 'Circle' inheriting the Shape
class, both having a method to print "This is rectangular shape" and "This is
circular shape" respectively. Create a subclass 'Square' of 'Rectangle' having a
method to print "Square is a rectangle". Now call the method of 'Shape' and
'Rectangle' class by the object of 'Square' class.
3. Write a Java program to create a Animal interface with a method called bark()
that takes no arguments and returns void. Create a Dog class that implements Animal
and overrides speak() to print "Dog is barking".
4. Write a Java program to create an interface Shape with the getArea() method.
Create three classes Rectangle, Circle, and Triangle that implement the Shape
interface. Implement the getArea() method for each of the three classes.
5. Write a Java program to create an interface Playable with a method play() that
takes no arguments and returns void. Create three classes Football, Volleyball, and
Basketball that implement the Playable interface and override the play() method to
play the respective sports.
/*------------------*/
07-01-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception
-: static keyword
1. it is a keyword
2. it is a class level keyword
3. if variable is static then it will create a single copy of variable
4. all access_modifier are applicable to static variable and method
5. it is a modifier
6. to static variable memory alocation done when class loaded into memory
7. to static variable memory dealocation done when class unloaded from memory
8. final modifier is applicable to static variable and method
9. it is recommended to access static variable and method by using class_name
10. you can not declare constructor,local variable,outer class and abstract method
as static
11. you can not override static method
12. you can overload static method
13. you can declare static block
-syntax
static {
/*
static block
static block execute before the main() method
*/
}
14. in interface by default all variables are static
-: final keyword
1. it is a keyword
2. if variable is final then you can not change its value
3. if method is final then you can not override that method
4. if class is final then you can not create its child class
5. you can not declare constructor,abstract method as final
6. final modifier is applicable to local variable
7. in interface by default all variables are final
8. you can overload final method
9. static modifier is applicable to final variable and method
10. you can define main() method as final
11. you can not declare block as final
12. it is a modifier
- create a class Dog - it is a sub class of Animal and override the Animal class
method
- create a class Tiger - it is a sub class of Animal and override the Animal class
method
- create a class Cat - it is a sub class of Animal and override the Animal class
method
/*-------------------*/
08-01-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception
-: Exception
- it is unwanted event occurs during the execution of program
e.g FileNotFoundException, SQLException
- types of exception
a) compiletime exception
b) runtime exception
a) compiletime exception
- the exception which checked at the compiletime is called as compiletime exception
- it is also called as checked exception
e.g FileNotFoundException, IOException , SQLException etc
- in program if checked exception occurs and programmmer does not define exception
handle code then compiler will not allowed to execute the program
- so if checked exception occurs in then programmmer must define exception handle
code
b) runtime exception
- the exception which does not identify by compiler and occurs during the execution
of program it is called as runtime exception
- it is also called unchecked exception
e.g ArithmeticException, NullPointerException etc
- in program if unchecked exception occurs and programmmer does not define
exception handle code then also compiler will allowed to execute the program
-: exception
- it will occurs due to lack of logical programmming
- programmmer is responsibile for exception
- exception can be handle during the execution of program
e.g
FileNotFoundException, NullPointerException etc
-: Error
- it will occurs due to lack of hardware resources
- programmmer is not responsibile for error
- error can not be handle during the execution of program
e.g StackOverflowError, VirtualMachineError etc.
-: Exception Handle
- exception handle means to provide the alternative solution for code
- if programmmer does not define any exception handle code means neither try-catch
block nor throws keyword then JVM will handle the exception
a) try-catch-finally block
-: try block
- it is a keyword
- syntax
try{
}
- generally programmmer a define code which may raised the exception
- if exception occurs in a try block following things will happen
a) at which line the exception is occurs further code will not execute by JVM
b) try block will throw the exception object
}catch(exception){
try{
}finally{
try{
}catch(exception){
}finally{
-: catch block
- it is a keyword
- in catch block programmmer define exception handle code
- one try block have many catch blocks
- one catch block handle only one exception
- at a time only one exception will raised in try block so though you define many
catch blocks only one exception will handle at a time
- syntax
catch(exception obj){
}catch(Exception e){
}catch(Exception e){
}catch(Exception e){
- if exception raised in try block then it will throw exception object then
- that exception object will catch by immediate catch block define after the try
- so if the catch block is able to handle the exception then execute catch block
- if it is not then it will check is any catch define after it
- if it is yes then pass that exception object to next catch block and so on....
- if it is no then JVM will handle the exception
try{
System.out.println("Line-1");
System.out.println(a);
System.out.println(b);
int c=a/b;
System.out.println(c);
System.out.println("Line-2");
}catch(ArithmeticException e){
System.out.println(e);
}catch(RuntimeException e){
System.out.println(e);
}catch(Exception e){
System.out.println(e);
}
-: Question
a) explain try-catch block
b) how JVM will handle the exception
/*-------------------*/
09-01-2024
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception
-: finally block
- it is the last block in try-catch block sequence
- syntax
finally{
- it is used to define a cleanup code for the resources that you used or open
either in try block or in catch block
- one try block have only one finally block
- you can define try-catch block in finally block
- after the finally you can not define catch block
- finally block will execute in both situation, if exception occurs then finally
block will execute and if exception not occurs then also finally block will execute
try{
db.open();
db.insert();
//db.close();
}catch(SQLException e){
print(e);
}finally{
db.close();
}
-: finalize()
- it is a method
- it is present in Object class
- Object class present in java.lang package
- you can override finalize()
- it is called by garbage collector before destroying the object
- finalize() method will detach all resources from object and make ready that
object to destroy
- syntax
protected void finalize(){
-: Question
1. what is difference between final, finally and finalize();
2. explain finally block
/*-------------*/
10-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception
-: throws keyword
- it is a keyword
- it is very dangerous keyword in java
- it is a method level keyword
- it is very effective for checked exception
- it is not much effective for unchecked exception
- you can define many exception for throws keyword, you can handle many exception
by using throws keyword
-
public class D {
public D() throws ArithmeticException{
}
public static void main(String[] args) throws Exception,ArithmeticException{
D d1 = new D();
d1.v1();
}
- if calling method throws any exception then caller method must throw either same
exception or its parent class exception
- child to parent sequence should be there
- throws keyword will delegate the responsibility of exception handling to caller
method
-: throw keyword
- it is a keyword
- it is used to throw exception object
- generally it is used to throw user define exception object
-: message printing
1) print object
try{
System.out.println(10/0);
}catch(ArithmeticException e){
System.out.println(e);
}
- it will print name of exception and message related to the exception
2) getMessage() method
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
System.out.println(e.getMessage());
}
- it will print message related to the exception
- this method is present in Throwable class
3) printStackTrace() method
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
//System.out.println(e.getMessage());
e.printStackTrace();
}
- it will print name of exception, message related to the exception and line
numbers affected by exception
- this method is present in Throwable class
4) custom message
try{
System.out.println(10/0);
}catch(ArithmeticException e){
//System.out.println(e);
//System.out.println(e.getMessage());
//e.printStackTrace();
System.out.println("The Arithmetic Exception is Raised...");
}
- you can print your own message
-: Interview Question
1. name of exception
2. which package it is present
3. type of exception
4. who is its parent class
5. who is its child class
6. when it occurs
7. in which version it introduce
1. Arithemetic
2. Runtime
3. NullPointer
4. InputMismatch
5. NumberFormat
6. IndexOutOfBounds
7. ArrayIndexOutOfBounds
8. StringIndexOutOfBounds
9. ClassNotFound
10. FileNotFound
11. IOException
12. SQLExcelption
13. Interrupted
14. llegalArgument
15. IllegalThreadState
16. StackOverFlowError
17. NoClassDefFoundError
18. NegativeArraySize
19. ExceptionInInitializerError
20. AssertionError
------------------
/*-------------*/
11-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Exception
1. Write a Java program that throws an exception and catch it using a try-catch
block.
2. Write a Java program to create a method that takes an integer as a parameter and
throws an exception if the number is odd.
/*-------------*/
13-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String
-: String
- it is a class in java
- it is a final class
- it is present in java.lang package
- it is a group of characters, set of characters.
- inernally it is a character array
- Object
1) String s1="Yellow";
2) String s2=new String("Pink");
-: StringBuffer
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuffer class
- Object
1) StringBuffer sb=new StringBuffer();
2) StringBuffer sb=new StringBuffer(String str);
-: StringBuilder
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuilder class
- Object
1) StringBuilder sb=new StringBuilder();
2) StringBuilder sb=new StringBuilder(String str);
/*-------------*/
14-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String
/*-------------*/
17-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: String
-: StringBuffer
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuffer class
- Object
1) StringBuffer sb=new StringBuffer();
2) StringBuffer sb=new StringBuffer(String str);
-: StringBuilder
- it is a class
- it is a final class
- it is present in java.lang package
- you can create String object as mutable by using StringBuilder class
- Object
1) StringBuilder sb=new StringBuilder();
2) StringBuilder sb=new StringBuilder(String str);
1. introduce in java-1.0
2. it will travel in both direction (forward and backward)
3. you can perform CRUD operation
4. syntax
for(initialization;condition;update_value){
-: Note - this for each loop is used to fetch the value from collection only
-: java-1.5
a) Annotation
b) co-variant return_type
c) for each loop
d) static import
e) generic collection
/*-------------*/
20-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection
-: Array
- it is a collection of homogenous data_type and having continous memory locations
- syntax
data_type array_name[]=new array_name[size];
- you can perform CRUD operation
- you can store many values under one variable_name
- it will reduce length of code
- array_name is identifiers
- array comes in reference data_type
- you can store primitive and reference value
-: Disadvantage
1. array has a fixed size
2. you can not change the size of array - it is not a growable in nature
3. syntax
data_type array_name[]=new array_name[size];
e.g
int y[]=new int[5];
4. no predefine method available for CRUD operation
5. with respective memory management array is not recommended
6. no predefine data structure is available
7. you can store only homogenous elements
8. you can store primitive and reference value
-: Collection
1. it will not have a fixed size
2. you can change the size of Collection - it is a growable in nature
3. syntax
List list=new ArrayList();
4. predefine method available for CRUD operation
5. with respective memory management collection is recommended
6. predefine data structure is available
7. you can store heterogenous elements
8. you can store only reference value
-: Collection
- it is a group of individual objects - that represent as single entity is called
Collection
-: Collection Framework
- it has several classes and interfaces that used to store a group of individual
objects to represent as single entity
-: Collection
- it is a group of individual objects - that represent as single entity is called
Collection
- it is an interface
- it introduce in jdk-1.2
- it is present in java.util package
- it is a child interface of Iterable interface
- List, Queue, Set are child interface of Collection interface
- it has some common method which are applicable to List,Queue and Set
-: Collections
- it is a class
- it is present in java.util package
- it has some utility methods
e.g sort(), search() etc.
- so you can call it as utility class
- it introduce in jdk-1.2
-: List
- it is an interface
- it introduce in jdk-1.2
- it is present in java.util package
- it is a child interface of Collection interface
- ArrayList, LinkedList, Vector and Stack are implemented classes of List interface
10 44 55 8
- by using index you can preserved insertion order
-: Legacy class
- Vector and Stack , HashTable and Properties are legacy classes
- it introduce in jdk-1.0
- the classes which came from older version is called as legacy classes
/*-------------*/
21-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection
-: ArrayList
- it is a class
- it introduce in java-1.2
- it is present in java.util package
- it implements List interface
- internally it is an array and that is growable in nature (i.e. resizable array)
- you can insert duplicate element
- insertion order will preserved
- you can insert null value
- you can insert heterogenous elements also
- Object
1. List list=new ArrayList();
2. ArrayList list=new ArrayList();
3. ArrayList list=new ArrayList(Collection c);
-: Iterator
- it is an interface
- it is present in java.util package
- it introduce in java-1.2
- it has 3 methods
a) public boolean hasNext()
b) pulbic Object next()
c) public default void remove();
- it will move only in forward direction
- it is an universal iterator
- it is parent interface of ListIterator interface
-: Iterable
- it is an interface
- it is present in java.lang package
- it introduce in java-1.5
- it has 1 method
a) public Iterator iterator();
- it is parent interface of Collection interface
-: ListIterator
- it is an interface
- it is present in java.util package
- it introduce in java-1.2
- it has 9 methods
a) public boolean hasNext()
b) pulbic Object next()
c) public void remove();
d) public boolean hasPrevious();
e) pulbic Object previous()
f) public int nextIndex();
g) public int previousIndex();
h) public void set(Object e);
i) public void add(Object e);
- it is a child interface of Iterator interface
- it is applicable only for List interface
- it will move in both direction forward or backward direction
-: Stack
- Last In First Out (LIFO)
- First In Last Out (FILO)
-: Queue
- First In First Out (FIFO)
- Last In Last Out (LILO)
/*-------------*/
22-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection
-: LinkedList
-> ArrayList
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. it implements List interface
5. it also implements RandomAccess, Cloneable, Serializable interface
6. it has almost all methods are non synchronized
7. non synchronized means - that many threads can access one method at a one time -
so it is thread not safe
8. because it is non synchronized the performance of ArrayList is relatively high
9. it is not a legacy class
10. it is internally array - it is index
- it is underlying a data structure of resizable of growable array
11. Object
a) List list=new ArrayList();
b) ArrayList list=new ArrayList();
12. it is best to used for retrieval operation
13. it is worst to used for insertion and deletion operation in the middle
-> Vector
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.0
4. it implements List interface
5. it also implements RandomAccess, Cloneable, Serializable interface
6. it has almost all methods are synchronized
7. synchronized means - that one thread can access one method at one time - so it
is thread safe
8. because it is synchronized the performance of Vector is relatively low
9. it is a legacy class
10. it has one child class - that is Stack
11. Object
a) List vector=new Vector();
b) vector vector=new Vector();
-> LinkedList
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. it implements List interface
5. it also implements Deque, Cloneable, java.io.Serializable interface
- Deque is child interface of Queue
- Deque introduce in jdk-1.6
- Queue interface introduce in jdk-1.5
- so from jdk-1.5 LinkedList implements Queue interface
6. it is not legacy class
7. Object
a) List list=new LinkedList();
b) LinkedList list=new LinkedList();
c) Queue list=new LinkedList();
8. it best to used for insertion and deletion operation in the middle
9. it worst to used to retrieval operation
10. it not implements RandomAccess interface
11. it is underlying data structure of doubly linkedlist
-: Question
a) what is difference between array and ArrayList
b) what is difference between Iterable and Iterator
c) what is difference between ArrayList and LinkedList
/*-------------*/
23-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection
-: Set
-> List
1. it is allowed to insert duplicate elements
2. it will preserved insertion order
3. it has index
-> Set
1. it is interface
2. it is a child interface of Collection
3. it introduce in java-1.2
4. HashSet and TreeSet are implemented classes of Set interface
5. it is a group of individual objects to represent as a single entity where
duplicate elements are not allowed and insertion order will not preserved
6. it does not have index
7. it is present in java.util package
8. SortedSet is a child interface of Set
-> HashSet
1. it is a class
2. it is present in java.util package
3. it introduce in java-1.2
4. Object
a) Set set=new HashSet();
b) HashSet set=new HashSet();
5. it implements Set interface
6. it also implements Serializable and Cloneable interface but not RandomAccess
interface
7. you can insert heterogenous elements
8. you can insert null as value
9. duplicate elements are not allowed
- if enter any duplicate element by add() method it will return false
10. insertion order will not preserved
11. No replace method is present
-: Question
a) explain Set interface
b) what is difference between HashSet and TreeSet
/*----------------*/
24-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Collection
-> TreeSet
1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. it implements Set interface
5. it also implements SortedSet and NavigableSet interface
- SortedSet is a child interface of Set
- it introduce in jdk-1.2
- NavigableSet is a child interface of SortedSet
- it introduce in jdk-1.6
- it also implements Cloneable, Serializable interface
6. Object
a) Set set=new TreeSet();
b) SortedSet set=new TreeSet();
c) NavigableSet set=new TreeSet();
d) TreeSet set=new TreeSet();
7. you can insert only homogenous elements
8. if you insert heterogenous elements then you will get ClassCastException
9. you can not insert heterogenous elements
10. you can not insert null as a value
11. if you insert null as a value then you will get NullPointerException
12. duplicate elements are not allowed
13. insertion order will not preserved
14. when you fetch the elements from TreeSet it will come according to some sorting
order
15. the elements which you insert into TreeSet must implements either Comparable or
Comparator interface
-: Map
- List and Set -> both are a group of individual objects and it is used to
represent as a single entity
- Map
- it is used to store a data into key and value pair format
- if you want to represent a group of objects into key and value pair format then
you can used Map interface
- key and value pair format called as entry
- you can consider Map as a collection of Entry objects
- it is interface
- it is not a child interface of Collection
- it is present in java.util package
- it introduce in jdk-1.2
- HashMap,HashTable,TreeMap are implemented classes of Map
- SortedMap is the child interface of Map
- the data will store into key and value pair format
- key -> should be unique - duplicate key is not allowed
- value -> duplicate value is allowed
- you can insert object as key and value
-: Entry
- it is interface
- it is inner interface of Map
---
//parnet interface
public interface A{
}
//child interface
public interface B extends A{
}
---
//outer interface
public interface A{
//inner interface
public interface B{
}
}
---
- it introduce in jdk-1.2
- it has following methods
a) Object getKey();
b) Object getValue();
c) Object setValue(Object o);
-: HashMap
1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. Object
a) Map map=new HashMap();
b) HashMap map=new HashMap();
c) HashMap map=new HashMap(Map map);
5. it implements Map interface
6. it also implements Cloneable, Serializable interface
7. it is underlying a data structure of HashTable
8. insertion order will not preserved - it is based on hash-code of keys
9. duplicate key is not allowed - key must be unique
10. duplicate value is allowed
11. you can insert heterogenous elements as key and value
12. you can insert null as key and value also
/*-----------------*/
27-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: TreeMap
-: TreeMap
1. it is a class
2. it is present in java.util package
3. it introduce in jdk-1.2
4. it implements Map, SortedMap and NavigableMap interface
- SortedMap is child interface of Map
- it is present in java.util package
- it introduce in jdk-1.2
-: Comparable
1. it is interface
2. it is present in java.lang package
3. it introduce in jdk-1.2
4. it is used to provide default sorting order
- String and all wrapper classes implements Comparable interface
5. it has only 1 method
public int compareTo(Object o);
-: Comparator
1. it is interface
2. it is a Functional Interface
3. it is present in java.util package
4. it introduce in jdk-1.2
5. it is used to provide custom sorting order
6. it has 2 methods
a) public int compare(Object o1, Object o2);
b) public boolean equals(Object o);
7. Collator and RuleBasedCollator class implements Comparator interface
-: Question
a) what is difference between Comparable and Comparator
b) what is difference between TreeMap and HashMap
c) what is difference between HashMap and HashTable
-: JBK Test
/*-----------------*/
28-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Generic Collection
- Boxing
1. it means packaging
2. boxing means to convert primitive value into wrapper class object
3. if this convertion done by compiler automatically, it is called as auto-boxing
4. auto-boxing introduce in jdk-1.5
- Unboxing
1. it means unpackaging
2. unboxing means to convert wrapper class object into primitive value
3. if this convertion done by compiler automatically, it is called as auto-unboxing
4. auto-unboxing introduce in jdk-1.5
a) byte Byte
b) short Short
c) int Integer
d) long Long
e) float Float
f) double Double
g) char Character
h) boolean Boolean
-: utility method
a) valueOf()
- it will convert String and primitive value into wrapper class object
- this method is present in all wrapper classes
- syntax
public wrapper_class_name valueOf(argument);
b) ***Value();
- it will return value of wrapper class object
- it will convert wrapper class object into primitive value
- syntax
public primitive data_type ***Value();
c) parse***(String s);
- this method is used to convert String into primitive value
- this method is available in all wrapper classes except character
- syntax
public primitive data_type parse***(String s);
d) toString();
- it will convert wrapper class object into String
- this method is available in all wrapper classes
- syntax
public String toString();
-: JDK-1.5
a) for each loop
b) var-arg method
c) static import
d) co-variant return type
e) annotation
f) generic collection
g) auto-boxing and auto-unboxing
-: jdk-1.7
a) binary literal
b) String as expression in switch case
c) used underscore in literal
int y=136775;
int h=13_67_75;
-: Question
a. what is generic collection
b. what is difference between non-generic and generic collection
c. explain auto-boxing and auto-unboxing
-: JBK Test
/*--------------------*/
29-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Generic Collection Practical
1. Write a Java program to create a generic method that takes a list of numbers and
returns the sum of all the even and odd numbers.
2. Write a Java program to create a generic method that takes two arraylist of the
same type and checks if they have the same elements in the same order.
/*----------------*/
30-01-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: Java-1.8
1. interface
- by default all methods in interface are public and abstract
- by default all variables in interface are public, static and final
2. functional interface
- the interface which have only and only one abstract method
- you can not declare functional interface as empty
- if a interface is called functional interface then it should contain one abstract
method
- to create a functional interface @FunctionalInterface annotation is used
- syntax
@FunctionalInterface
public interface interface_name{
//one abstract method
}
3. lambda expression
public void m1(){
print("Apple");
}
->
public int total(int a,int b) {
int c=0;
c=a+b;
return c;
}
-
int total(int a,int b) {
int c=0;
c=a+b;
return c;
}
-
total(int a,int b) {
int c=0;
c=a+b;
return c;
}
-
(int a,int b) {
int c=0;
c=a+b;
return c;
}
-
(int a,int b) ->{
int c=0;
c=a+b;
return c;
};
-: Stream API
/*----------------*/
03-02-2025
-: Last Session
-: Mark Your Attendence
-: Today's Topic
-: File Handling
-: DATA STORE
- variable - int, String, double, boolean, char
- in variable you can store data until program is acitve
- in variable you can not store data permanently
-: File
- it is used to store a data permanently
- generally it is used to store a small amount of data
- every file has an extension
e.g
image - jpg, png
audio - mp3
video - mp4
excel - xlsx
word - docx
pdf - pdf
text file - txt
1. create a file
- open a file
2. write a file / read a file
3. close a file
- delete a file
d) write a file
String dir_path="C:\\Ek\\sairaj\\";
String file_path="aditi.txt";
File file=new File(dir_path+file_path);
try {
// FileWriter file_writer=new FileWriter(dir_path+file_path);
// FileWriter file_writer=new FileWriter("C:\\Ek\\sairaj\\
shubham.txt");
//FileWriter file_writer=new FileWriter(file,true);
FileWriter file_writer=new FileWriter(new
File(dir_path+file_path),true);
System.out.println("File Crreated....");
String data="My name is Aditi. I like an Orange.";
// file_writer.write(100);
file_writer.write(data);
file_writer.flush();
file_writer.close();
System.out.println("Data Write into File");
}catch(IOException e) {
System.out.println(e);
}
--
-: Data
-: Flower
- Rose.txt (color name)
- Lotus.txt
- Lilly.txt
-: State
- Maharashtra.txt (capital name)
- Goa.txt
- Tamilnadu.txt
-: Result