0% found this document useful (0 votes)
2 views403 pages

Core Java

Uploaded by

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

Core Java

Uploaded by

johncena70124774
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

01-01-2025

01-01-2025
01-01-2025

EXECUTION IN JAVA:
2-1-2025
Thursday, January 2, 2025 7:45 PM

Addition of two numbers

class AddTwoNumbers{
public static void main(String[] args){
int num1=2;
int num2=3;
int sum=num1+num2;
[Link](sum);
}
}

[Link] main method mandatory for compilation?

No, Program execution starts from main method. Main method is a mediator and it
will send our program to jvm during the execution time.
class AddTwoNumbers{
{
int num1=2;
int num2=3;
int sum=num1+num2;
[Link](sum);
}
}

Wipro 2019 java developers

[Link] we create a empty class file , can we compile and execute it?

yes we can compile the source file, but we cannot execute it

class AddTwoNumbers
{

What is class?

class is a structured layout


class is blueprint
full stack java batch-21 Page 1
class is blueprint
class contains variables,methods and class has a body
class has a main method
main()-->starting point for program execution

public static void main(String[] args)

[Link] main method has public?

To be accessed by jvm from different folder main method should be public.

To allocated memory inside the class,main method has the static keyword

why main method has void?

main method doesnot return any value as output, main method will send the logic
to jvm. so main method has a keyword void

Why the main method has string data type?

*** Any value can be represented as a string data type, further we can convert any
value from string data type to its own data type

Why the main method as array[]?

For reading multiple values from the end user main method should be of array data
type

why the main method has args?


full stack java batch-21 Page 2
why the main method has args?

For reading the values from the end user, during the runtime, main method has args
parameter.

Downloading java software and setting path:

step1: Go to google and type

"jdk software download"

Download Link:

[Link]

step 2:

select type of jdk(jdk 21) and select platform as "windows"

Direct download Link:

[Link]

step 3:

go to downloads folder, and double click on exe file

step 4:

click on next, next......

java software will be successfully installed in our computer

Note:

After successfull installation we will find a folder with name:

"java" in c:/program files


9652592663
full stack java batch-21 Page 3
"java" in c:/program files
9652592663
set the path in environmental variable

steps internship

full stack java with internship

100% placement assistance

full stack java batch-21 Page 4


3-1-2025
Friday, January 3, 2025 7:59 PM

Setting java path in environment variables

Rightclick on This pc-->properties-->Advanced System Settings-->A window will


open-->Click on Environment Variables-->click "new" on "System variables"

Variable name:path
Variable value:C:\Program Files\Java\jdk-21\bin;

Click "ok" for three times

Java is now ready for developing programs

To check the java version available in our system

java -version

C:\Users\BSNV SATYANARAYANA>java -version


java version "21.0.5" 2024-10-15 LTS
Java(TM) SE Runtime Environment (build 21.0.5+9-LTS-239)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.5+9-LTS-239, mixed mode, sharing)

Program 1:

Write a program to display a message "Welcome to java world"

class displaymessage
{
public static void main(String[] args)
{
[Link]("Welcome to java world");

}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java displaymessage
Welcome to java world
full stack java batch-21 Page 1
Welcome to java world

Writing , saving, compiling and executing java program:

step 1: open notepad and type the program

step 2:save the program in a folder(folder name is as your wish) with language extension
name

[Link]

step 3: click on file-->Save-->save as Type must be"All files"-->click on save

step 4: go the folder-->type cmd in address bar--> and press enter

step 5: compile the program as follows

javac [Link]

ex: javac [Link]

step 6: execute the program as follows

syntax:

java class_name

Program 2:

write a program to display sum of two numbers:

class Addition
{ 3 4
public static void main(String[] args)
{
int a=3,b=4,c; a b
c=a+b;
[Link](c);
} 7
}
c
full stack java batch-21 Page 2
c
[Link]

full stack java batch-21 Page 3


4-1-2025
Saturday, January 4, 2025 8:08 PM

Program:3

Write a program to display details of a user?

username
password
firstname
lastname
mailid

class UserDetails
{
public static void main(String[] args)
{
String username="codingbrains";
String password="codingbrains";
String firstname="coding";
String lastname="brains";
String mailid="codingbrainsofficial@[Link]";
[Link](username);
[Link](password);
[Link](firstname);
[Link](lastname);
[Link](mailid);
}
}

output:
D:\batch-21>java [Link]
codingbrains 9652592663
codingbrains
coding
brains
codingbrainsofficial@[Link]

Assignment

Write a program to display employee details

layout:

employname(String)
full stack java batch-21 Page 1
employname(String)
employid(int)
salary(int)

Develop a program to read student details like name, branch, rollno, marks, display
name,branch,rollno, marks, percentage

class Studentdetails
{
public static void main(String[] args)
{
String name="rajesh";
String branch="CSE";
int rollno=23456;
int s1=75;
int s2=88;
int s3=66;
int s4=55; Name=
int s5=77;
int s6=85;
int totalmarks=s1+s2+s3+s4+s5+s6;
float percentage=(s1+s2+s3+s4+s5+s6)/6; Name=rajesh
[Link]("Name="+name)
[Link]("Branch="+branch);
[Link]("Subject1="+s1);
[Link]("Subject2="+s2);
[Link]("Subject3="+s3);
[Link]("Subject4="+s4);
[Link]("Subject5="+s5);
[Link]("Subject5="+s6);
[Link]("TotalMarks="+totalmarks);
[Link]("Percentage="+percentage);
}
}

output:

D:\batch-21>java Studentdetails
Name=rajesh
Branch=CSE
Subject1=75
Subject2=88
Subject3=66
Subject4=55
Subject5=77
full stack java batch-21 Page 2
Subject5=77
Subject6=85
TotalMarks=446
Percentage=74.0

Data types in java:

The types of data which we are expecting as input to a java program are known as
data types in java

Datatype in java are categorized into two types

a)primitive data types


b)non primitive data types
a)primitive data types

"The single valued data types are called as primitive data types

primitive data types are categorized into 4 types

a)integer data type


b)float data type
c)character data type
d)Boolean data type

a)Integer data types

The numeric data which is represented without decimal point is called as integer data
types

Integer data type is again categorized into 4 types

a)byte
b)short
c)int
d)long 0 or 1
a==>byte bit means 0 or 1
a)byte -8bits

range=-128 to 127

Program
full stack java batch-21 Page 3
range=-128 to 127

Program

Class Bytedata
{
public static void main(String[] args)
{
byte a=127;
[Link]("The value="+a);
}
}

full stack java batch-21 Page 4


5-1-2025
Sunday, January 5, 2025 8:00 PM

short- 2bytes
short- 2*8(1byte=8 bits)
-16bits bit -->1 or 0

Example:

class Datatypes
{
public static void main(String[] args)
{
short a=32767;
[Link]("The value="+b);
}
}

int:

The range of int is -2,147,483,648 to 2,147,483,647


int occupies 4 bytes of memory

Example:

class Datatypes
{
public static void main(String[] args)
{
int i=123456789
[Link]("The value of i is"+i);
}
}

D:\batch-21>javac [Link]
full stack java batch-21 Page 1
D:\batch-21>javac [Link]
[Link]: error: no suitable method found for
println(String,int)
[Link]("The value of i is",+i);
^
method [Link]() is not applicable
(actual and formal argument lists differ in length)
method [Link](boolean) is not applicable
(actual and formal argument lists differ in length)
method [Link](char) is not applicable
(actual and formal argument lists differ in length)
method [Link](int) is not applicable
(actual and formal argument lists differ in length)
method [Link](long) is not applicable
(actual and formal argument lists differ in length)
method [Link](float) is not applicable
(actual and formal argument lists differ in length)
method [Link](double) is not applicable
(actual and formal argument lists differ in length)
method [Link](char[]) is not applicable
(actual and formal argument lists differ in length)
method [Link](String) is not applicable
(actual and formal argument lists differ in length)
method [Link](Object) is not applicable
(actual and formal argument lists differ in length)
1 error

class Datatypes
{
public static void main(String[] args)
{
int i=1234567896;
[Link]("The value of i is"+i);
}
}

The value is 1234567896

long

The long data type stores data upto 16 digits. It occupies 8 bytes of memory.
In process of assigning long data type value we must use L or "l" in RHS of declaration

full stack java batch-21 Page 2


Example:

class Datatypes
{
public static void main(String[] args)
{
long creditcardNo=9898989898123L;
[Link]("The creditcard Number is="+creditcardNo);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Datatypes
The creditcard Number is=9898989898123

D:\batch-21>

Float Data types:

The data types which are represented with decimal point are called as float data types

Float data types are divided into two types

a)float
float occupies 4 bytes memory

class Datatypes
{
public static void main(String[] args)
{
float a=12.34567F;
[Link]("The float value is="+a);
}
}

Note: In java if we are taking decimal values and if we are declaring the value as float data
type, we have assign F or f in the RHS

b)double
==>8 bytes of memory
full stack java batch-21 Page 3
==>8 bytes of memory

example:

class Datatypes
{
public static void main(String[] args)
{
double a=12.6787654;
[Link]("The double value="+a);
}
}

output:

D:\batch-21>java Datatypes
The double value=12.6787654

Character values:

The single valued character which is represented in single quotes is known as character
data [Link] data types occupies 2 bytes of memory

Ex: 'a','h','j'.........

The following are the three different ways to represent character data types

[Link] quotes

class Datatypes
{
public static void main(String[] args)
{
char ch='a';
[Link]("The character is="+ch);
}
}

output: ascii
D:\batch-21>java Datatypes
The character is=a

full stack java batch-21 Page 4


[Link] ascii value

class Datatypes
{
public static void main(String[] args)
{
char ch=76;
[Link]("The character is="+ch);
}
}

D:\batch-21>java Datatypes
The character is=L

[Link] format

Unicode Format website: [Link]

Example:

class Datatypes
{
public static void main(String[] args)
{
char ch='\u0041';
[Link]("The character is="+ch);
}
}

output:

D:\batch-21>java Datatypes
The character is=A

full stack java batch-21 Page 5


6-1-2025
Monday, January 6, 2025 8:09 PM

Why character data type occupies 2 bytes of memory?

In java character data type holds unicode characters, to allocate storage for unicode
characters java programming has 2 bytes of memory for character data type.

Boolean Data type

The boolean type which is existing in the form of "true" or "false" is known as
boolean [Link] data type occupies 1 bit of memory.
"true"
Class Datatypes
{ "false"
public static void main(String[] args)
{ 1
boolean b1=true;
boolean b2=false; 0
[Link]("boolean value="+b1);
[Link]("boolean value="+b2);
}
}

output:
D:\batch-21>java Datatypes
boolean value=true
boolean value=false

Type Casting:

Converting one data type into another data type is called as type casting. In java the
following are the two types of type casting

[Link] type casting


[Link] type casting

implicit type casting: The process of converting lower data type value into higher
data type value is called as implicit type casting.

explicit type casting:The process of converting higher data type value into lower data
type value is called as implicit type casting.

implicit type casting:

full stack java batch-21 Page 1


Converting lower data type value into higher data type value is called implicit type
[Link] is also called as widening. There will be no loss of information

class Implicttype
{
public static void main(String[] args)
{
byte x=10;
int y;
y=x; //placing 1 byte x value into 4 bytes y value
[Link](x); //10
[Link](y);//10
}
}

output:
D:\batch-21>java Implicttype
10
10

class Implicittype
{
public static void main(String[] args)
{
char x='a';
int y;
y=x;//placing 2 bytes x value into 4 bytes of value;
[Link](x);//a
[Link](y);//97
}
}

output:
D:\batch-21>java Implicittype
a
97

Explicit type casting:

[Link] higher data type value into lower data type value is called explicit type
casting.
[Link] is also called as narrowing.
[Link] will be loss of information
4. we can perform explicit type casting by using the following syntax

src_variable=(src_datatype)dest_variable

class Typecasting
{
public static void main(String[] args)
{
double x=12.345; //occupies 8 bytes of memory
int y; //occupies 4 bytes of memory
y=(int)x;
[Link](x); //12.345
[Link](y);//12
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Typecasting
12.345
12

full stack java batch-21 Page 2


class:

[Link] is a structured layout


[Link] contain methods and variables.

object:

Object is a storage related to instance of class, holding the members of a class

full stack java batch-21 Page 3


7-1-2025
Tuesday, January 7, 2025 7:59 PM

object :

Object is a storage related to instance of a class holding the member of a class.


we use "new" keyword in java to create objects

Syntax of object_creation:

classname obj_name=new classname()

Define "static" keyword?

"static" keyword in java will decide the memory location of programming


components(variables,methods)

The programming component which are declared with "static" keyword will get the
memory inside the class.

The programming component which are declared without static keyword will get the
memory within the object

Variables are of two types

[Link] variables
[Link] static variables

[Link] variables

The variables which are declared with "static keyword" outside the method are
known as static variables.
static variables will get memory with in the class.

The variables which are declared without static keyword are known as non static
variables

The non static variables are divided into two types

a)Instance variables
b)Local variables

Instance variable
full stack java batch-21 Page 1
Instance variable

The non static variables which are declared outside the method are known as instance
variables or object variables
These instance variables will get the memory within the object

Local variables

The nonstatic variable which are declared inside the method are known as local
variables or method variables

The local variable will the memory within the method

program:

class Variables
{
int a=12;
static int b=13;
public static void main(String[] args)
{
int c=23;
Variables ob=new Variables();
[Link]("b value="+Variables.b);
[Link]("a value="+ob.a);
[Link]("c value="+c);
}
}

D:\batch-21>javac [Link]

D:\batch-21>java Variables
b value=13
a value=12
c value=23

D:\batch-21>
9652592663
Define global variables in java?

There is no concept of global variable in java, because we cannot declare variables


full stack java batch-21 Page 2
There is no concept of global variable in java, because we cannot declare variables
outside the class, which generate compilation error

Define local static variable in java?

There is no concept of declaring static local variable in java, it generates compilation


error.

full stack java batch-21 Page 3


8-1-2025
Wednesday, January 8, 2025 8:06 PM

Methods in Java

Methods are the actions and which are executed to generate results. Based on static
keyword methods are categorized into two types

[Link] methods
[Link] static methods(Instance methods)

[Link] methods

The methods which are declared with static keyword are called as static methods or
class methods

The static methods will get memory within the class , these methods can be accessed
with class name.

Syntax:

return_type method_name(para_list)
{ int a, int b;
method body int add(a,b)
} {
c=a+b;
class Methods return c;
{ }
static int x=123;
int y=124;
static void m1()
{
[Link]("m1 method");
[Link]("x value:"+x);

}
void m2()
{
[Link]("m2 method");
[Link]("y value:"+y);
}
public static void main(String[] args)
{
Methods.m1();
Methods ob=new Methods();
ob.m2();

}
}

output:
full stack java batch-21 Page 1
output:

D:\batch-21>java Methods
m1 method
x value:123
m2 method
y value:124

JVM Architecture:

JVM is divided into 3 components

[Link] area
[Link] area
[Link] stack area

full stack java batch-21 Page 2


9-1-2025
Thursday, January 9, 2025 8:01 PM

VM Architecture:

JVM is divided into 3 components

[Link] area
[Link] area
[Link] stack area

Method area:

The memory location where the class is loaded is known as Method area or Class
area.
static programming components will get the memory within the class.

Among static components , main() is automatically copied to java stack area to start
the execution process.

Heap Area:

The memory location where objects are created is known as Heap area.
While object creation Instance members will get the memory within the object.

Java stack area

The memory location where the methods are executed is known as java stack area.
main() is first copied on to a java stack area, and this main() will call the remaining
full stack java batch-21 Page 1
main() is first copied on to a java stack area, and this main() will call the remaining
methods

Example:

class Customerdetails
{
String custId="abc-1234";
String custname="codingbrains";
String city="Bangalore";
static long phno=9898981234L;
static String mailid="codingbrainsofficial@[Link]";
static void m1()
{
[Link]("Mailid="+mailid);
[Link]("Phone Number="+phno);
}
void m2()
{
[Link]("Customer Id="+custId);
[Link]("Customer Name="+custname);
[Link]("Customer City="+city);
}
public static void main(String[] args)
{
Customerdetails.m1();
Customerdetails ob=new Customerdetails();
ob.m2();
}
}

output:
D:\batch-21>java Customerdetails
Mailid=codingbrainsofficial@[Link]
Phone Number=9898981234
Customer Id=abc-1234
Customer Name=codingbrains
Customer City=Bangalore

Reading Input values in a java programs:

==>To read input values dynamically during runtime we use predefined class
"Scanner class". The Scanner class is available inside [Link] package.

The following are the some of the instance methods from Scanner class to read data to
java programs

[Link]()--> to read byte value


[Link]()--> to read short value
[Link]()--> to read int values
full stack java batch-21 Page 2
[Link]()--> to read int values
[Link]()--> to read Long value
[Link]()-->to read float values
[Link]()--> to read double values
[Link]()-->to read boolean values
[Link]()--->to read string values

we use javap command in command prompt to view predefined methods from


Scanner class

syntax:

javap [Link]

Scanner Class Location

C:\ProgramFiles\Java\jdk-21\lib\src

Extract the src zip folder

src-->[Link]-->java-->util

full stack java batch-21 Page 3


11-1-2025
Saturday, January 11, 2025 8:10 PM

Syntax for object creation for scanner class

Scanner s=new Scanner([Link])

syntax:

nextByte()

byte var=[Link]()

nextShort()

short var=[Link]()

nextInt()

int var=[Link]()

nextLong()

long var=[Link]()

nextFloat()
full stack java batch-21 Page 1
nextFloat()

float var=[Link]()

nextDouble()

double var=[Link]();

nextBoolean()

boolean var=[Link]()

nextLine()

String var=[Link]()

Develop a program to read and display Userdetails

import [Link];
class Userdetails
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
String username=[Link]();
[Link]("Enter the mailid:");
String mailid=[Link]();
[Link]("Enter the phoneno:");
long phoneno=[Link]();
[Link]("Username:"+username);
[Link]("Mailid:"+mailid);
[Link]("PhoneNo:"+phoneno);
}
}

output:
D:\batch-21>java Userdetails
Enter the username:
full stack java batch-21 Page 2
Enter the username:
codingbrains
Enter the mailid:
codingbrains@[Link]
Enter the phoneno:
9898981234
Username:codingbrains
Mailid:codingbrains@[Link]
PhoneNo:9898981234

Write a program to read and display Bookdetails(bookname,author,price)

import [Link];
class Bookdetails
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the bookname:");
String bookname=[Link]();
[Link]("Enter the author name:");
String author =[Link]();
[Link]("Enter the book price:");
int price=[Link]();
[Link]("Book name:"+bookname);
[Link]("Author name:"+author);
[Link]("Book price:"+price);
}
}

output:
D:\batch-21>java Bookdetails
Enter the bookname:
Java Complete Reference
Enter the author name:
Ashok
Enter the book price:
456
Book name:Java Complete Reference
full stack java batch-21 Page 3
Book name:Java Complete Reference
Author name:Ashok
Book price:456 codingbrainsofficial@[Link]

Assignment:

Develop a program to read and display product details(Product name, price,qty)

full stack java batch-21 Page 4


12-1-2025
Sunday, January 12, 2025 8:11 PM

Operators in Java operands

The special symbol which performs operations is known as operator

The following are the operators in java 2+3=5 Result

[Link] operators
[Link] operators operator
[Link] operators
[Link] decrement Operators
[Link] operator
[Link] operators

[Link] Operators

The operator which performs basic operations like addition, substraction,


Multiplication, division, Modulo division are called arthimetic operators

Operator Meaning
+ Addition 2)4(2 Quotient Value
- Substraction 4
* Multiplication -------
0 remainder
/ Division
% Modulo Division

Example:

import [Link];
class Addition
{
public static void main(String[] args)
{ EditPlus
Scanner s=new Scanner([Link]); Eclipse
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter the second number:");
int b=[Link]();
int c=a+b;
[Link]("The sum="+c);
}
}
full stack java batch-21 Page 1
}

output:
D:\batch-21>java Addition
Enter first number:
5
Enter the second number:
7
The sum=12

Program:

import [Link];
class Division
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter second number:");
int b=[Link]();
int c=a/b;
[Link]("The result="+c);
}
}

output:
D:\batch-21>java Division
Enter first number:
4
Enter second number:
2
The result=2

Program:

import [Link];
class ModuloDivision
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
full stack java batch-21 Page 2
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter second number:");
int b=[Link]();
int c=a%b;
[Link]("The result="+c);
}
}

output:
D:\batch-21>java ModuloDivision
Enter first number:
4
Enter second number:
2
The result=0

Relational Operators

The operators which performs comparision between two values and generate boolean
result are known as Relational Operators

Operator Meaning
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
== equal to
!= Not equal to

Program

import [Link];
class RelationalOperators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter the second number:");
full stack java batch-21 Page 3
[Link]("Enter the second number:");
int b=[Link]();
boolean c=a>b;
[Link]("The result is:"+c);
}
}

output:
D:\batch-21>java RelationalOperators
Enter first number:
5
Enter the second number:
7
The result is:false

Program

import [Link];
class RelationalOperators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter the second number:");
int b=[Link]();
boolean c=(a!=b);
[Link]("The result is:"+c);
}
}

output:
D:\batch-21>java RelationalOperators
Enter first number:
5
Enter the second number:
6
The result is:true

D:\batch-21>javac [Link]

D:\batch-21>java RelationalOperators
Enter first number:
full stack java batch-21 Page 4
Enter first number:
5
Enter the second number:
5
The result is:false

Logical Operators

The operators which perform comparision between boolean values and generate
boolean result are known as logical operators

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT

Logical AND:

In Logical AND if both the boolean values are true then the result is true, other wise
the resutl will be false

A B A&B
T T T
F T F
T F F
F F F

Program:

import [Link]
class booleanprogram
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the first value:");
boolean a=[Link]();
[Link]("Enter the second number:");
boolean b=[Link]();
boolean c=a&&b;
[Link]("The result is:"+c);
}
full stack java batch-21 Page 5
}
}

full stack java batch-21 Page 6


16-1-2025
Thursday, January 16, 2025 8:06 PM

Logical OR(||)

In Logical OR if either one of the boolean values are true then the result is true
other wise the result is false

A B A||B
T T T
F T T
T F T
F F F

program:

import [Link];
class LogicalOperators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the first value:");
boolean a=[Link]();
[Link]("Enter the second value:");
boolean b=[Link]();
boolean c=a||b;
[Link]("The result is:"+c);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java LogicalOperators
Enter the first value:
True
Enter the second value:
False
The result is:true
full stack java batch-21 Page 1
The result is:true

D:\batch-21>java LogicalOperators
Enter the first value:
False
Enter the second value:
False
The result is:false

Logical NOT:

In Logical NOT if the boolean value is True then the result is false, if the boolean
value is False then the result is true

A !A
T F
F T

Program:

import [Link];
class LogicalOperators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the value:");
boolean a=[Link]();
[Link](!a);
}
}

D:\batch-21>java LogicalOperators
Enter the value:
true
false

D:\batch-21>java LogicalOperators
Enter the value:
full stack java batch-21 Page 2
Enter the value:
false
true

Define Parameters or arguments?

Parameters are the variables which are used to transfer the data from one method
to another method

Parameters/arguments are divided into types

[Link] parameters
[Link] parameters.

Actual parameters

The parameters which recieve original values inside the called method are called
actual parameters

Formal Parameters

The parameters which recieve the value inside the method signature are called
formal parameters

Program:

import [Link];
class Addition
{
int add(int a, int b)
{
int c=a+b;
return c;
}
}
class Mainclass
{
public static void main(String[] args)
{ n1 n2
Scanner s=new Scanner([Link]);
[Link]("Enter the first number:");
full stack java batch-21 Page 3
{ n1 n2
Scanner s=new Scanner([Link]);
[Link]("Enter the first number:"); 5 6
int n1=[Link]();
[Link]("Enter the second number:");
int n2=[Link]();
Addition ob=new Addition();
int n3=[Link](n1,n2);
[Link]("The addition result is:",+n3);
}
}

full stack java batch-21 Page 4


17-1-2025
Friday, January 17, 2025 8:11 PM

import [Link];
class Addition
{
int add(int a, int b)
{
int c=a+b;
return c;
}
}
class Mainclass
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the first number:");
int n1=[Link]();
[Link]("Enter the second number:");
int n2=[Link]();
Addition ob=new Addition();
int n3=[Link](n1,n2);
[Link]("The addition result is:",+n3);
}
}

D:\batch-21>java Mainclass
Enter the first number:
5
Enter the second number:
6
The addition result is:11

Actual Arguments

n1,n2 are actual values, and these values are being passed to the add method.
These are called actual arguments

Formal arguments

The add method in the addition class is defined as :


int add(int a, int b)

Here a and b are called formal arguments that recieve values of n1 and n2 when
the method is called

full stack java batch-21 Page 1


Define Return type?

Return type specify whether the method will return the value or not after execution

Based on the value the return types are classified into two types

a.non_return types
[Link] type

[Link] return type

The method will not return any value after execution, such type are declared with
"void"

[Link] _type

The method will return the value after execution

Write a program to read a number and check even or not?

import [Link];
class CheckEven
{
boolean verify(int n)
{
if(n%2==0)
{
return true;
}
else
{
return false;
}
}
}

class EvenOdd
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the n value:");
int v=[Link]();
CheckEven ob=new CheckEven();
full stack java batch-21 Page 2
CheckEven ob=new CheckEven();
boolean k=[Link](v);
if(k)
{
[Link]("Even number");
}
else
{
[Link]("Odd number");
}
}
}

D:\batch-21>java EvenOdd
Enter the n value:
5
Odd number

D:\batch-21>java EvenOdd
Enter the n value:
6
Even number

full stack java batch-21 Page 3


full stack java batch-21 Page 4
19-1-2025
Sunday, January 19, 2025 8:06 PM

Increment and decrement Operators

Operator Meaning
++ Increment by 1
-- Decrement by 1

++a==>Pre increment operator


a++==>Post increment operator
--a==>Predecrement Operator
a--==>Post decrement Operator

For example
5 6
class Operators
{
public static void main(String[] args) a b
{ 6
int a=5;
int b=++a;
[Link](a);==>6
[Link](b);==>6
}
}

output:
D:\batch-21>java Operators
6
6

example: 5 5
class Operators
{ a
public static void main(String[] args)
{
int a=5;
int b=a++;
[Link](a);
full stack java batch-21 Page 1
int a=5;
int b=a++;
[Link](a);
[Link](b);
}
}

output:
D:\batch-21>java Operators
6
5

Example:

class Operators
{
public static void main(String[] args)
{
int a=5,b=3; a)6 3 9
int c=a++ +b; b)5 3 9
[Link](a); c)6 3 8
[Link](b); d)5 3 8
[Link](c);
}
int c=a++ + b
}
c=5+3
c=8
output:
D:\batch-21>java Operators
6
3
8

Assignment Operator

Operator Meaning
= Normal Assignment
a+=b a=a+b
a-=b a=a-b
a*=b a=a*b
a/=b a=a/b
a%=b a=a%b
full stack java batch-21 Page 2
a%=b a=a%b

example:

import [Link];
class Operators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter second number:");
int b=[Link]();
a+=b;
[Link]("The result="+a);
}
}

output:
Enter first number:
5
Enter second number:
6
The result=11

import [Link];
class Operators
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter first number:");
int a=[Link]();
[Link]("Enter second number:");
int b=[Link]();
a*=b;
[Link]("The result="+a);
}
}
full stack java batch-21 Page 3
output:
Enter first number:
5
Enter second number:
6
The result=30

Bitwise Operators

0 or 1 is called as bit

There are six types of bitwise operators

[Link] AND(&)
[Link] OR(|)
[Link] XOR(^)
[Link] Complement(~) tilde Symbol
[Link] Leftshift operator(<<)
[Link] Rightshift Operator(>>)

Bitwise AND(&)

If both bits are 1 then the result is 1 otherwise the result is 0

4 & 5

4-->1 0 0
5-->1 0 1
--------------
100
-----------------

100

4 & 5==>4
full stack java batch-21 Page 4
4 & 5==>4

class Operators
{
public static void main(String[] args)
{
int a=4, b=5;
int c=a&b;
[Link](c);
}
}

Output:
D:\batch-21>java Operators
4

Bitwise OR Operator(|):

Rule: If atleast one bit is 1 then the result is 1 otherwise the result is 0

4|5

4 ==>1 0 0
5==>1 0 1
-------------
1 0 1

101

4|5-->5

class Operators
{
public static void main(String[] args)
{
int a=4, b=5;
int c=a|b;
[Link](c);
full stack java batch-21 Page 5
[Link](c);
}
}

output:
5

Bitwise XOR(^)

Rule:

If both bits are different the result is 1 otherwise the result is 0

4^5

4-->1 0 0
5-->1 0 1
---------
0 0 1

0 0 1

4 ^ 5==> 0 0 1

class Operators
{ temp
public static void main(String[] args) temp
{
int a=4, b=5;
int c=a^b;
[Link](c);
}
}

output:
D:\batch-21>java Operators
1
full stack java batch-21 Page 6
1

full stack java batch-21 Page 7


20-1-2025
Monday, January 20, 2025 8:07 PM

[Link] Complement Operator(~)

This operator performs NOT [Link] operator takes single value as input

Rule:

Take the weights of 0s with -sign and add them and also add -1

Example

~12

Let us convert 12 into binary format

Binary value of 12 is 1100

12-->1100

~12->0011

0 0 1 1

Take the weights of 0s


with -sign and add them
and also add -1

Program:

class Operators
{
public static void main(String[] args)
{
int a=12;
int b=~a;
[Link](b);
}
}

output:
D:\batch-21>java Operators
full stack java batch-21 Page 1
D:\batch-21>java Operators
-13

~13

convert 13 into binary format

Binary value of 13->1101

13-->1101
~13-->0010

0 0 1 0
Take the weights of 0s
with -sign and add
them and also add -1

Program:

class Operators
{
public static void main(String[] args)
{
int a=13; 9652592663
int b=~a;
[Link](b);
}
}
output:
D:\batch-21>java Operators
-14

Bitwise Leftshift Operator(<<)

Rule: we have to multiply with 2

x=12
x<<2

x=12-->12*2=24*2=48

class Operators
{
full stack java batch-21 Page 2
{
public static void main(String[] args)
{
int a=12;
[Link](a<<2);
}
}

D:\batch-21>java Operators
48

x=12
x<<3

x=12-->12*2=24*2=48*2=96

class Operators
{
public static void main(String[] args)
{
int a=12;
[Link](a<<3);
}
}

D:\batch-21>java Operators
96

Bitwise Right Shift Operator(>>)

Right shift operator means divide with 2

x=12
x>>2

12/2=6/2=3

class operators
{
public static void main(String[] args)
{
int a=12;
[Link](a>>2);
full stack java batch-21 Page 3
[Link](a>>2);
}
}

output:
D:\batch-21>java operators
3

x=18
x>>3

18/2=9/2=4/2=2

class operators
{
public static void main(String[] args)
{
int a=18;
[Link](a>>3);
}
}

output:
D:\batch-21>java operators
2

Selection statement:

The statements which are used to execute a particular lines of a program based
on the condition are called selection statments.

full stack java batch-21 Page 4


[Link]-else 3 4
[Link]-else ladder
[Link]

Biggest of two numbers

import [Link];
class Biggest
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the first number:"); n1 n2
int n1=[Link]();
[Link]("Enter the second number:");
int n2=[Link]();
if(n1>n2)
{
[Link]("The first number is greater than second number");
}
else if(n2>n1)
{
[Link]("The second number is greater than first number");
}
else
{
[Link]("Both numbers are equal");
}
}
}

full stack java batch-21 Page 5


output:
D:\batch-21>java Biggest
Enter the first number:
5
Enter the second number:
6
The second number is greater than first number

D:\batch-21>java Biggest
Enter the first number:
6
Enter the second number:
5
The first number is greater than second number

D:\batch-21>java Biggest
Enter the first number:
6
Enter the second number:
6
Both numbers are equal

D:\batch-21>

In process of constructing java applications we can use any number of


subclasses and one main class

main class-> the class holding main() method is known as main class
subclass--> the class which are present in the application other than main class
are called as subclasses

Develop a program to perform arthmetic operations based on user choice

full stack java batch-21 Page 6


full stack java batch-21 Page 7
21-1-2025
Tuesday, January 21, 2025 8:06 PM

Control statements in java are statements that help in determining the flow of
control from one statement to another in a program

Java supports

1) selection statement(Decision making statements)


2) Iterative statements(Looping control statements)

Decision making statements are again classified into following types

a)simple if statement
b)if-else statement
c)Nested if statement
d) if...else if statement
e) switch statement

simple if statement
===============

A simple if statement in java is used to execute a block of code if only if a specified


condition evaluates to true. If the condition is false the code block is skipped. It is a
basic decision making structure for controlling program flow.

Syntax:

if(condition)
{
statement
}

If the condition is true then "statement" will be executed, otherwise it will not
execute.

Program:

class SimpleIf
{
public static void main(String[] args)
{
int number=10;
if(number>5)
{
[Link]("The number is greater than 5");
}
}
full stack java batch-21 Page 1
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java SimpleIf
The number is greater than 5

b)if-else statement

An if-else statement in java allows to execute one block of code if a condition is true
and another block of code if the condition is [Link] structure is used in handling
binary decisions.

Syntax:

if(condition)
{
statement-1
}
else
{
statement-2
}
Program:

class IfElse
{
public static void main(String[] args)
{
int number=10;
if(number%2==0)
{
[Link]("The number is even");
}
else
{
[Link]("The number is odd");
}
}
}
output:
D:\batch-21>javac [Link]

D:\batch-21>java IfElse
full stack java batch-21 Page 2
D:\batch-21>java IfElse
The number is even

c)Nested-if statement

A nested if statement is when an if block contains another if block inside it. This
allows us to check multiple conditions sequentially. where the inner condition is
evaluated only if the outer condition is true. It is useful for scenarios requiring
hierarchical decision making

program

class NestedIf
{
public static void main(String[] args)
{
int number=15;
//outer if condition
if(number>0)
{
//Inner if condition
if(number%2==0)
{
[Link]("The number is positive and even");
}
else
{
[Link]("The number is positive and odd");
}
}
else
{
[Link]("The number is not positive");
}
}
}

d)if-else if statement

An if-else if statement evaluates multiple conditions sequentially. If the first conditon


is true, if block is [Link] the next condition is checked and so on. If no
conditions are true, then else block is executed

program:

class IfElseIf
{
public static void main(String[] args)
full stack java batch-21 Page 3
public static void main(String[] args)
{
int number=0;
if(number>0)
{
[Link]("The number is positive");
}
else if(number<0)
{
[Link]("The number is negative");
}
else
{
[Link]("The number is zero");
}
}
}

In process of constructing java applications we can use any number of subclasses


and one main class

main class-> the class holding main() method is known main class
subclass--> the classes which are present in the application other then main class are
called subclasses

Develop a program to perform arithmetic operations based on user choice


full stack java batch-21 Page 4
Develop a program to perform arithmetic operations based on user choice

class Addition
{
int add(int x,int y)
{
return x+y;
}
}

class Substraction
{
int sub(int x,int y)
{
return x-y;
}
}

class Multiplication
{
int mul(int x,int y)
{
return x*y;
}
}

class Division
{
int div(int x,int y)
{
return x/y;
}
}

class ModDivision
{
int moddiv(int x,int y)
{
return x%y;
}
}

class Calculator
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
full stack java batch-21 Page 5
Scanner s=new Scanner([Link]);
[Link]("Enter the first value:");
int v1=[Link]();
[Link]("Enter the second value:");
int v2=[Link]();
[Link]("*********Choice**********");
[Link]("[Link]\n [Link]\n [Link]\n [Link]\n [Link]");
[Link]("Enter your choice:");
int choice=[Link]();
switch(choice)
{
case 1:
Addition ad=new Addition();
int r1=[Link](v1,v2);
[Link]("Sum result is:"+r1);
break;
}
}
}

full stack java batch-21 Page 6


21-1-2025
Tuesday, January 21, 2025 8:06 PM

Control statements in java are statements that help in determining the flow of
control from one statement to another in a program

Java supports

1) selection statement(Decision making statements)


2) Iterative statements(Looping control statements)

Decision making statements are again classified into following types

a)simple if statement
b)if-else statement
c)Nested if statement
d) if...else if statement
e) switch statement

simple if statement
===============

A simple if statement in java is used to execute a block of code if only if a specified


condition evaluates to true. If the condition is false the code block is skipped. It is a
basic decision making structure for controlling program flow.

Syntax:

if(condition)
{
statement
}

If the condition is true then "statement" will be executed, otherwise it will not
execute.

Program:

class SimpleIf
{
public static void main(String[] args)
{
int number=10;
if(number>5)
{
[Link]("The number is greater than 5");
}
}
full stack java batch-21 Page 1
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java SimpleIf
The number is greater than 5

b)if-else statement

An if-else statement in java allows to execute one block of code if a condition is true
and another block of code if the condition is [Link] structure is used in handling
binary decisions.

Syntax:

if(condition)
{
statement-1
}
else
{
statement-2
}
Program:

class IfElse
{
public static void main(String[] args)
{
int number=10;
if(number%2==0)
{
[Link]("The number is even");
}
else
{
[Link]("The number is odd");
}
}
}
output:
D:\batch-21>javac [Link]

D:\batch-21>java IfElse
full stack java batch-21 Page 2
D:\batch-21>java IfElse
The number is even

c)Nested-if statement

A nested if statement is when an if block contains another if block inside it. This
allows us to check multiple conditions sequentially. where the inner condition is
evaluated only if the outer condition is true. It is useful for scenarios requiring
hierarchical decision making

program

class NestedIf
{
public static void main(String[] args)
{
int number=15;
//outer if condition
if(number>0)
{
//Inner if condition
if(number%2==0)
{
[Link]("The number is positive and even");
}
else
{
[Link]("The number is positive and odd");
}
}
else
{
[Link]("The number is not positive");
}
}
}

d)if-else if statement

An if-else if statement evaluates multiple conditions sequentially. If the first conditon


is true, if block is [Link] the next condition is checked and so on. If no
conditions are true, then else block is executed

program:

class IfElseIf
{
public static void main(String[] args)
full stack java batch-21 Page 3
public static void main(String[] args)
{
int number=0;
if(number>0)
{
[Link]("The number is positive");
}
else if(number<0)
{
[Link]("The number is negative");
}
else
{
[Link]("The number is zero");
}
}
}

In process of constructing java applications we can use any number of subclasses


and one main class

main class-> the class holding main() method is known main class
subclass--> the classes which are present in the application other then main class are
called subclasses

Develop a program to perform arithmetic operations based on user choice


full stack java batch-21 Page 4
Develop a program to perform arithmetic operations based on user choice

class Addition
{
int add(int x,int y)
{
return x+y;
}
}

class Substraction
{
int sub(int x,int y)
{
return x-y;
}
}

class Multiplication
{
int mul(int x,int y)
{
return x*y;
}
}

class Division
{
int div(int x,int y)
{
return x/y;
}
}

class ModDivision
{
int moddiv(int x,int y)
{
return x%y;
}
}

class Calculator
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
full stack java batch-21 Page 5
Scanner s=new Scanner([Link]);
[Link]("Enter the first value:");
int v1=[Link]();
[Link]("Enter the second value:");
int v2=[Link]();
[Link]("*********Choice**********");
[Link]("[Link]\n [Link]\n [Link]\n [Link]\n [Link]");
[Link]("Enter your choice:");
int choice=[Link]();
switch(choice)
{
case 1:
Addition ad=new Addition();
int r1=[Link](v1,v2);
[Link]("Sum result is:"+r1);
break; 9652592663
case 2:
Substraction sb=new Substraction();
int r2=[Link](v1,v2);
[Link]("Sub result is:"+r2);
break;
case 3:
Multiplication ml=new Multiplication();
int r3=[Link](v1,v2);
[Link]("Multiplication result is:"+r3);
break;

}
}
}

Switch statement

A switch statement in java is used to execute one block of code from multiple options
based on the value of a [Link] case represents a specific value to match and
the corresponding block executes if the match is found. The break statement exits
the switch block.

full stack java batch-21 Page 6


23-1-2025
Thursday, January 23, 2025 8:10 PM

Looping statements in java

Looping statements are the statement which executes several number of time as long
as a specified condition is satisified

In java programming we have four types of looping control statements

a)while loop
b)do while loop
c)for loop
d)Enhanced for loop( from java 1.5 version) /for each loop

a)while loop

In java, a while loop is used to repeatedly execute a block of code as long as the
specified condition is [Link] condition is evaluated before each iteration and if it
evaluates to false, the loop terminates.

Syntax:

while(condition)
{
//code to be executed
}

Write a program to read an integer and display reverse of a number?

input:543
output:345

Logic:
======

r=0 input n=23


while(n!=0)
{
k=n%10; step:1
r=(r*10)+k; ====
n=n/10; k=n%10
=23%10
full stack java batch-21 Page 1
k=n%10;
r=(r*10)+k; ====
n=n/10; k=n%10
} =23%10
=3
r=(r*10)+k
=(0*10)+3
=0+3
=3
n=n/10
=23/10
=2
step:2
=====
n=2
k=n%10
=2%10
=2
r=(r*10)+k
=3*10+2
=30+2
=32
n=n/10
=2/10
=0

Program:
import [Link];
class ReverseNumber
{
int k;
int r=0;
int rev(int n)
{
while(n!=0)
{
k=n%10;
r=(r*10)+k;
n=n/10;
}
return r;
}
}
class Reversemain
full stack java batch-21 Page 2
class Reversemain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter n value:");
int v=[Link]();
ReverseNumber ob=new ReverseNumber();
int r= [Link](v);
[Link]("Reverse of number is:"+r);
}
}

output:
D:\batch-21>java Reversemain
Enter n value:
23
Reverse of number is:32

Write a program to check whether the given number is armstrong number or


not?

sum of cubes of digits==given number

153=

370=

Logic:

sum=0
full stack java batch-21 Page 3
Logic:

sum=0
while(n!=0)
n%10
{
n/10
d=n%10
sum=sum+d*d*d
n=n/10
} n=153

full stack java batch-21 Page 4


24-1-2025
Friday, January 24, 2025 8:06 PM

Logic:

sum=0
while(n!=0)
{
d=n%10
sum=sum+d*d*d
n=n/10
}

n=153
step:1
n=153
d=n%10
=153%10
=3
sum=sum+d*d*d
=0+3*3*3
=0+27
=27
n=n/10
=153/10
=15

step:2

d=n%10
=15%10
=5
sum=sum+d*d*d
=27+5*5*5
=27+125
=152
n=n/10
=15/10
=1

full stack java batch-21 Page 1


step 3:

d=n%10
=1%10
=1
sum=sum+d*d*d
=152+1
=153
n=n/10
=1/10
n=0

Program:

import [Link];
class Armstrong
{
int sum=0;
int arm(int n)
{
while(n!=0)
{
int d=n%10;
sum=sum+d*d*d;
n=n/10;
}
return sum;
}
}
class Armstrongmain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter a number:");
int v=[Link]();
Armstrong ob=new Armstrong();
int z=[Link](v);
full stack java batch-21 Page 2
int z=[Link](v);
if(v==z)
{
[Link]("The given number is a armstrong number");
}
else
{
[Link]("The given number is not a armstrong number");
}

}
}

output:
D:\batch-21>java Armstrongmain
Enter a number:
153
The given number is a armstrong number

D:\batch-21>java Armstrongmain
Enter a number:
222
The given number is not a armstrong number

Construct a java application with the following layout

[Link] Employee Name


[Link] Employee Designation
The designation must be in Developer,Tester,DBM
[Link] the designation is verified successfully, then read employee Id, and also read
Employee Basic Salary
[Link] salary must be 12000/- else print message Invalid salary
[Link] Basic salary is validated successfully then calculate total salary

program:
import [Link];
class Designation
{
boolean k=false;
full stack java batch-21 Page 3
boolean k=false;
boolean verify(String desg)
{
switch(desg)
{
case "Developer":k=true;
break;
case "Tester":k=true;
break;
case "DBM":k=true;
break;
default:k=false;
}
return k;
}
}
class Totalsalary
{
int calculate(int bsal)
{
return bsal+(12*bsal);
}
}

class Empmain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter emp name:");
String ename=[Link]();
[Link]("Enter the emp designation:");
String edesg=[Link]();
Designation b=new Designation();
boolean k=[Link](edesg);
if(k)
{
[Link]("Enter Emp id:");
int eid=[Link]();
[Link]("Enter bsal:");
full stack java batch-21 Page 4
[Link]("Enter bsal:");
int bsal=[Link]();
if(bsal>=12000)
{
Totalsalary ob=new Totalsalary();
int totsal=[Link](bsal);
[Link]("===========Employee Details========");
[Link]("Employee Name:"+ename);
[Link]("Employee Desg:"+edesg);
[Link]("Employee id:"+eid);
[Link]("Employee bsal:"+bsal);
[Link]("Employee Salary:"+totsal);
}

else
{
[Link]("Invalid Salary:");
}
}
else
{
[Link]("Invalid Designation");
}
}
}

full stack java batch-21 Page 5


25-1-2025
25 January 2025 20:20

Develop a java program by using the following layout

[Link] pinno
==>The pinno must be 4 digits else "Invalid pinno".
[Link] pinno is validated successfully, then verify pinno
The pinno must be 1111 or 2222 or 3333 else "Incorrect pinno"
[Link] pinno is validated successfully, then read amount to withdraw
==>The amount must be greater than zero and multiples of 100,
else Invalid amount

[Link] the amount is validated successfully, then amount must be less than
2000(because the account of the customer contains only 2000)

Program:
import [Link];
class Countdigits
{
int count=0;
int getcount(int n)
{
while(n>0)
{
count++
n=n/10;
}
return count;
}
class Checkpinno
{

}
full stack java batch-21 Page 1
class Withdraw
{

class Bankmain
{

public static void main(String[] args)


{
Scanner s=new Scanner([Link]);
[Link]("Enter pinno:");
int pinno=[Link]();
Countdigits cd=new Countdigits()
int c=[Link](pinno);
if(c==4)
{

}
else
{
[Link]("Invalid Pinno");
}
}

full stack java batch-21 Page 2


int count=0;
getcount(int n)
{
while(n>0)
{
count++;
n=n/10;
}

10)234(23
230
10)2345(234
--------
2340
4
----------
5
step:1
n=2345
n>0(True) 10)23(2
count=1 20
n=2345/10 ----------
n=234 3

step:2
n=234
n>0(True)
count=2 10)2(0
n=234/10 0
full stack java batch-21 Page 3
n>0(True)
count=2 10)2(0
n=234/10 0
n=23 ------------
2
step:3
n=23
n>0(True)
count=3
n=n/10
=23/10
n=2

step:4
n=2
n>0(True)
count=4
n=2/10
n=0

full stack java batch-21 Page 4


27-1-2025
Monday, January 27, 2025 8:08 PM

Program:

Develop a java program by using the following layout

[Link] pinno
==>The pinno must be 4 digits else "Invalid pinno".
[Link] pinno is validated successfully, then verify pinno
The pinno must be 1111 or 2222 or 3333 else "Incorrect pinno"
[Link] pinno is validated successfully, then read amount to withdraw
==>The amount must be greater than zero and multiples of 100,
else Invalid amount

[Link] the amount is validated successfully, then amount must be less than 2000(because the
account of the customer contains only 2000)
import [Link];
class Countdigits
{
int count=0;
int getcount(int n)
{
while(n>0)
{
count++;
n=n/10;
}
return count;
}
}
class Checkpinno
{
boolean k=false;
boolean verify(int pinno)
{
switch(pinno)
{
case 1111:k=true;
break;
case 2222:k=true;
break;
case 3333:k=true;
break;
default:k=false;
full stack java batch-21 Page 1
default:k=false;
}
return k;
}
}

class Withdraw
{
void Wdraw(int amt)
{
[Link]("Amount Withdrawn:"+amt);
[Link]("Balance Amount:"+(2000-amt));
[Link]("Transaction completed successfully");
}
}

class Bankmainclass
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter pinno:");
int pinno=[Link]();
Countdigits cd=new Countdigits();
int c=[Link](pinno);
if(c==4)
{
Checkpinno cpn=new Checkpinno();
boolean k=[Link](pinno);
if(k)
{
[Link]("Enter the amount to withdraw");
int amt=[Link]();
if(amt>=0 && amt%100==0)
{
if(amt<=2000)
{
Withdraw wd=new Withdraw();
[Link](amt);
}
else
{
[Link]("Insufficient funds");
}
full stack java batch-21 Page 2
}
}
else
{
[Link]("Invalid amount");
}
}
else
{
[Link]("Incorrect Pinno:");
}

}
else
{
[Link]("Invalid pinno");
}
}
}

Java for loop is a control statement that allows the code to be executed repeatedly
based on given condition.
syntax:

for(intialization expr;text expr;update exp}


{
body of the loop;
}

example:

class SumofNumbers
{
public static void main(String[] args)
{
int sum=0;
for(int i=1;i<=10;i++)
{
sum=sum+i;
}
[Link]("The sum of first 10 natural numbers is:"+sum);
} sum=sum+i
} i=1
full stack java batch-21 Page 3
[Link]("The sum of first 10 natural numbers is:"+sum);
} sum=sum+i
} i=1
1<=10(True)
output: sum=sum+i
D:\batch-21>java SumofNumbers =0+1
The sum of first 10 natural numbers is:55 =1

i=2
2<=10(True)
sum=sum+i
=1+2
=3

i=3
3<=10(True)
sum=sum+i
3+3
6

full stack java batch-21 Page 4


28-1-2025
Tuesday, January 28, 2025 8:07 PM

A for loop is a control flow statement used to repeat a block of code ,a certain number of
times until a condition is true

syntax:

for(initialization;condition;increment/decrement)
{
code to be executed
}

components

[Link]:This step is executed only once at the start of the loop, It typically
initializes a variable

[Link]:

This condition is evaluated before each iteration. If the condition is true the loop
continues, if the condition is false then the loop

[Link]/decrement

This step is executed for each iteration. It usually modifies the variable, typically increase
or decrease the value inside the variable.

Write a program to print multiplication table

import [Link];
class MultiplicationTable
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter a number to print its multiplication Table:");
int number=[Link]();
for (int i=1;i<=10;i++)
{
[Link](number+"*"+i+"="+(number*i));
full stack java batch-21 Page 1
[Link](number+"*"+i+"="+(number*i));
}

}
}
output:
Enter a number to print its multiplication Table:
5
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
5*6=30
5*7=35
5*8=40
5*9=45
5*10=50

D:\batch-21>java MultiplicationTable
Enter a number to print its multiplication Table:
7
7*1=7
7*2=14
7*3=21
7*4=28
7*5=35
7*6=42
7*7=49
7*8=56
7*9=63
7*10=70

Enhanced for loop:

This enhanced for loop is used to process the data inside an array
full stack java batch-21 Page 2
This enhanced for loop is used to process the data inside an array

array=>group of data with homogenous elements

arr[]={12,23,44,56,78}

syntax:

for(data_type variable:array_name)
{
//code to be executed
}

class Enhancedforloop
{
public static void main(String[] args)
{
int arr[]={12,23,44,56,78};
for(int i:arr)
{
[Link](i);
}
}
}

output:
D:\batch-21>java Enhancedforloop
12
23
44
56
78

do-while loop in java

The do while loop is similar to while loop, but the key difference is that
the code inside the loop is guaranteed to execute atleast once,even if the
condition is false. This is because the condition is checked after the loop
full stack java batch-21 Page 3
condition is false. This is because the condition is checked after the loop
body is executed

Syntax

do{
//code to be executed
}while(condition);

class DoWhileExample
{ 9652592663
public static void main(String[] args)
{
int i=1;
do{
[Link](i);
i++;
}while(i<=5);
}
}
output:
D:\batch-21>java DoWhileExample
1
2
3
4
5

class DoWhileExample
{
public static void main(String[] args)
{
int i=10;
do{
[Link](i);
i++;
full stack java batch-21 Page 4
i++;
}while(i<=5);
}
}
output:
D:\batch-21>java DoWhileExample
10
Factorial of a number using do while loop

import [Link];
class Factorial 4!=4*3*2*1
{ =24
public static void main(String[] args) 5!
{ 5*4*3*2*1
Scanner s=new Scanner([Link]); 120
[Link]("Enter a number:");
int num=[Link]();
int factorial=1;
int i=1;
do{
factorial=factorial*i;
i++;
}while(i<=num);
[Link]("Factorial of"+num+"is:"+ factorial);
}
}
output:
D:\batch-21>javac [Link]

D:\batch-21>java Factorial
Enter a number:
5
Factorial of5is:120

D:\batch-21>java Factorial
full stack java batch-21 Page 5
D:\batch-21>java Factorial
Enter a number:
4
Factorial of4is:24

D:\batch-21>

full stack java batch-21 Page 6


29-1-2025
Wednesday, January 29, 2025 8:05 PM

Factorial of a number using do while loop

import [Link];
class Factorial
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]); Flow of execution
[Link]("Enter a number:");
int num=[Link](); step 1:
int factorial=1; num=4
int i=1; factorial=factorial*i
do{ factorial=1*1
factorial=factorial*i; factorial=1
i++==>2
i++;
while(i<=num)
}while(i<=num); 2<=4==>True
[Link]("Factorial of"+num+"is:"+ factorial);
} step 2:
} factorial=factorial*i
=1*2
output: factorial=2
D:\batch-21>javac [Link] i++==>3
while(i<=num)
3<=4(True)
D:\batch-21>java Factorial
Enter a number: step:
4! factorial=factorial*i
5 4*3*2*1 2*3
Factorial of5is:120 24 =6
factorial=6
D:\batch-21>java Factorial i++==>4
while(i<=num)
Enter a number: 4<=4
4 True
Factorial of4is:24
step:4
factorial=factorial*i
D:\batch-21 6*4=24
factorial=24
i++==>5
full stack java batch-21 Page 1
i++==>5
while(i<=num)
5<=4==>False

TCS java developer-->2024

Enter the day:MON


It is a weekday
The result is :true

Enter the day:FRI


It is a weekday
The result is:true

Enter the day:SAT


It is a weekend
The result is:false

Enter the day:SUN


It is a weekend
The result is :false

Yield Keyword

Program:

import [Link];
class CheckDay
{
boolean check(String day)
{
switch(day){
case "MON":
case "TUE":
case "WED":
case "THU":
case "FRI":
[Link]("It is a weekday");
return true;
case "SAT":
case "SUN":
full stack java batch-21 Page 2
case "SUN":
[Link]("It is a weekend");
return false;
default:
[Link]("Invalid day");
return false;
}

}
}

class SwitchReturnExample
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the day:");
String day=[Link]();
CheckDay ob=new CheckDay();
boolean result=[Link](day);
[Link]("The result is:"+result);
}
}

Yield Keyword

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

class CheckDay{

boolean check(String day){


return switch(day){
case "MON","TUE","WED","THU","FRI"->{
[Link]("It is a weekday");
yield true;
}
case "SAT","SUN"->{
[Link]("It is a weekend");
yield false;
}
default->{
[Link]("Invalid day");
yield false;
}
full stack java batch-21 Page 3
}
};
}
}

class SwitchReturnExample{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the day:");
String day=[Link]();
CheckDay ob=new CheckDay();
boolean result=[Link](day);
[Link]("The result is:"+result);
}
}

output:
D:\batch-21>java SwitchReturnExample
Enter the day:
SUN
It is a weekend
The result is:false

D:\batch-21>java SwitchReturnExample
Enter the day:
SAT
It is a weekend
The result is:false

In java, yield is a keyword, introduced in java 12 version as part of switch expression


It is used to return a value from a switch expression. Unlike the break statement
in traditional switch statements, yield explicitly returns a value from a case block.

key point about yield

[Link] in switch expression: yield is only valid inside switch expression.

[Link] a value: Unlike break, which just exists the switch, yield returns a value from a
case block.

full stack java batch-21 Page 4


Blocks
===
class Blocks
{
static int k=10;
public static void main(String[] args)
{
k++; //k=k+1
[Link]("=====Main()=====");
[Link]("The value of k:"+k);
}
static
{
[Link]("====Static Block=====");
[Link]("The value of k:"+k);
}
}

D:\batch-21>java Blocks
====Static Block=====
The value of k:10
=====Main()=====
The value of k:11

full stack java batch-21 Page 5


30-1-2024
Thursday, January 30, 2025 8:11 PM

Program:

class Blocks
{
static int k=10;
public static void main(String[] args)
{
k++; //k=k+1;
[Link]("=====Main()======");
[Link]("The value of k:"+k);
}
static
{
[Link]("====Static Block====");
[Link]("The value of k:"+k);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Blocks
====Static Block====
The value of k:10
=====Main()======
The value of k:11

The set of statements which are declared within curly braces and executed
automatically is known block

Blocks in java are categorized into two types

[Link] blocks
[Link] static blocks(Instance Blocks)

Syntax:

static
{
//code
}

Execution behaviour of static block


full stack java batch-21 Page 1
Execution behaviour of static block

[Link] blocks executes with highest priority when the class is used for the first
time

[Link] static methods the static blocks will access only static variables and
cannot access instance variables.

class Blocks
{
int k=10;
public static void main(String[] args)
{
k++; //k=k+1;
[Link]("=====Main()======");
[Link]("The value of k:"+k);
}
static
{
[Link]("====Static Block====");
[Link]("The value of k:"+k);
}
}

D:\batch-21>javac [Link]
[Link]: error: non-static variable k cannot be referenced from a static context
k++; //k=k+1;
^
[Link]: error: non-static variable k cannot be referenced from a static context
[Link]("The value of k:"+k);
^
[Link]: error: non-static variable k cannot be referenced from a static
context
[Link]("The value of k:"+k);
^
3 errors

full stack java batch-21 Page 2


Static block with two classes

class Staticblock
{
static int k=10;
static
{
[Link]("======Static Block====");
[Link]("The value of k:"+k);
}
}

class Staticmain
{
public static void main(String[] args)
{
Staticblock.k=300;
[Link]("=========main()======");
[Link]("The value of k:"+Staticblock.k);
}

D:\batch-21>java Staticmain
======Static Block====
full stack java batch-21 Page 3
======Static Block====
The value of k:10
=========main()======
The value of k:300

[Link]-static Blocks(Instance Block):

The blocks which are declared without static keyword are known as non static
blocks or Instance Blocks

syntax:

//set of instructions
}

Execution Behaviour of Instance Blocks

[Link] blocks are executed automatically while object creation


[Link] blocks can access both static variables and non static variables

Example:

class Instanceblock
{
int a=10;
static int b=20;

{
a++;
b++;
[Link]("====Instance Block====");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}

void dis()
{
a++;
b++;
[Link]("Instance Method dis()=====");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
full stack java batch-21 Page 4
[Link]("The value of b:"+b);
}
}

class Instancemain
{
public static void main(String[] args)
{
Instanceblock b1=new Instanceblock();
[Link]();
Instanceblock b2=new Instanceblock();
[Link]();

}
}

Output:
D:\batch-21>java Instancemain
====Instance Block====
The value of a:11
The value of b:21
Instance Method dis()=====
The value of a:12
The value of b:22
====Instance Block====
The value of a:11
The value of b:23
Instance Method dis()=====
The value of a:12
The value of b:24

full stack java batch-21 Page 5


30-1-2024
Thursday, January 30, 2025 8:11 PM

Program:

class Blocks
{
static int k=10;
public static void main(String[] args)
{
k++; //k=k+1;
[Link]("=====Main()======");
[Link]("The value of k:"+k);
}
static
{
[Link]("====Static Block====");
[Link]("The value of k:"+k);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Blocks
====Static Block====
The value of k:10
=====Main()======
The value of k:11

The set of statements which are declared within curly braces and executed
automatically is known block

Blocks in java are categorized into two types

[Link] blocks
[Link] static blocks(Instance Blocks)

Syntax:

static
{
//code
}

Execution behaviour of static block

[Link] blocks executes with highest priority when the class is used for the first
time

[Link] static methods the static blocks will access only static variables and
cannot access instance variables.

class Blocks
{
int k=10;
public static void main(String[] args)

full stack java batch-21 Page 1


public static void main(String[] args)
{
k++; //k=k+1;
[Link]("=====Main()======");
[Link]("The value of k:"+k);
}
static
{
[Link]("====Static Block====");
[Link]("The value of k:"+k);
}
}

D:\batch-21>javac [Link]
[Link]: error: non-static variable k cannot be referenced from a static context
k++; //k=k+1;
^
[Link]: error: non-static variable k cannot be referenced from a static context
[Link]("The value of k:"+k);
^
[Link]: error: non-static variable k cannot be referenced from a static
context
[Link]("The value of k:"+k);
^
3 errors

Static block with two classes

class Staticblock
{
static int k=10;
static
{
[Link]("======Static Block====");
[Link]("The value of k:"+k);
}
}
full stack java batch-21 Page 2
}

class Staticmain
{
public static void main(String[] args)
{
Staticblock.k=300;
[Link]("=========main()======");
[Link]("The value of k:"+Staticblock.k);
}

D:\batch-21>java Staticmain
======Static Block====
The value of k:10
=========main()======
The value of k:300

[Link]-static Blocks(Instance Block):

The blocks which are declared without static keyword are known as non static
blocks or Instance Blocks

syntax:

//set of instructions
}

Execution Behaviour of Instance Blocks

[Link] blocks are executed automatically while object creation


[Link] blocks can access both static variables and non static variables

Example:

class Instanceblock
{
int a=10;
static int b=20;

{
a++;
b++;
[Link]("====Instance Block====");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}

void dis()
{
a++;
b++;
[Link]("Instance Method dis()=====");
full stack java batch-21 Page 3
[Link]("Instance Method dis()=====");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
}

class Instancemain
{
public static void main(String[] args)
{
Instanceblock b1=new Instanceblock();
[Link]();
Instanceblock b2=new Instanceblock();
[Link]();

}
}

Output:
D:\batch-21>java Instancemain
====Instance Block====
The value of a:11
The value of b:21
Instance Method dis()=====
The value of a:12
The value of b:22
====Instance Block====
The value of a:11
The value of b:23
Instance Method dis()=====
The value of a:12
The value of b:24

full stack java batch-21 Page 4


Full stack Java with Internship total course Fees is 3000
gpay/phone pay
8074869471
[Link] recorded access
[Link], pw
Constructors

Constructor is a special method having same name as the class name and
execute while object creation

full stack java batch-21 Page 5


1-2-2025
Saturday, February 1, 2025 8:05 PM

Constructor:

Constructor is a method having same name as the class name and execute while
object creation process

syntax:

class_name(para_list)
{
//set of instructions
}

program:

class Constructor
{
int a=100;
Constructor()
{
[Link]("=====Constructor=====");
[Link]("The value of a:"+a);
}
void dis(){
[Link]("=====dis()=====");
[Link]("The value of a:"+a);
}
}

class Constructormain
{
public static void main(String[] args)
{
Constructor ob=new Constructor();
[Link]();
}
}

full stack java batch-21 Page 1


output:
D:\batch-21>javac [Link]

D:\batch-21>java Constructormain
=====Constructor=====
The value of a:100
=====dis()=====
The value of a:100

What is the difference between constructor and instance block?

constructor and instance block are executed while object creation


[Link] block has the highest priority in execution when compared to the
constructor

class Constructor
{
int a=100;
Constructor()
{
[Link]("=====Constructor=====");
[Link]("The value of a:"+a);
}
{
[Link]("=====Instance Block=====");
[Link]("The value of a:"+a);
}
}

class Constructormain
{
public static void main(String[] args)
{
Constructor ob=new Constructor();
Constructor ob1=new Constructor();
}
}

full stack java batch-21 Page 2


D:\batch-21>java Constructormain
=====Instance Block=====
The value of a:100
=====Constructor=====
The value of a:100
=====Instance Block=====
The value of a:100
=====Constructor=====
The value of a:100

What is the difference between static block and constructor?

Static block executes only once with highest priority when the class is used for the
first time and constructor is executed for each object while object creation
process.

class Constructor
{
int a=100;
Constructor()
{
[Link]("====Constructor====");
[Link]("The value of a:"+a);
}
static
{
[Link]("====Static block====");
[Link]("The value of a:"+a);
}
public static void main(String[] args)
{
Constructor ob=new Constructor();
}
}

output:
D:\batch-21>javac [Link]
[Link]: error: non-static variable a cannot be referenced from a static
full stack java batch-21 Page 3
[Link]: error: non-static variable a cannot be referenced from a static
context
[Link]("The value of a:"+a);
^
1 error

class Constructor
{
static int a=100;
Constructor()
{
[Link]("====Constructor====");
[Link]("The value of a:"+a);
}
static
{
[Link]("====Static block====");
[Link]("The value of a:"+a);
}
public static void main(String[] args)
{
Constructor ob=new Constructor();
}
}

D:\batch-21>java Constructor
====Static block====
The value of a:100
====Constructor====
The value of a:100

class Constructor
{
static int a=100;
Constructor()
{
full stack java batch-21 Page 4
{
[Link]("====Constructor====");
[Link]("The value of a:"+a);
}
static
{
[Link]("====Static block====");
[Link]("The value of a:"+a);
}
public static void main(String[] args)
{
Constructor ob=new Constructor();
Constructor ob1=new Constructor();
}
}

D:\batch-21>java Constructor
====Static block====
The value of a:100
====Constructor====
The value of a:100
====Constructor====
The value of a:100

Can we use return type for the constructor?

when the constructor is declared with return type, then it is considered as a


normal method.

class Constructor
{
static int a=100;
void Constructor()
{
[Link]("====Constructor=====");
[Link]("The value of a:"+a);
}
public static void main(String[] args)
{
Constructor ob=new Constructor();
[Link]();
full stack java batch-21 Page 5
[Link]();
}
}

output:
D:\batch-21>java Constructor
====Constructor=====
The value of a:100

constructor with parameters

The constructor which are declared with parameters are known as parameterized
constructor or constructor with parameters

import [Link];
class Userlogin
{
String username,password,mailid;
long phno;
Userlogin(String a,String b,String c,long d)
{
username=a;
password=b;
mailid=c;
phno=d;
}
void getuserlogin()
{
[Link]("=======Userdetails========");
[Link]("Username:"+username);
[Link]("Password:"+password);
[Link]("mailid:"+mailid);
[Link]("Phoneno:"+phno);
}
}

class Usermain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
full stack java batch-21 Page 6
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
String uname=[Link]();
[Link]("Enter the password:");
String pword=[Link]();
[Link]("Enter the mailid:");
String mid=[Link]();
[Link]("Enter the PhoneNo:");
long pno=[Link]();
Userlogin ob=new Userlogin(uname,pword,mid,pno);
[Link]();
}
}

output:

D:\batch-21>java Usermain
Enter the username:
rajesh
Enter the password:
rajesh123
Enter the mailid:
rajesh@[Link]
Enter the PhoneNo:
9898981234
=======Userdetails========
Username:rajesh
Password:rajesh123
mailid:rajesh@[Link]
Phoneno:9898981234

Full stack Java with Internship total course Fees is


gpay/phone pay
8074869471

tomorrow there is no class


next class is on monday

full stack java batch-21 Page 7


3-2-2025
Monday, February 3, 2025 8:35 PM

Three friends, named Bunny, Vinny, Sunny are playing a game. The rules of a game
are, A random number is selected from a series of numbers. The person Who got a
number containing Zeros in it, has to quit the game. But provided that a person who
got a number containing only zero will not quit the game, and continue in the game.
Develop a code in which a number is given and display the output whether to quit
the game or continue in the game.

import [Link].*;
import [Link].*;

public class Solution {

public static void main(String[] args) {


Scanner s=new Scanner([Link]);
int num=[Link]();
String s1=[Link](num);
if([Link]("0") && ![Link]("0")){
[Link]("Quit the game");
}else{
[Link]("Dont Quit the game");
}
}
}

import [Link];
class Userlogin
{
String username,password,mailid;
long phno;
Userlogin(String username,String password,String mailid,long phno)
{
username=username;
full stack java batch-21 Page 1
username=username;
password=password;
mailid=mailid;
phno=phno;
}
void getuserlogin()
{
[Link]("=======Userdetails========");
[Link]("Username:"+username);
[Link]("Password:"+password);
[Link]("mailid:"+mailid);
[Link]("Phoneno:"+phno);
}
}

class Usermain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
String uname=[Link]();
[Link]("Enter the password:");
String pword=[Link]();
[Link]("Enter the mailid:");
String mid=[Link]();
[Link]("Enter the PhoneNo:");
long pno=[Link]();
Userlogin ob=new Userlogin(uname,pword,mid,pno);
[Link]();
}
}

output:
D:\batch-21>java Usermain
Enter the username:
suresh
Enter the password:
suresh
full stack java batch-21 Page 2
suresh
Enter the mailid:
suresh@[Link]
Enter the PhoneNo:
9898981234
=======Userdetails========
Username:null
Password:null
mailid:null
Phoneno:0

full stack java batch-21 Page 3


4-2-2025
Tuesday, February 4, 2025 8:20 PM

Define this keyword?

"this" keyword is a predefined keyword , if we are using instance variables inside


any method,,"this" keyword is used to load the data from local variables

import [Link];
class Userlogin
{
String username,password,mailid;
long phno;
Userlogin(String username,String password,String mailid,long phno)
{
[Link]=username;
[Link]=password;
[Link]=mailid;
[Link]=phno;
}
void getuserlogin()
{
[Link]("=======Userdetails========");
[Link]("Username:"+username);
[Link]("Password:"+password);
[Link]("mailid:"+mailid);
[Link]("Phoneno:"+phno);
}
}

class Usermain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
String uname=[Link]();
[Link]("Enter the password:");
String pword=[Link]();
[Link]("Enter the mailid:");
String mid=[Link]();
[Link]("Enter the PhoneNo:");
long pno=[Link]();
Userlogin ob=new Userlogin(uname,pword,mid,pno);
[Link]();
}
}

D:\>javac [Link]

D:\>java Usermain
Enter the username:
rajesh
Enter the password:
rajesh
Enter the mailid:
rajesh@[Link]

full stack java batch-21 Page 1


rajesh@[Link]
Enter the PhoneNo:
9898981234
=======Userdetails========
Username:rajesh
Password:rajesh
mailid:rajesh@[Link]
Phoneno:9898981234

class with multiple constructor

class in java can be declared with any number of constructors. we can call these
constructors during object creation process.

class Test
{
Test(int a)
{
[Link]("======Test(a)==========");
[Link]("The value of a:"+a);
}
Test(int x, int y)
{
[Link]("=====Test(x,y)============");
[Link]("The value of x:"+x);
[Link]("The value of y:"+y);
}
}
class Testmain
{
public static void main(String[] args)
{
Test ob1=new Test(12);
}
}

output:
D:\batch-21>java Testmain
======Test(a)==========
The value of a:12

class Test
{
Test(int a)
{
[Link]("======Test(a)==========");
[Link]("The value of a:"+a);
}
Test(int x, int y)
{
[Link]("=====Test(x,y)============");
[Link]("The value of x:"+x);
[Link]("The value of y:"+y);
}
}
class Testmain
{
public static void main(String[] args)
{
Test ob1=new Test(12);
Test ob2=new Test(14,15);
}
}
output:
D:\batch-21>java Testmain
======Test(a)==========
The value of a:12
=====Test(x,y)============
The value of x:14
The value of y:15

can we call multiple constructors by creating a single object for a class?

yes, we can execute the multiple constructors from another constructor by creating
a single object. This process is called "constructor chaining process"

what is constructor chaining process?

The process of calling one constructor from another constructor is known as


constructor chaining process. we can use predefined "this()" to perform
full stack java batch-21 Page 2
constructor chaining process. we can use predefined "this()" to perform
constructor chaining process

class Test
{
Test(int a)
{
this(14,15);
[Link]("======Test(a)=======");
[Link]("The value of a:"+a);
}
Test(int x,int y)
{
[Link]("=====Test(x,y)=====");
[Link]("The value of x:"+x);
[Link]("The value of y:"+y);
}
}

class Testmain
{
public static void main(String[] args)
{
Test ob1=new Test(12);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Testmain
=====Test(x,y)=====
The value of x:14
The value of y:15
======Test(a)=======
The value of a:12

What is the difference between "this" keyword and this()?

"this" keyword is a predefined keyword, if we want to laod the data from local
variables then we will use this keyword

"this()" is predefined method if we want to access the constructor from another


constructor then we will use this().

loading data to instance variables

1. using object reference variable.

import [Link];
class Bookdetails
{
String bcode,bname,bauthor;
void getbookdetails()
{
[Link]("======BookDetails=====");
[Link]("Bookcode:"+bcode);
[Link]("Bookname:"+bname);
[Link]("Bookauthor:"+bauthor);
}
}
class Bookmain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
Bookdetails ob=new Bookdetails();
[Link]("Enter the bookcode:");
[Link]=[Link]();
[Link]("Enter the bookname:");
[Link]=[Link]();
[Link]("Enter the bookauthor:");
[Link]=[Link]();
[Link]();

}
}

output:
full stack java batch-21 Page 3
output:

D:\batch-21>java Bookmain
Enter the bookcode:
A-123
Enter the bookname:
C-Language
Enter the bookauthor:
B-Swamy
======BookDetails=====
Bookcode:A-123
Bookname:C-Language
Bookauthor:B-Swamy

full stack java batch-21 Page 4


5-2-2025
Wednesday, February 5, 2025 8:08 PM

loading data into instance variables

[Link] using setter and getter methods

import [Link];
class Product
{
String code,name;
float price;
void setcode(String code)
{
[Link]=code;
}
void setname(String name)
{
[Link]=name;
}
void setprice(float price)
{
[Link]=price;
}
String getcode()
{
return code;
}
String getname()
{
return name;
}
float getprice()
{
return price;
}
}

class Productmain
{
public static void main(String[] args)
{
full stack java batch-21 Page 1
{
Product ob=new Product();
Scanner s=new Scanner([Link]);
[Link]("Enter the product code:");
[Link]([Link]());
[Link]("Enter the product name:");
[Link]([Link]());
[Link]("Enter the product price:");
[Link]([Link]());
[Link]("======Displaying by using Getter methods====");
[Link]("Product code:"+[Link]());
[Link]("Product name:"+[Link]());
[Link]("Product price:"+[Link]());
}
}

D:\batch-21>java Productmain
Enter the product code:
A201
Enter the product name:
Mouse
Enter the product price:
500
======Displaying by using Getter methods====
Product code:A201
Product name:Mouse
Product price:500.0

Define setter methods?

The methods which are used to set the data to instance variables are known as setter
methods

Define getter methods?

The methods which are used to get the data from the instance variables are known as
getter methods.

Every instance variable in a class will have setter methods and getter methods

full stack java batch-21 Page 2


notepad
edit plus Editors
command
jdk
IDE-->Integrated development enviroment

In IDE's we can develop, execute and we can use libraries at a same time

netbeans
Eclipse

Eclipse
website: [Link]/downloads

full stack java batch-21 Page 3


6-2-2025
Thursday, February 6, 2025 8:07 PM

Write a program to calculate employee salary

import [Link];
bsal=12000
class Employeesalary
total salary=Hr+pf
{
3*bsal=3*12000=36000
int totalsalary(int bsal)
{
return(3*bsal)
}
}

class Employeemain
{
public static void main(String[] args)
{
Scanner s=new Scanner([Link]);
[Link]("Enter bsal:");
int bsal=[Link]();
Employesalary ob=new Employeesalary();
int totalsal=[Link](bsal)
[Link]("Totalsalary:"+totalsal);
}
}

output:
D:\batch-21>javac [Link]

D:\batch-21>java Employeemain
Enter bsal:
12000
Totalsalary:36000

full stack java batch-21 Page 1


Steps to prepare project in eclipse IDE

step 1: Open Eclipse IDE, while opening name the workspace and click
launch

step2:

click on file--->new--->project-->select java project-->click next-->name


the project--->click on finish

step 3:

create packages in src

Rightclick on "src"-->new--->package
name the package and click on finish

step:4

Right click on package-->new--->class

name the class and click finish

Note:

To increase font size, click on window option-->preferences-->General-->


Apperance-->colors and fonts-->java--->java editor text font-->apply

ctrl+shift+o--->To add predefined libraries

full stack java batch-21 Page 2


7-2-2025
Friday, February 7, 2025 8:08 PM

[Link]

package p1;

public class Employeesalary {


public int totalsalary(int bsal) {
return(3*bsal);
}
}

[Link]

package p2;

import [Link];

import [Link];

public class Employeemain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter bsal:");
int bsal=[Link]();
Employeesalary ob=new Employeesalary();
int totalsal=[Link](bsal);
[Link]("Totalsal:"+totalsal);
}
}

full stack java batch-21 Page 1


[Link]

package p1;

public class Bookdetails {


public String bcode,bname,bauthor;
public void getbookdetails()
{
[Link]("======BookDetails=====");
[Link]("Bookcode:"+bcode);
[Link]("Bookname:"+bname);
[Link]("Bookauthor:"+bauthor);
}
}

[Link]

package p2;

import [Link];

import [Link];

public class Bookmain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Bookdetails ob=new Bookdetails();
[Link]("Enter the bookcode:");
[Link]=[Link]();
[Link]("Enter the bookname:");
[Link]=[Link]();
[Link]("Enter the bookauthor:");
[Link]=[Link]();
full stack java batch-21 Page 2
[Link]=[Link]();
[Link]();
}
}

output:
Enter the bookcode:
A-121
Enter the bookname:
C Language
Enter the bookauthor:
BSWamy
======BookDetails=====
Bookcode:A-121
Bookname:C Language
Bookauthor:BSWamy

Define packages in java

==>Package is a collection classes


==>packages are of two types

[Link] packages
[Link] packages

[Link] packages

The packages which are already available in java library are called as predefined
packages

[Link]
[Link]

[Link] packages

The packages which are defined by the user are called user defined packages
we use "package" keyword to define userdefined packages

syntax

package package_name

full stack java batch-21 Page 3


Developing getter , setter methods by using eclipse ide

To generate getter and setter methods automatically

click on empty space==>select source==>generate getters and setter

[Link]
==========

package p1;

public class Product {


public String code,name;
public float price;
public String getCode() {
return code;
}
public void setCode(String code) {
[Link] = code;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
[Link] = price;
}
}

[Link]

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

package p2;

full stack java batch-21 Page 4


package p2;

import [Link];

import [Link];

public class Productmain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Product ob=new Product();
[Link]("Enter the product code:");
[Link]([Link]());
[Link]("Enter the product name:");
[Link]([Link]());
[Link]("Enter the product price");
[Link]([Link]());
[Link]("====Displaying by using getter methods====");
[Link]("Product Code:"+[Link]());
[Link]("Product Name:"+[Link]());
[Link]("Product Price:"+[Link]());
}
}

output:

Enter the product code:


M121
Enter the product name:
Mouse
Enter the product price
500
====Displaying by using getter methods====
Product Code:M121
Product Name:Mouse
Product Price:500.0

full stack java batch-21 Page 5


full stack java batch-21 Page 6
8-2-2025
Saturday, February 8, 2025 8:20 PM

[Link]

package p1;

public class Customer {


String custId,custName,custCity,custMailid;
long custphNO;
public String getCustId() {
return custId;
}
public void setCustId(String custId) {
[Link] = custId;
}
public String getCustName() {
return custName;
}
public void setCustName(String custName) {
[Link] = custName;
}
public String getCustCity() {
return custCity;
}
public void setCustCity(String custCity) {
[Link] = custCity;
}
public String getCustMailid() {
return custMailid;
}
public void setCustMailid(String custMailid) {
[Link] = custMailid;
}
public long getCustphNO() {
return custphNO;
}
public void setCustphNO(long custphNO) {
[Link] = custphNO;
}
}

[Link]

package p2;

import [Link];

full stack java batch-21 Page 1


import [Link];

import [Link];

public class Customermain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Customer ob=new Customer();
[Link]("Enter the customer Id:");
[Link]([Link]());
[Link]("Enter the customer name:");
[Link]([Link]());
[Link]("Enter the customer City:");
[Link]([Link]());
[Link]("Enter the customer Mailid:");
[Link]([Link]());
[Link]("Enter the customer Phone No:");
[Link]([Link]());
[Link]("====Displaying by using Getter Methods");
[Link]("CustId:"+[Link]());
[Link]("CustName:"+[Link]());
[Link]("CustCity:"+[Link]());
[Link]("CustMailId:"+[Link]());
[Link]("CustPhNo:"+[Link]());
}
}

output:
Enter the customer Id:
A-234
Enter the customer name:
Krishna
Enter the customer City:
HYd
Enter the customer Mailid:
krishna@[Link]
Enter the customer Phone No:
9898981234
====Displaying by using Getter Methods
CustId:A-234
CustName:Krishna
CustCity:HYd
CustMailId:krishna@[Link]
CustPhNo:9898981234

Assignment
==========

ProjectName: Student_App
packages:
p1:Percentage,Totalmarks
full stack java batch-21 Page 2
p1:Percentage,Totalmarks
p2:StudentMainClass

Assignment
========
Project Name:ArithmeticOperations
Packages:

p1:Addition,Substraction,Multiplication,Division,ModDivision
p2:ArthimeticMainClass

Accessmodifiers in Java

AccessModifiers in java will specify the visibility of programming


components within the project

==>The following are the some important access specifiers/modifiers in


java

[Link]
[Link]
[Link]
[Link]

[Link]:

If a component is specified with "public" those components are used


within the project

[Link]

"private" programming components are accessed only inside the class

[Link]

"protected" programming components are accessed within in the package

[Link]

The programming components which are declared without any access


modifiers are known as default

full stack java batch-21 Page 3


modifiers are known as default

These "default" programming components are accessed only inside the


package.

[Link]

package p1;

public class Accessspecifier {


public int x=25;
public void method1() {
[Link](x);
}
}

Accessmain

[Link]

package p2;

import [Link];
full stack java batch-21 Page 4
import [Link];

public class Accessmain {


public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method1();
}
}

Private access specifier

[Link]

package p1;

public class Accessspecifier {


public int x=25;
private void method1() {
[Link](x);
}
}

[Link]

package p2;

import [Link];

public class Accessmain {


public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method1();
}
}

[Link]

package p1;

public class Accessspecifier {


public int x=25;
private void method1() {
[Link](x);
}
public void method2() {

full stack java batch-21 Page 5


public void method2() {
method1();
}
}

[Link]

package p2;

import [Link];

public class Accessmain {


public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method2();
}
}

Example

[Link]

package p1;

public class Accessspecifier {


public int x=25;
private void method1() {
[Link](x);
}
public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method1();
}
}

Example:

Protected

package p1;

public class Accessspecifier {


public int x=25;
protected void method1() {
[Link](x);
full stack java batch-21 Page 6
[Link](x);
}
public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method1();
}
}

example:

default

package p1;

public class Accessspecifier {


public int x=25;
void method1() {
[Link](x);
}
public static void main(String[] args) {
Accessspecifier ob=new Accessspecifier();
ob.method1();
}
}

full stack java batch-21 Page 7


9-2-2025
Sunday, February 9, 2025 8:10 PM

Question-2

A network protocol specifies how data is exchanged via transmission media. The protocol
converts each message into a stream of 1's and 0's. Given a decimal number, write an
algorithm to convert the number into a binary form.
From <[Link]

Solution:

import [Link];
public class DecimalToBinary
{
public static void main(String[] args)
{ "10001"
Scanner s=new Scanner([Link]); 10001
int x=[Link](); "10000"
String y=[Link](x); "5"==>5
[Link](y); 23-->"23"
}
}

[Link](int i) is method in java that converts a given integer into its


binary respresentation

It takes int as an argument

Returns a String containing binary representation of the number

Define import statment?

"import" statement will make class available from one package to another package.

Types of imports in java:

==>importing process in java can be in three ways

a) using "import [Link]"


full stack java batch-21 Page 1
a) using "import [Link]"
b) using "import package.*"
c) using "full qualified name"

a) using "import [Link]"

In this importing we will specify the class_name to make it available to the current
class.

This importing process is known as "Explicit importing process"

Example:
import [Link];

b) using "import package.*"

In this importing process all the classes from the package are available to the current
program

This importing is called as "implicit importing"

example:

import [Link].*;

c) using "fully qualified name"

The process of decalaring class with package names in the programming code is
known as fully qualified name.

Example:

[Link] s=new [Link]([Link]);

***TCS

Define a method which returns the value 1 if the given number is even, in other case
return 0

full stack java batch-21 Page 2


Name of the method: isEven() //which accepts an integer value as argument and
return 1 if the given number is even, else return 0

Argument: int
Return type: an integer value
example: if x=22 return 1, if x=35 return 0

[Link]

package p1;

public class Even {


public int isEven(int n) {
if(n%2==0) {
return 1;
}
else {
return 0;
}
}
}

[Link]

package p2;

import [Link];

import [Link];

public class Evenmain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Even ob=new Even();
[Link]("Enter the value:");
int val=[Link]();
int r=[Link](val);
[Link]("Result:"+r);
}
}

output:
Enter the value:
22

full stack java batch-21 Page 3


22
Result:1

*** Wipro

Define a method which returns the greatest number among two numbers
write the method with the following specifications

Name of the method: getGreatest() // which accepts two integer value as argument
and returns the greatest value.

Arguments: two argument of type integer

Return type: an integer value

Specifications

The value returned by the method getGreatest() is determined by the following rules:

if any of the given number is negative , return -1


if any of the given number is zero ,return -2
if any of the number is positive return the greatest number
[Link]

package p1;

public class Greatest {


public int getGreatest(int x,int y) {
if(x<0 || y<0) {
return -1;
}
else if(x==0 || y==0) {
return -2;
}
else {
if(x>y) return x;
else return y;
}
}
}

[Link]

package p2;

full stack java batch-21 Page 4


import [Link];

import [Link];

public class Greatestmain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Greatest ob=new Greatest();
[Link]("Enter the value1:");
int val1=[Link]();
[Link]("Enter the value2:");
int val2=[Link]();
int r=[Link](val1,val2);
[Link]("Result:"+r);
}
}

output:
Enter the value1:
33
Enter the value2:
44
Result:44

-2,23

-1

34,0

-2

23,44

44

full stack java batch-21 Page 5


11-2-2025
Tuesday, February 11, 2025 8:07 PM

***TCS

Define a method which returns the number if it is a even number, if the number is
odd then return the next multiple of 10

Write the method with the following specifications

Name of the method: oddRounder() //which accepts an integer value as argument and
return the same value if it is even number., if the value is odd then return the next
multiple of 10

Arguments: one argument of type integer

Return type: an integer value

x=24 then return 24


if x=25 then return 30

Logic:

k=n/10
return (k+1)*10

n=23
k=n/10
=23/10 n=41
=2 k=n/10
return (k+1)*10
(k+1)*10
(2+1)*10
3*10 k=4
=30 (4+1)*10
5*10
50

[Link]

package p1;

full stack java batch-21 Page 1


public class Rounder1 {
public int oddRounder(int n) {
if(n%2==0) {
return n;
}
else
{
int k=n/10;
return (k+1)*10;
}
}
}

[Link]

package p2;

import [Link];

import p1.Rounder1;

public class Roundermain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Rounder1 ob=new Rounder1();
[Link]("Enter the value:");
int val=[Link]();
int r=[Link](val);
[Link]("Result:"+r);

}
}

[Link]

package p1;

public class User {


public static String userName,mailId;
public static long phNo;
}

[Link]

package p2;

import [Link];
full stack java batch-21 Page 2
import [Link];

import [Link];

public class Usermain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
[Link]=[Link]();
[Link]("Enter the mailId:");
[Link]=[Link]();
[Link]("Enter the phoneNo:");
[Link]=[Link]();
[Link]("Username:"+[Link]);
[Link]("Mailid:"+[Link]);
[Link]("PhoneNo:"+[Link]);
}
}

output:

Enter the username:


Kumar
Enter the mailId:
kumar@[Link]
Enter the phoneNo:
9898981234
Username:Kumar
Mailid:kumar@[Link]
PhoneNo:9898981234

Static import
================

The process of declaring import statement with "static"


keyword is known as static import and which is introduced
by java5 version.

syntax

import static package_name.Class_name.*

Ex:

import static [Link].*

Advantage:

full stack java batch-21 Page 3


==>In static import all the static members of a class
are available to current running program and the static
members can be accessed directly without class name.
[Link]

package p1;

public class User {


public static String userName,mailId;
public static long phNo;
}

[Link]

import [Link];

import static [Link].*;

public class Usermain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the username:");
userName=[Link]();
[Link]("Enter the mailId:");
mailId=[Link]();
[Link]("Enter the phoneNo:");
phNo=[Link]();
[Link]("Username:"+userName);
[Link]("Mailid:"+mailId);
[Link]("PhoneNo:"+phNo);
}
}

output:
Enter the username:
rajesh
Enter the mailId:
rajesh@[Link]
Enter the phoneNo:
9898981234
Username:rajesh
Mailid:rajesh@[Link]
PhoneNo:9898981234

If we read string data after numeric data, the string data


will be skipped because the enter key information is available
as a char data type for nextLine().To overcome this problem we
have to use Parse methods
full stack java batch-21 Page 4
have to use Parse methods

byte var=[Link]([Link]());
short var=[Link]([Link]());
int var=[Link]([Link]());
long var=[Link]([Link]());
float var=[Link]([Link]());
double var=[Link]([Link]());

[Link]

package p1;

import [Link];

public class Program {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the Book Code:");
int code=[Link]([Link]());
[Link]("Enter the Book Name:");
String name=[Link]();
[Link]("=====Details====");
[Link]("===The code is:"+code);
[Link]("===The Book name is:"+name);
}
full stack java batch-21 Page 5
}
}

full stack java batch-21 Page 6


12-2-2025
Wednesday, February 12, 2025 8:06 PM

Strings in java

The sequenced collection of characters which are represented in double quotes is


known as string

0 1 2 3 4 5 6 7 index values
L ANGUAGE

The characters in the string are organized based on the index values.

The following are the predefined classes from [Link] package are used to create
String applications

[Link] class
[Link] Buffer class
[Link] Builder Class

To check predefined methods inside string class type the following command

javap [Link]

Write a program to find length of the string

Program:

[Link]

package p1;

import [Link];

public class String1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
int len=[Link]();
[Link]("The length of the string is:"+len);
}
}

OUTPUT:
full stack java batch-21 Page 1
OUTPUT:

Enter a string:
language
The length of the string is:8

length() is used to find the length of the string

Define toString()?

toString() is used to display the data present inside the


object. This toString() is auto executable method and is
executed automatically when we use an object

[Link]

package p1;

import [Link];

public class String1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
String str1=[Link]();
[Link]("The given string is:"+str1);
}
}

output:

Enter a string:
language
The given string is:language

CharAt() method is used to retrieve character from the string


based on index value.

[Link]

full stack java batch-21 Page 2


package p1;

import [Link];

public class String1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
char ch=[Link](2);
[Link]("The character present at index 2:"+ch);
}
}

output:

Enter a string:
lanugage
The character present at index 2:n

write a program to read a string and display reverse of a


string.

input:
language

output:
egaugnal

[Link]

package p1;

import [Link];

public class String1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
int len=[Link]();
[Link]("===Reverse of a string=====");
for(int i=len-1;i>=0;i--)
{
full stack java batch-21 Page 3
int len=[Link]();
[Link]("===Reverse of a string=====");
for(int i=len-1;i>=0;i--)
{
char ch=[Link](i);
[Link](ch);
}
}
}
language

output: length=8
Enter a string:
i=len-1
language i=7
===Reverse of a string=====
egaugnal

Write a program to read a string and display the count of vowels

vowels : a e i o u
Input: language
count of vowels:4

[Link]
package p1;

import [Link];

public class String1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
int len=[Link]();
int count=0;
for(int i=0;i<len-1;i++)
{
char ch=[Link](i);
switch(ch)
{
case 'a':count++;
break;
case 'e':count++;
break;
case 'i':count++;
break;
case 'o':count++;
break;
case 'u':count++;
full stack java batch-21 Page 4
case 'u':count++;
break;
}
}
[Link]("Count of vowels:"+count);
}
}

output:

Enter a string:
java language program
Count of vowels:8

Write a program to read a string and check the string is palindrome string or not

Note:

The reverse of string is equal to a given string is known as palindrome string

i/p: madam

full stack java batch-21 Page 5


15-2-2025
Saturday, February 15, 2025 8:09 PM

apple

Define ASCII Code?

The unique numeric number which is generated when a key is pressed from the
keyboard is known as ASCII(American standard code for information interchange)
code
Every key in keyboard will have its own ASCII Value

ASCII values for upper case letters(A to Z): 65 to 90


ASCII values for lower case letters(a to z): 97 to 122
ASCII values for number(0 to 9):48 to 57

Write a program to generate upper case letters, lower case letters and number(0-9)

package p1;

public class Ascii {


public static void main(String[] args) {
[Link]("=====Upper Case Letters=======");
for (int i=65;i<=90;i++) {
char ch=(char)i;
[Link](ch);
}
[Link]("=====Lower Case letters");
for(int i=97;i<=122;i++)
{
char ch=(char)i;
[Link](ch);
}
[Link]("===Numbers(0-9)=====");
for(int i=48; i<=57;i++) {
char ch=(char)i;
[Link](ch);
}
}
}

output:
full stack java batch-21 Page 1
output:

=====Upper Case Letters=======


A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
=====Lower Case letters
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q

full stack java batch-21 Page 2


q
r
s
t
u
v
w
x
y
z
===Numbers(0-9)=====
0
1
2
3
4
5
6
7
8
9

Write a program to read a string and count the numbers in a string

Input

java19 version on 20th sept 2022

output:
Count of numbers:8

java19 version on 20th sept 2022

package p1;

import [Link];

public class Numbers {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string:");
String str=[Link]();

full stack java batch-21 Page 3


String str=[Link]();
int len=[Link]();
int count=0;
[Link]("=====Result======");
for(int i=0;i<=len-1;i++)
{
char ch=[Link](i);
int z=(int)ch;
if(z>=48 && z<=57)
{
count++;
}
}
[Link]("Count of numbers:"+count);

}
}

output:
Enter the string:
java 19 version on 20th sept 2022
=====Result======
Count of numbers:8

wipro 2020

write a program to read a string and display mirror image

input
language

output language len=8


last index=7(len-1)
language | egaugnal

logic:

for(int j=len-1;j>=0;j--)
{
char ch=[Link](j);
}

full stack java batch-21 Page 4


package p1;

import [Link];

public class Mirror {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string:");
String str=[Link]();
int len=[Link]();
for(int i=0;i<=len-1;i++)
{
char ch=[Link](i);
[Link](ch+" ");
}
[Link]("|");
for(int j=len-1;j>=0;j--) {
char ch=[Link](j);
[Link](" "+ch);
}

}
}

output:
Enter the string:
language
l a n g u a g e | e g a u g n a l

Assignment

write a program to print [Link] vowels,[Link] consonants,[Link] special symbols


present in a given string

Input

java19, by 2020%year.

output

Count of vowels:4
full stack java batch-21 Page 5
Count of vowels:4
Count of consonants:6
Count of Numbers:6
Count of others:5

full stack java batch-21 Page 6


16-2-2025
Sunday, February 16, 2025 8:11 PM

Hackerrank

An e-commerce website wishes to find the lucky customer who will be eligible for full value
cash back. For this purpose,a number N is fed to the system. It will return another number
that is calculated by an algorithm. In the algorithm, a sequence is generated, in which each
number n the sum of the preceding numbers. initially the sequence will have two 1's in it.
The System will return the Nth number from the generated sequence which is treated as the
order ID. The lucky customer will be one who has placed that order. Write an alorithm to
help the website find the lucky customer.
From <[Link]

Program:

n=8

1 1 2 3 5 8 13 21

order=21

n=5

1 1 2 3 5

order=5

n=6

1 1 2 3 5 8

order=8

n=9
n=1
1 1 2 3 5 8 13 21 34
1 1
full stack java batch-21 Page 1
n=1
1 1 2 3 5 8 13 21 34
1 1
order=34
output=1
Program: n=2
import [Link]; 1 1
public class LuckyCustomer{
public static int findLuckyCustomer(int N){ output=1
if(N==1 || N==2){
return 1;
}
Flow of execution
int a=1,b=1;
int nextNumber=0; N=8

for(int i=3;i<=N;i++){ a b
nextNumber=a+b; 1 1
a=b;
b=nextNumber; i=3
} 3<=8 True
return b; nextNumber=a+b
} =1+1
public static void main(String[] args){ =2
Scanner s=new Scanner([Link]); nextNumber=2
int N=[Link](); a=1
[Link](findLuckyCustomer(N)); b=2
}
} 21 i=4
4<=8 True
nextNumber=a+b
output:21 =1+2
=3
nextNumber=3
a=2
b=3

i=5
5<=8(True)
nextNumber=2+3=5
a=3
b=5
full stack java batch-21 Page 2
b=5

i=6
6<=8(True)
nextNumber=3+5=8
a=5
b=8

i=7
7<=8(True)
nextNumber=5+8=13
a=8
b=13

i=8
8<=8(True)
nextNumber=21
a=13
b=21

i=9
8<=9(False)

Program:

package p1;

import [Link];

public class String5 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string:");
String str=[Link]();
int len=[Link]();
int vcount=0,acount=0,ncount=0;
for(int i=0;i<=len-1;i++)
{
char ch=[Link](i);
int k=(int)ch; //char into Ascii
if((k>=65 && k<=90) || (k>=97 && k<=122))
{
acount++;
}
if(k>=48 && k<=57) {
ncount++;
full stack java batch-21 Page 3
ncount++;
}
switch(ch)
{
case 'a':
case 'A':vcount++;
break;
case 'e':
case 'E':vcount++;
break;
case 'i':
case 'I':vcount++;
break;
case 'o':
case 'O':vcount++;
case 'u':
case 'U':vcount++;
break;
}
}
[Link]("Count of vowels:"+vcount);
[Link]("Count of consonents:"+(acount-vcount));
[Link]("Count of numbers:"+ncount);
[Link]("Count of others:"+(len-(acount+ncount)));
}
}

output:
Enter the string:
java 19,by 2022%year.
Count of vowels:4
Count of consonents:6
Count of numbers:6
Count of others:5

full stack java batch-21 Page 4


17-2-2025
Monday, February 17, 2025 8:06 PM

Define substring()

substring() method is used to retrieve the part of the string based on index values

language length=8

last index value=len-1


=8-1
=7

2 index to 4 index-->ngu
0 index to 2 index-->lan
0 index to 3 index-->lang
3 index to 6 index-->guag
5 index to 7 index-->age

substring(int)
substring(int,int)

package p1;
full stack java batch-21 Page 1
package p1;

import [Link];

public class String6 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter a string:");
String str=[Link]();
String s1=[Link](4);
[Link]("The substring of s1 is:"+s1);
String s2=[Link](1,5);
[Link]("The substring of s2 is:"+s2);
}
}

output:
Enter a string:
program
The substring of s1 is:ram
The substring of s2 is:rogr

Write a program to read student hall ticket number and display the branch based
on the branch code.

01==>civil
02==>EEE 226N120591
03-->mech
04--->ece
substring(6,8)
05-->cse

[Link]

package p1;
public class Generatebranch {
public String generate(String brCode)
{
return switch(brCode)
{
case "01": yield "CIVIL";
case "02": yield "EEE";
case "03": yield "MECH";
case "04": yield "ECE";
case "05": yield "CSE";
default: yield null;

full stack java batch-21 Page 2


default: yield null;
};
}
}

[Link]

package p2;

import [Link];

import [Link];

public class String7 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the Hall Ticket Number:");
String rollNo=[Link]();
int len=[Link]();
if(len==10) {
String brCode=[Link](6,8);
Generatebranch ob=new Generatebranch();
String branch=[Link](brCode);
if(branch==null)
{
[Link]("Invalid Branch");
}
else
{
[Link]("Hall Ticket Number Belongs to:"+branch);
}

}
else
{
[Link]("Invalid Hall Ticket Number");
}
}
}

output:
Enter the Hall Ticket Number:
226N120591
Hall Ticket Number Belongs to:CSE

Define string comparision process?

The process of comparing two strings is known as string comparision Process

we use the following to perform string comparision process


full stack java batch-21 Page 3
we use the following to perform string comparision process

a)equals() method
b)compareTo() method
c)"is equalto(==)" operator

(a) using equals() method

equals() method is used to compare two strings and generate boolean


value(true/false) as a result

syntax:

[Link](s2)

output:
[Link]

package p1;

import [Link];

public class Compare {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string -1:");
String s1=[Link]();
[Link]("Enter the string-2:");
String s2=[Link]();
boolean z=[Link](s2);
[Link](z);
}
}

Enter the string -1:


python
Enter the string-2:
java
false

full stack java batch-21 Page 4


18-2-2025
Tuesday, February 18, 2025 8:07 PM

b)compareTo()

compareTo() is used to compare two strings and generate int result

syntax:

int z=[Link](s2)

Example:

Enter the string1:

abc

Enter the string2:

Abc

Enter the string1:

apple

Enter the string2:


ant

Enter the string 1:

doNkey

Enter the string2:

dog

package p1;

import [Link];

public class Compare {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string-1");
String s1=[Link]();
[Link]("Enter the string-2");
String s2=[Link]();
int z=[Link](s2);
if(z==0)
{
[Link]("String are equal");
}
else if(z>0)
{
[Link]("S1 is greater than s2");
}
else
{
[Link]("S1 is less than S2");
}
}
}

output:

Enter the string-1


dog
Enter the string-2
dog
String are equal

full stack java batch-21 Page 1


Using "equalto(==)" operator

equalto(==) will compare the object references, which means it


will not compare the content(data) available inside the objects

we can create objects for string class in two ways

[Link] literal object creation

String s1="apple"
String s2="apple"

[Link] operator object creation

String s3=new String("apple")


String s4=new String("apple")

Define string constant Pool?

The seperate partition of heap area where string objects are created is known as
"String constant pool" If objects are created by using string literal process , the
objects are stored in "string constant pool"

*******
Inside string constant pool , duplicate object creation for same content is not
possible

What is the difference between string literal process and "new operator process"?

In string literal process , the execution control will check the string constant pool,
whether the string constant pool is containing any object with same data

if the object with same data is not available then new object will be created
if the object with same data is available then new object will not be created

In new operator process new object will be created for every data.

full stack java batch-21 Page 2


19-2-2025
Wednesday, February 19, 2025 8:05 PM

String Concatenation Process

Define string concatenation process?

The process of combining multiple strings into a single string is known as string
concatenation process

To perform string concatenation process we use the following

i) "+" Operator
ii) concat() method

package p1;

public class Concatenation {


public static void main(String[] args) {
String s1="java";
String s2="oracle";
String s3="python";
String s4= s1+s2+s3; //javaoraclepython
[Link]("S4:"+s4);
String s5=[Link](s3);//javapython
[Link]("S5:"+s5);//javapython
String s6=[Link](s2).concat(s3);//javaoraclepython
[Link]("S6:"+s6);
}
}

output:
S4:javaoraclepython
S5:javapython
S6:javaoraclepython

stringbuffer class

The string buffer class is available inside [Link] package

The string buffer class contains the following methods

[Link]()
[Link]()
full stack java batch-21 Page 1
[Link]()
[Link]()
[Link]()
[Link](int)
[Link](String)
[Link](CharSequence)

Inorder to access the methods inside the StringBuffer class we have to create object to
StringBuffer class

StringBuffer sb=new StringBuffer();

In this syntax StringBuffer object is created with the default capacity equal to 16
characters. we use append() method to add the data to StringBuffer objects

The capacity of StringBuffer object increases dynamically at runtime by "doubling the


capacity and adding 2"

==>16,34,70

package p1;

import [Link];

public class Buffer {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
StringBuffer sb=new StringBuffer();
[Link]("====Buffer Status=====");
[Link]("Default Capacity:"+[Link]());
}
}

output:
====Buffer Status=====
Default Capacity:16

package p1;

import [Link];

public class Buffer {


public static void main(String[] args) {

full stack java batch-21 Page 2


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
StringBuffer sb=new StringBuffer();
[Link]("====Buffer Status=====");
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
while(true)
{
[Link]("=====choice======");
[Link]("[Link]()\[Link]()");
[Link]("Enter the choice:");
switch([Link]([Link]())) {
case 1:
[Link]("Enter the data:");
[Link]([Link]());
[Link]("data in buffer:"+[Link]());
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
break;
}

}
}
}

output
====Buffer Status=====
Default Capacity:16
length:0
=====choice======
[Link]()
[Link]()
Enter the choice:
1
Enter the data:
java
data in buffer:java
Default Capacity:16
length:4
=====choice======
[Link]()
[Link]()
Enter the choice:
1
Enter the data:
programming
data in buffer:javaprogramming
Default Capacity:16
length:15
=====choice======
[Link]()
[Link]()
Enter the choice:
1
Enter the data:
a
data in buffer:javaprogramminga
Default Capacity:16

full stack java batch-21 Page 3


Default Capacity:16
length:16
=====choice======
[Link]()
[Link]()
Enter the choice:
1
Enter the data:
b
data in buffer:javaprogrammingab
Default Capacity:34
length:17
=====choice======
[Link]()
[Link]()
Enter the choice:

full stack java batch-21 Page 4


20-1-2025
Thursday, February 20, 2025 9:03 PM

package p1;

import [Link];

public class Buffer {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
StringBuffer sb=new StringBuffer();
[Link]("=====BufferStatus======");
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
while(true)
{
[Link]("=====Choice=======");
[Link]("[Link]()\[Link](int,string)\[Link]()");
[Link]("Enter the choice:");
switch([Link]([Link]())) {
case 1:
[Link]("Enter the data:");
[Link]([Link]());
[Link]("data in buffer:"+[Link]());
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
break;
case 2:
if([Link]()!=0) {
[Link]("Enter the index value:");
int index=[Link]([Link]());
if(index>=0 && index<[Link]())
{
[Link]("Enter the data:");
[Link](index,[Link]());
[Link]("data in buffer:"+[Link]());
}
else
{
[Link]("Invalid index value......");
}
}
else
{
full stack java batch-21 Page 1
{
[Link]("buffer is empty........");
}
break;
case 3:
if([Link]()!=0) {
[Link]("Enter the starting index:");
int i1=[Link]([Link]());
if(i1>=0 && i1<[Link]()) {
[Link]("Enter the ending index:");
int i2=[Link]([Link]());
if(i2>i1 && i2<[Link]()) {
[Link](i1, i2);
[Link]("data in buffer:"+[Link]());
}
else {

[Link]("Invalid Ending index");


}
}
else {
[Link]("Invalid Starting Index");
}

}
else {
[Link]("buffer is empty...");
}
}
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
}

}
}

full stack java batch-21 Page 2


21-2-2025
Friday, February 21, 2025 8:20 PM

package p1;

import [Link];

public class Buffer {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
StringBuffer sb=new StringBuffer();
[Link]("=====BufferStatus======");
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
while(true)
{
[Link]("=====Choice=======");
[Link]("[Link]()\[Link](int,string)\[Link]()\[Link]()");
[Link]("Enter the choice:");
switch([Link]([Link]())) {
case 1:
[Link]("Enter the data:");
[Link]([Link]());
[Link]("data in buffer:"+[Link]());
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
break;
case 2:
if([Link]()!=0) {
[Link]("Enter the index value:");
int index=[Link]([Link]());
if(index>=0 && index<[Link]())
{
[Link]("Enter the data:");
[Link](index,[Link]());
[Link]("data in buffer:"+[Link]());
}
else
{
[Link]("Invalid index value......");
}
}
else
{
[Link]("buffer is empty........");
}
break;
case 3:
if([Link]()!=0) {
[Link]("Enter the starting index:");
int i1=[Link]([Link]());
if(i1>=0 && i1<[Link]()) {

full stack java batch-21 Page 1


if(i1>=0 && i1<[Link]()) {
[Link]("Enter the ending index:");
int i2=[Link]([Link]());
if(i2>i1 && i2<[Link]()) {
[Link](i1, i2);
[Link]("data in buffer:"+[Link]());
}
else {

[Link]("Invalid Ending index");


}
}
else {
[Link]("Invalid Starting Index");
}

}
else {
[Link]("buffer is empty...");
}
break;
case 4:
if([Link]()!=0) {
[Link]();
[Link]("The reverse string is:"+[Link]());
}
else {
[Link]("Buffer is empty");
}
}
[Link]("Default capacity:"+[Link]());
[Link]("length:"+[Link]());
}

}
}

=====BufferStatus======
Default capacity:16
length:0
=====Choice=======
[Link]()
[Link](int,string)
[Link]()
[Link]()
Enter the choice:
4
Buffer is empty
Default capacity:16
length:0
=====Choice=======
[Link]()
[Link](int,string)
[Link]()
[Link]()

full stack java batch-21 Page 2


[Link]()
Enter the choice:
1
Enter the data:
java
data in buffer:java
Default capacity:16
length:4
Default capacity:16
length:4
=====Choice=======
[Link]()
[Link](int,string)
[Link]()
[Link]()
Enter the choice:
4
The reverse string is:avaj
Default capacity:16
length:4
=====Choice=======
[Link]()
[Link](int,string)
[Link]()
[Link]()
Enter the choice:
1
Enter the data:
java
data in buffer:avajjava
Default capacity:16
length:8
Default capacity:16
length:8
=====Choice=======
[Link]()
[Link](int,string)
[Link]()
[Link]()
Enter the choice:

Syntax:
StringBuffer sb=new StringBuffer(int);

In this syntax StringBuffer object will be created with the


capacity equal to the value passed as parameter while object
creation

example:

StringBuffer sb=new StringBuffer(4);

javaa
full stack java batch-21 Page 3
javaa

4+4+2=10
sb=4

package p1;

public class Buffer {


public static void main(String[] args) {
StringBuffer sb=new StringBuffer(4);
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("java");
[Link]("The data inside buffer object:"+[Link]());
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("A");
[Link]("The data inside the buffer object:"+[Link]());
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
}
}

Default Capacity:4
length:0
The data inside buffer object:java
Default Capacity:4
length:4
The data inside the buffer object:javaA
Default Capacity:10
length:5

Using the following the syntax:

StringBuffer sb=new StringBuffer("program")

In this syntax StringBuffer object is created with default


full stack java batch-21 Page 4
In this syntax StringBuffer object is created with default
capacity equal to the sum of 16+7=23 characters capacity buffer
object will be created

output:

package p1;

public class Buffer {


public static void main(String[] args) {
StringBuffer sb=new StringBuffer("java");
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("program");
[Link]("The data inside buffer object:"+[Link]());
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("develeopers");
[Link]("The data inside the buffer object:"+[Link]());
[Link]("Default Capacity:"+[Link]());
[Link]("length:"+[Link]());
}
}

Default Capacity:20
length:4
The data inside buffer object:javaprogram
Default Capacity:20
length:11
The data inside the buffer object:javaprogramdeveleopers
Default Capacity:42
length:22

Syntax

StringBuffer sb1=new StringBuffer("developer")


StringBuffer sb2=new StringBuffer(sb1)

program:
full stack java batch-21 Page 5
program:

package p1;

public class Buffer {


public static void main(String[] args) {
StringBuffer sb1=new StringBuffer("developer");
StringBuffer sb2=new StringBuffer(sb1);
[Link]("==========sb1======");
[Link]("sb1:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========sb2======");
[Link]("sb2:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========operation on sb2======");
[Link](0, 2);
[Link]("sb2:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========sb1======");
[Link]("sb1:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
}
}

output

==========sb1======
sb1:developer
capacity:25
length:9
==========sb2======
sb2:developer
capacity:25
length:9
==========operation on sb2======
sb2:veloper
capacity:25
length:7
==========sb1======
sb1:developer
capacity:25
length:9

full stack java batch-21 Page 6


22-2-2025
Saturday, February 22, 2025 8:07 PM

Syntax

StringBuffer sb1=new StringBuffer("developer")


StringBuffer sb2=new StringBuffer(sb1)

This syntax is used to interlink StringBuffer objects which


means one object will have data from another object
program:

package p1;

public class Buffer {


public static void main(String[] args) {
StringBuffer sb1=new StringBuffer("developer");
StringBuffer sb2=new StringBuffer(sb1);
[Link]("==========sb1======");
[Link]("sb1:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========sb2======");
[Link]("sb2:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========operation on sb2======");
[Link](0, 2);
[Link]("sb2:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
[Link]("==========sb1======");
[Link]("sb1:"+[Link]());
[Link]("capacity:"+[Link]());
[Link]("length:"+[Link]());
}
}

output

==========sb1======
sb1:developer
capacity:25
length:9
==========sb2======
sb2:developer
capacity:25
length:9
==========operation on sb2======
sb2:veloper
capacity:25
length:7
==========sb1======

full stack java batch-21 Page 1


==========sb1======
sb1:developer
capacity:25
length:9

String Tokenizer

StringTokenizer class is from [Link] package.

The following are methods of StringTokenizer Class

i)hasMoreTokens()
ii)nextToken()
iii)countTokens()

StringTokenizer class is used to break the given string into


tokens(parts/pieces) based on the delimiter(break
specification)

i)hasMoreTokens()

hasMoreTokens() is used to check the Token available or not,


and return boolean result.

syntax:

boolean hasMoreTokens();

ii)nextToken()

nextToken() method is used to retrieve and delete the token


from the StringTokenizer Object

syntax:

String nextToken();

iii)countTokens()

countTokens() method is used to count the tokens available from


stringTokenizer object.
full stack java batch-21 Page 2
stringTokenizer object.

syntax:

int countTokens();

package p1;

import [Link].*;

public class StringTokenizer1 {


public static void main(String[] args) {
full stack java batch-21 Page 3
public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string:");
String str=[Link]();
[Link]("Enter the delimiter");
String del=[Link]();
StringTokenizer ob=new StringTokenizer(str,del);
[Link]("count of Tokens:"+[Link]());
[Link]("====Tokens=====");
while([Link]())
{
String tk=[Link]();
[Link]([Link]());
}
}
}

Enter the string:


java language program
Enter the delimiter
a
count of Tokens:6
====Tokens=====
j
v
l
ngu
ge progr
m

Program:

Write a program to read a string and display the reverse words


from the string .

input: java langauge program


output avaj egaugnal margrop

package p1;

import [Link].*;

public class StringTokenizer1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the string:");
String str=[Link]();
StringTokenizer ob=new StringTokenizer(str," ");
[Link]("====Tokens====");
while([Link]())
{
String tk=[Link]();
StringBuffer sb=new StringBuffer(tk);
full stack java batch-21 Page 4
StringBuffer sb=new StringBuffer(tk);
[Link]([Link]());
}
}
}

output:

Enter the string:


java program
====Tokens====
avaj
margorp

full stack java batch-21 Page 5


24-2-2025
Monday, February 24, 2025 8:06 PM

Wrapper Class

The predefined class from [Link] package which are used to make primitive data
types available in the form of objects are known as wrapper classes.

Every primitive data type will have its own wrapper class and there are 8 wrapper
classes

*** Java Tools and Frameworks will hold data only in the form objects, because of
this reason we have to make primitive data types available in the form of objects

List of wrapper classes

Data type wrapper class


byte Byte 12
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean

Define Boxing Process?

The process of binding primitive data types into wrapper class object is known as
Boxing process

Boxing process is performed by using constructors.

List of constructors in Wrapper class

Wrapper class Constructors


Byte Byte(byte),Byte(String)
Short Short(short),Short(String)
Integer Integer(int),Integer(String)
full stack java batch-21 Page 1
Integer Integer(int),Integer(String)
Long Long(long),Long(String)
Float Float(float),Float(double),Float(String)
Double Double(double),Double(String)
Character Character(char)
Boolean Boolean(boolean),Boolean(String)

example:

package p1;

public class WrapperClass1 {


public static void main(String[] args) {
Integer ob1=new Integer(12);
Integer ob2=new Integer("23");
Float ob3=new Float(12.3F);
Float ob4=new Float(1234567.78);
Float ob5=new Float("23.1f");
Double ob6=new Double(12345.7);
[Link]("===Display data from Objects=====");
[Link]("ob1:"+[Link]());
[Link]("ob2:"+[Link]());
[Link]("ob3:"+[Link]());
[Link]("ob4:"+[Link]());
[Link]("ob5:"+[Link]());
[Link]("ob6:"+[Link]());

}
}

output:
full stack java batch-21 Page 2
output:
===Display data from Objects=====
ob1:12
ob2:23
ob3:12.3
ob4:1234567.8
ob5:23.1
ob6:12345.7

Define unboxing process?

The process of storing primitive type out of wrapper object without using toString()
is known as unboxing process

We use the following methods to perform unboxing process

byte byteValue();
short shortValue();
int intValue();
long longValue();
float floatValue();
double doubleValue();
char charValue();
boolean boolenValue();

package p1;

public class WrapperClass1 {


public static void main(String[] args) {
Integer ob1=new Integer(12);
Integer ob2=new Integer("23");
Float ob3=new Float(12.3F);
Float ob4=new Float(1234567.78);
Float ob5=new Float("23.1f");
Double ob6=new Double(12345.7);

//unboxing process
int i1=[Link]();
int i2=[Link]();
float i3=[Link]();
[Link]("===Display data from Objects=====");
[Link]("ob1:"+i1);
[Link]("ob2:"+i2);
[Link]("ob3:"+i3);
full stack java batch-21 Page 3
[Link]("ob3:"+i3);

}
}

Output
===Display data from Objects=====
ob1:12
ob2:23
ob3:12.3

full stack java batch-21 Page 4


25-2-2024
Tuesday, February 25, 2025 8:07 PM

Define auto boxing process?

The process of assigning a value directly to an object without using new keyword is
known as autoboxing process

Define autounboxing process

The process of assigning an object to a variable is called as unboxing process

example:

package p1;

public class WrapperClass {


public static void main(String[] args) {
Integer ob1=12;
Float ob2=12.34F;
Character ob3='A';
Boolean ob4=true;

//Autounboxing process

int i1=ob1;
float f1=ob2;
char ch=ob3;
boolean b1=ob4;
[Link]("Displaying the values:");
[Link]("i1:"+i1);
[Link]("f1:"+f1);
[Link]("ch:"+ch);
[Link]("b1:"+b1);
}
}

output:
Displaying the values:
i1:12
f1:12.34
ch:A
b1:true

full stack java batch-21 Page 1


Define Annotation?

The tag based information which is added to the programming component is known
as Annotation

The annotations are represented by using '@' symbol

These annotations will provide information to compiler at compilation stage

@SuppressWarning("removal")

package p1;

public class WrapperClass {


@SuppressWarnings("removal")
public static void main(String[] args) {
Integer ob1=new Integer(12);
Integer ob2=new Integer("23");
Float ob3=new Float(12.3F);
@SuppressWarnings("unused")
Float ob4=new Float(1234567.78);
@SuppressWarnings("unused")
Float ob5=new Float("23.1f");
@SuppressWarnings("unused")
Double ob6=new Double(12345.7);

//unboxing process
int i1=[Link]();
int i2=[Link]();
float i3=[Link]();
[Link]("===Display data from Objects=====");
[Link]("ob1:"+i1);
[Link]("ob2:"+i2);
[Link]("ob3:"+i3);
full stack java batch-21 Page 2
[Link]("ob3:"+i3);

}
}

Arrays in Java:

The sequenced collection of elements of same data type is known as array.

Types of Arrays

Arrays are categorized into two types

[Link] dimensional array


[Link] dimensional array

Single dimensional Array:

The arrrays which are declared with one dimension(with one row or one column)
are called as single dimensional arrays

Syntax:

Class_name arr_var[]=new Class_name[size];

Write a program to display multiple integer values using array?

package p1;

import [Link];

public class Array1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the size of Array:");
int n=[Link]();
Integer a[]=new Integer[n];
for(int i=0;i<[Link];i++)
{
a[i]=new Integer([Link]());
}
for(int i=0;i<[Link];i++)

full stack java batch-21 Page 3


for(int i=0;i<[Link];i++)
{
[Link](a[i].toString());
}
}
}

output:
Enter the size of Array:
5
31
32
33
34
35
31
32
33
34
35

What is the difference between

i)length
ii)length()

i)length

"length" is keyword used to find the length of the array

ii) length()

length() is used to find the length of the string

Extended for loop

Extended for loop is introduced in java 5 version and which is used to retrieve
elements from array-objects on the array-name

Syntax:

for(Wrapper_class var_name:array_name)
{
full stack java batch-21 Page 4
{
//loop body
}

package p1;

import [Link];

public class Array1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the size of Array:");
int n=[Link]();
Integer a[]=new Integer[n];
for(int i=0;i<[Link];i++)
{
a[i]=new Integer([Link]());
}
for(int i=0;i<[Link];i++)
{
[Link](a[i].toString());
}
[Link]("===Displaying arrray elements using extended for loop====");
for(Integer k: a)
{
[Link]([Link]());
}
}
}

Extended for loop is auto executable loop which executes automatically and there is
no concept of intialization, condition and increment/decrement

full stack java batch-21 Page 5


27-2-2025
Thursday, February 27, 2025 8:06 PM

Write a program to read and display Multiple string values using array.
[Link]

package p1;

public class Employee {


public String id,name,desg;
public int bSal;
public float totSal;
public String toString() {
return id+"\t"+name+"\t"+desg+"\t"+bSal+"\t"+totSal+"\t";
}
}

[Link]

package p1;

import [Link];

public class Array2 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the number of Employees:");
int n=[Link]([Link]());
Employee ob[]=new Employee[n];
[Link]("Enter the Employee Details.....");
for(int i=0;i<[Link];i++)
{
ob[i]=new Employee();
[Link]("Enter the EmpId:");
ob[i].id=[Link]();
[Link]("Enter the EmpName:");
ob[i].name=[Link]();
[Link]("Enter the EmpDesg:");
ob[i].desg=[Link]();
[Link]("Enter the EmpBSal:");
ob[i].bSal=[Link]([Link]());
ob[i].totSal=ob[i].bSal+(2*ob[i].bSal);
full stack java batch-21 Page 1
ob[i].totSal=ob[i].bSal+(2*ob[i].bSal);
}
[Link]("======Employee Details========");
for(Employee k :ob)
{
[Link]([Link]());
}
}
}

Write a program to print Bookdetails using Arrays

[Link]

package p1;

import [Link];

public class Arrray3 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the number of Books:");
int n=[Link]([Link]());
BookDetails ob[]=new BookDetails[n];
for(int i=0;i<[Link];i++)
{
[Link]("********Book Details********");
ob[i]=new BookDetails();
[Link]("Enter the BookCode:");
ob[i].code=[Link]();
[Link]("Enter the BookName:");
ob[i].name=[Link]();
[Link]("Enter the Book Author:");
ob[i].author=[Link]();
[Link]("Enter the BookPrice:");
ob[i].price=[Link]([Link]());
[Link]("Enter the BookQty:");
ob[i].qty=[Link]([Link]());
}
[Link]("=====BookDetails=====");
for(BookDetails k:ob)
{
full stack java batch-21 Page 2
{
[Link]([Link]());
}
}
}

[Link]

package p1;

public class BookDetails {


public String code,name,author;
public float price;
public int qty;
public String toString() {
return code+"\t"+name+"\t"+author+"\t"+price+"\t"+qty;
}
}

output:

Enter the number of Books:


2
********Book Details********
Enter the BookCode:
A121
Enter the BookName:
CLang
Enter the Book Author:
BSwamy
Enter the BookPrice:
23
Enter the BookQty:
2
********Book Details********
Enter the BookCode:
A122
Enter the BookName:
Java
Enter the Book Author:
KJoseph
Enter the BookPrice:
full stack java batch-21 Page 3
Enter the BookPrice:
55
Enter the BookQty:
2
=====BookDetails=====
A121 CLang BSwamy 23.0 2
A122 Java KJoseph 55.0 2

full stack java batch-21 Page 4


28-2-2025
Friday, February 28, 2025 8:06 PM

Define "Object Array"?

Object Array is from [Link] package, object array can hold disimilar values which
means values generated from different classes

syntax:

Object o[]=new Object[size];

[Link]

package p1;

public class User {


public String uName;
public long phNo;
public User(String uName,long phNo)
{
[Link]=uName;
[Link]=phNo;
}
public String toString() {
return uName+"\t"+phNo;
}
}

[Link]

package p1;

public class Object1 {


public static void main(String[] args) {
Object o[]=new Object[3];
o[0]=new Integer(121);//Wrapper Class
o[1]=new String("Java");//String class Object
o[2]=new User("Python",9898981234L);
[Link]("===Displaying values for Object Array=====");
for(Object k: o)
{
[Link]([Link]());
}
}
}
full stack java batch-21 Page 1
}

MultiDimensional Arrays

The arrays which are decalared with multiple dimensions are known as multi
dimensional arrays

Syntax of multidimensional arrays:

Class_name arr_var[][]=new Class_name[size][size];

package p1;

import [Link];

public class MultiDimension {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the number of rows:");
int r=[Link]();
[Link]("Enter the number of columns:");
int c=[Link]();
Integer ob[][]=new Integer[r][c];
[Link]("Enter the Integer Elements:");
for(int i=0;i<r;i++)
{
for (int j=0;j<c;j++)
{
ob[i][j]=new Integer([Link]());
}
}
[Link]("====Displaying the data=======");
full stack java batch-21 Page 2
[Link]("====Displaying the data=======");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
[Link](ob[i][j].toString()+" ");
}
[Link]();
}
}
}

output:
Enter the number of rows:
3
Enter the number of columns:
3
Enter the Integer Elements:
11
22
33
44
55
66
77
88
99
====Displaying the data=======
11 22 33
44 55 66
77 88 99

full stack java batch-21 Page 3


full stack java batch-21 Page 4
1-3-2025
Saturday, March 1, 2025 8:13 PM

Hacker rank solution-4


import [Link].*;
import [Link].*;

public class Solution {

public static void main(String[] args) {


Scanner s=new Scanner([Link]);
int n=[Link]();
int d,s1=0;
while(n!=0){ n=123
d=n%10;
123!=0
s1=s1+d; True
n=n/10; d=n%10
d=123%10
} 10)123(12
[Link](s1);
120
-------
} 3
}
d=3

s1=s1+d
=0+3
s1=3

n=n/10
10)123(12
120
------------
3
n=12

True

d=n%10
10)12(1
10
------
2
d=2
s1=s1+d
=3+ 2
s1=
n=n/10
n=12/10

10)12(1
10
-----
full stack java batch-21 Page 1
-----
2
n=1

d=n%10
10)1(0
0
------
1
d=1
s1=s1+d
=5+1
s1=6

n=n/10
=1/10
10)1(0
0
- --------
1
n=0

Write a program to display sum of diagonal elements in a 3X3 matrix

package p1;

import [Link];

public class SumDiagonal {


public static void main(String[] args) {
int sum=0;
Scanner s=new Scanner([Link]);
Integer ob[][]=new Integer[3][3];
[Link]("Enter 3X3 matrix:");
for(int i=0; i<3;i++) //rows
{
for(int j=0;j<3;j++)//cols
{
ob[i][j]=new Integer([Link]());
}

}
[Link]("====Displaying 3X3 Matrix======");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
[Link](ob[i][j].toString()+" ");
}
[Link]();
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{

full stack java batch-21 Page 2


{
if(i==j)
{
sum=sum+ob[i][j];
}
}
}
[Link]("====Sum of diagonal elements======");
[Link]("Sum:"+sum);
}
}

Enter 3X3 matrix:


1
2
3
4
5
6
7
8
9
====Displaying 3X3 Matrix======
1 2 3
4 5 6
7 8 9
====Sum of diagonal elements======
Sum:15

Write a program to read n integer elements and display

(i)smallest element
(ii)largest element

Logic explanation

int val=0;
int greater(Integer a[])
{
for(int i=0;i<[Link];i++)
{
if(a[i]>val) n=5====>length
{
val=a[i]; Elements
}
} a[0]=5
return val; a[1]=7
} a[2]=8
} a[3]=4
a[4]=3

val=0;
a[0]>val
5>0 True
full stack java batch-21 Page 3
5>0 True
val=5
a[1]>val largest=8
7>5 True
val=7
a[2]>val
8>7
val=8

a[3]>val
4>8 False

a[4]>val
3>8 false

full stack java batch-21 Page 4


3-3-2025
Monday, March 3, 2025 8:25 PM

[Link]

package p1;

public class greater {


int val=0;
int GreaterValue(Integer a[])
{
for(int i=0;i<[Link];i++)
{
if(a[i]>val)
{
val=a[i];
}
}
return val;
}
}

[Link]

package p1;

public class SmallerValue {


public int Smaller(Integer a[])
{
int val=a[0];
for(int i=0;i<[Link];i++)
{
if(a[i]<val)
{
val=a[i];
}
}
return val;
}
}

[Link]

package p1;

public class SmallerValue {


public int Smaller(Integer a[])
{
int val=a[0];
for(int i=0;i<[Link];i++)
{
if(a[i]<val)
{
val=a[i];
}
}
return val;
}
}

Enter the size of Array


5
Enter the Integer elements:
6
7
78
98
91
GreaterValue:98
Smaller value:6

can we pass parameter to standard main() method?

yes we can pass parameter to standard main method while


execution time, because the main() method call is
available at the time of execution
full stack java batch-21 Page 1
available at the time of execution

class Main1
{
public static void main(String[] args)
{
[Link]("===Main() method======");
for(String k:args)
{
[Link]([Link]());
}
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
[Link]("===Main() Method======");
for(String k:args)
{
[Link]([Link]());
}
}
}

output
12
12.38
python
hyd
A

Define Command line arguments?


full stack java batch-21 Page 2
Define Command line arguments?

The process of passing arguments as parameters to main() method is known as


command line arguments

What is the difference between

a) arguments
b) parameters

int x=12,y=13
add(x,y)

When we pass variables to a methd while method call then these variables are
called as parameters

when we pass values directly to a method while method_call these values are
called as arguments

What is the disadvantage of Array:

Array size once defined cannot be modified at runtime or execution time


because of this reason arrays are not preferable for real time applications. In
real time applications arrays are replaced with collection framework.

full stack java batch-21 Page 3


4-3-2025
Tuesday, March 4, 2025 8:06 PM

***Imp

Relations in java

The process of interlinking components(objects,class) in java are known as relations


in java

Relations in java are categorized into 3 types

[Link]
[Link]
[Link]

address
[Link]

The process in which one object holding the reference of another object is called as
reference concept

[Link]

package p1;

public class Address {


public String hNo,sName,city,state;
public int pinCode;
}

[Link]

package p1;

public class Address {


public String hNo,sName,city,state;
public int pinCode;
}

[Link]

package p1;

public class Customer {

full stack java batch-21 Page 1


public class Customer {
public String id,name;
public Address ad=new Address();
public Contact ct=new Contact();
public String toString() {
return
id+"\t"+name+"\t"+[Link]+"\t"+[Link]+"\t"+[Link]+"\t"+[Link]+"\t"+[Link]+"\t"+ct
.mailId+"\t"+[Link];
}
}

[Link]

package p1;

import [Link];

public class Referencemain {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Customer ob=new Customer();
[Link]("Enter the CustId:");
[Link]=[Link]();
[Link]("Enter the CustName:");
[Link]=[Link]();
[Link]("Enter the hno");
[Link]=[Link]();
[Link]("Enter the streetname:");
[Link]=[Link]();
[Link]("Enter the City:");
[Link]=[Link]();
[Link]("Enter the state:");
[Link]=[Link]();
[Link]("Enter the pincode:");
[Link]=[Link]([Link]());
[Link]("Enter the mailid:");
[Link]=[Link]();
[Link]("Enter the phoneno:");
[Link]=[Link]([Link]());
String data=[Link]();
[Link](data);
}
}

Inheritance:

The process in which one class takes the features or properties of another class is
known as inheritance

In inheritance process the classes are inherited with "extends" keyword

full stack java batch-21 Page 2


full stack java batch-21 Page 3
5-3-2025
Wednesday, March 5, 2025 8:15 PM

syntax:

class ClassA
{
//body
}
class ClassB extends ClassA
{
//body
}

In inheritance process we always create object for ChildClass

Syntax

ClassB ob=new ClassB();

***(i) In inheritance concept Instance members of PClass are accessed by


CClass object name
(ii) Static members of PClass are accessed by PClass name

[Link]
package p1;

public class PClass {


public int a;
public static int b;
public void m1()
{
[Link]("=====PClass Instance m1()=======");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
public static void m11() {
[Link]("==PClass Static m1()=======");
//[Link]("The value of a:"+a);//Error
[Link]("The value of b:"+b);
}
}

[Link]

package p1;
full stack java batch-21 Page 1
package p1;

public class CClass extends PClass {


public int x;
public static int y;
public void m2()
{
[Link]("====Cclass Instance m2()=====");
[Link]("The value of x:"+x);
[Link]("The value of y"+y);
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
public static void m22() {
[Link]("====CClass Static m22()====");
//[Link]("The value of x:"+x);//Error
[Link]("The value of y:"+y);
//[Link]("The value of a:"+a);//Error
[Link]("The value of b:"+b);
}
}

[Link]

package p1;

import [Link];

public class main1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
CClass ob=new CClass();//Normal Inheritance Process
[Link]("Enter the value of a:");
ob.a=[Link]();
[Link]("Enter the value of b:");
PClass.b=[Link]();
[Link]("Enter the value of x:");
ob.x=[Link]();
[Link]("Enter the value of y:");
CClass.y=[Link]();
ob.m1();
PClass.m11();
ob.m2();
CClass.m22();

}
}

output

full stack java batch-21 Page 2


Enter the value of a:
2
Enter the value of b:
3
Enter the value of x:
4
Enter the value of y:
5
=====PClass Instance m1()=======
The value of a:2
The value of b:3
==PClass Static m1()=======
The value of b:3
====Cclass Instance m2()=====
The value of x:4
The value of y5
The value of a:2
The value of b:3
====CClass Static m22()====
The value of y:5
The value of b:3

Constructors in inheritance

0-arg constructor

[Link]
package p1;

public class PClass {

public PClass()
{
[Link]("====PClass()======");
}
full stack java batch-21 Page 3
}
}

[Link]

package p1;

public class CClass extends PClass {


public CClass() {
[Link]("=====CClass()=======");
}
}

[Link]

package p1;

import [Link];

public class main1 {


public static void main(String[] args) {
CClass ob=new CClass();
}
}

full stack java batch-21 Page 4


6-3-2025
Thursday, March 6, 2025 8:07 PM

Parameterized constructor in inheritance

when we have parameterized constructor in PClass , then we must add super()


to CClass constructor and we have to pass parameter

super()

super() is used to execute constructors from the parent class

[Link]

package p1;

public class PClass {


public PClass(int k)
{
[Link]("====PClass()=====");
[Link]("The value of K:"+k);
}
}

[Link]

package p1;

public class CClass extends PClass {


public CClass(int k)
{
super(k);//PClass_con_call
}
}

[Link]

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass(123);
}
}

output
====PClass()=====
The value of K:123

Explanation
==============

full stack java batch-21 Page 1


Blocks in heritance

full stack java batch-21 Page 2


7-3-2025
Friday, March 7, 2025 8:06 PM

Imp:

what is the difference between

(i) super()
(ii)this()

i)super()

super() is used to execute constructors from PClass

ii) this()

this() is used to execute constructors/methods from the same class

Blocks in inheritance

PClass

package p1;

public class PClass {


public static int a;
static
{
[Link]("=====PClass Static Block======");
[Link]("The value of a:"+a);
}
}

CClass
package p1;

public class CClass extends PClass {


public static int b;
static
{
[Link]("=====CClass Static Block=======");
[Link]("The value of b:"+b);
}
}

Main1
package p1;

public class Main1 {


full stack java batch-21 Page 1
public class Main1 {
public static void main(String[] args) {
CClass ob=new CClass();
}
}

output:

=====PClass Static Block======


The value of a:0
=====CClass Static Block=======
The value of b:0

Empty
reference CClass ob=new CClass();
PClass
object
package p1;

public class PClass {


public static int a;
static
{
[Link]("=====PClass Static Block======");
[Link]("The value of a:"+a);
}
}

full stack java batch-21 Page 2


}

CClass
package p1;

public class CClass extends PClass {


public static int b;
static
{
[Link]("=====CClass Static Block=======");
[Link]("The value of b:"+b);
}
}

Main1
package p1;

public class Main1 {


public static void main(String[] args) {
CClass.a=200;

}
}

=====PClass Static Block======


The value of a:0

full stack java batch-21 Page 3


PClass

package p1;

public class PClass {


public static int a;
static
{
[Link]("=====PClass Static Block======");
[Link]("The value of a:"+a);
}
}

CClass
package p1;

public class CClass extends PClass {


public static int b;
static
{
[Link]("=====CClass Static Block=======");
[Link]("The value of b:"+b);
}
}

full stack java batch-21 Page 4


Main1
package p1;

public class Main1 {


public static void main(String[] args) {
CClass.a=200;

}
}

=====PClass Static Block======


The value of a:0

=====PClass Static Block======


The value of a:0
=====CClass Static Block=======
The value of b:0

what is empty object reference?

"Empty object reference" is created when we create object for the class holding
only static members

package p1;

public class PClass {


public static int a;
static
{
[Link]("=====PClass Static Block======");
[Link]("The value of a:"+a);
}
{
[Link]("===PClass Instance Block=====");
[Link]("The value of a:"+a);
}
}

package p1;

public class CClass extends PClass {


public static int b;
static
{
[Link]("=====CClass Static Block=======");
[Link]("The value of b:"+b);
}
{
[Link]("===CClass Instance Block=====");
[Link]("The value of b:"+b);
}
}

full stack java batch-21 Page 5


package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass();
}
}

=====PClass Static Block======


The value of a:0
=====CClass Static Block=======
The value of b:0
===PClass Instance Block=====
The value of a:0
===CClass Instance Block=====
The value of b:0

full stack java batch-21 Page 6


8-3-2025
Saturday, March 8, 2025 8:08 PM

Static block in PClass will have highest priority in execution than static block
available in child class

Instance block in pclass will have highest priority in execution than instance block
available in CClass

Method overriding process


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

If we have a method with same method signature in PClass and Cclass then PClass
method is replaced by CClass method is known as Method overriding process

Method signature means

return type
method name
para_list
para_type

Method overriding is divided into

a)Instance method overriding process


b)Static method overriding process
c)Constructor overriding process

a)Instance method overriding process

package p1;

public class PClass {


public int calculate(int x) {

full stack java batch-21 Page 1


public int calculate(int x) {
[Link]("=====PClass method======");
return x*x;
}
}

package p1;

public class CClass extends PClass {


public int calculate(int x) {
[Link]("====CClass method=====");
return x*x*x;
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass();
[Link]("Result:"+[Link](11));
}
}

output:

====CClass method=====
Result:1331

static method overriding

package p1;

public class PClass {


public static void m(int x) {
[Link]("=========PClass m()=========");
[Link]("The value of x:"+x);
}
}

package p1;

public class CClass extends PClass{


public static void m(int x) {
[Link]("===CClass m()====");
[Link]("The value of x:"+x);
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
PClass.m(123);
}
}

full stack java batch-21 Page 2


package p1;

public class PClass {


public static void m(int x) {
[Link]("=========PClass m()=========");
[Link]("The value of x:"+x);
}
}

package p1;

public class CClass extends PClass{


/*public static void m(int x) {
[Link]("===CClass m()====");
[Link]("The value of x:"+x);*/

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass();
ob.m(123);
}
}

full stack java batch-21 Page 3


9-3-2025
Sunday, March 9, 2025 8:15 PM

Define Method Hiding Process?

When we have same satic method signature in PClass and Cclass, then execution
control will execute CClass-method it will not reach PClass-method, this is known as
method hiding Process(Pclass method is Hided by Cclass method)

package p1;

public class PClass {


public static void m(int x) {
[Link]("=====PClass m()====");
[Link]("The value of x:"+x);
}
}

package p1;

public class CClass extends PClass {


public static void m(int x) {
[Link]("=====CClass m()======");
[Link]("The value of x:"+x);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
CClass ob=new CClass();
ob.m(123);
}
}

c)Constructor overriding

full stack java batch-21 Page 1


There is no constructor overriding process in java, because constructor in PClass will
have PClass name and Constructor in CClass will have CClass name.

**** Same instance method signature in PClass and CClass is known as Method
overriding process

***** Same static method signature in PClass and CClass is known as Method Hiding
Process

Method OverLoading Process

More than one Method with same method name but differentiated by parameter list
or parameter type is known as method overloading

Method overloading process is divided into 3 types

[Link] Method overloading


[Link] method overloading
[Link] overloading process

a)Instance method overloading:

More than one instance method with same method name but different parameter list or
parameter type is known as Instance method overloading process

this:

"this" keyword is used to access methods and variables from the same class

super:
full stack java batch-21 Page 2
super:

"super" keyword is used to access the methods from pclass

package p1;

public class PClass {


public void m(int a,int b)
{
this.m(a);
[Link]("The value of b:"+b);
}
public void m(int a)
{
[Link]("The value of a:"+a);
}
}

package p1;

public class CClass extends PClass {


public void m(int a,int b,int c,int d)
{
full stack java batch-21 Page 3
{
this.m(a,b,c);
[Link]("The value of d:"+d);
}
public void m(int a,int b,int c)
{
super.m(a,b);
[Link]("The value of c:"+c);
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass();
ob.m(11,12,13,14);
}
}

The value of a:11


The value of b:12
The value of c:13
The value of d:14
Tomorrow there is no class

full stack java batch-21 Page 4


11-3-2025
Tuesday, March 11, 2025 8:08 PM

static method overloading process

More than one static method with same name but different parameter list is known as
static method overloading

package p1;

public class PClass {


public static void m(int a, int b)
{
[Link]("===m(a,b)=====");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
public static void m(int a)
{
[Link]("=====m(a)=====");
[Link]("The value of a:"+a);
}
}

package p1;

public class CClass extends PClass {


public static void m(int a,int b,int c,int d)
{
[Link]("====m(a,b,c,d)=======");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
[Link]("The value of c:"+c);
[Link]("The value of d:"+d);
}
public static void m(int a,int b, int c)
{
[Link]("===m(a,b,c)======");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
[Link]("The value of c:"+c);
}
public void access(int a, int b,int c,int d)
{
super.m(a);
super.m(a,b);
this.m(a,b,c);
this.m(a,b,c,d);
}
full stack java batch-21 Page 1
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass();
[Link](11, 12, 13, 14);
}
}

Constructor overloading

More than one constructor with different parameter list is known as constructor
overloading

this():

this() is used to access the constructors from the same class

super():

super() is used to access the constructors from the parent class

package p1;

public class PClass {


public PClass(int a, int b)
{
this(a);
[Link]("The value of b:"+b);
}
public PClass(int a) {
[Link]("The value of a:"+a);
}
}

package p1;

public class PClass {


full stack java batch-21 Page 2
public class PClass {
public PClass(int a, int b)
{
this(a);
[Link]("The value of b:"+b);
}
public PClass(int a) {
[Link]("The value of a:"+a);
}
}

package p1;

public class Main1 {


public static void main(String[] args) {
CClass ob=new CClass(11,12,13,14);

}
}

The value of a:11


The value of b:12
The value of c:13
The value of d:14

Types of inheritance

Inheritance in java is categorized into the following

[Link] inheritance
[Link] inheritancec
[Link]-level inheritance
[Link] inheritance
[Link] Inheritance

full stack java batch-21 Page 3


single inheritance

The process of extracting the features from one class at a time is known as single
inhertiance

Multiple inheritance

full stack java batch-21 Page 4


12-3-2025
Wednesday, March 12, 2025 8:07 PM

single inheritance

The process of extracting the features from


one class at a time is known as single
inheritance

multiple inheritance

The process of extracting the features from


more than one class is known as multiple
inheritance

Multiple inheritance process using classes is not available in java, which generates
ambiguity(confusion) to the JVM because the multiple inheritance is using repetation
of same programming components. The ambiguity generates wrong results.

we can perform multiple inheritance concept in java by using interfaces

Interfaces in java:

Interface is a collection of variables,abstract methods and concrete methods from java 8


version onwards

(upto java 7 version interface is a collection of variables and abstract methods, which
means interface cannot hold concrete methods)

abstract methods

The methods which are declared without method_body are known as abstract methods

syntax:

return_type method_name(para_list)

full stack java batch-21 Page 1


full stack java batch-21 Page 2
concrete method

The methods which are declared with method body are known as concrete
methods

syntax:

return_type method_name(para_list)
{
//concrete method
}

coding rules for interface

Rule 1:

we use "interface" keyword to declare interfaces.

syntax:

interface interface_name
{

full stack java batch-21 Page 3


full stack java batch-21 Page 4
13-3-2025
Thursday, March 13, 2025 8:07 PM

Rule 2:

The programming components which are declared with in the interface are "public"

Rule 3:

In interface we can declare both primitive data types and non primitive data types

Rule 4:

The variables which are declared within in the interface are of automatically "static"
and "final"

static variables in interface will get the memory within the interface and can be
accessed with interface_name

final variables are variables with values once intialized cannot be modified.

Rule 5:

The methods which are declared within in the interface are automatically Nonstatic
abstract methods

Rule 6:

The interfaces are implemented to a class using "implements" keyword and the classes
are known as implementation classes

Rule:7

Implementation classes must construct body for all abstract methods of interface

Rule 8:

We can also declare Non implemented methods with in the implementation class

Rule 9:

Interfaces cannot be instantiated, which means we cannot create object for interaces
full stack java batch-21 Page 1
Interfaces cannot be instantiated, which means we cannot create object for interaces
directly

Arithmetic
===========
package p1;

public interface Arithmetic {


public abstract int calculate(int x,int y);
public abstract void dis(int k);
}

[Link]
=============

package p1;

public class Addition implements Arithmetic {


public int calculate(int x,int y) { //Implemented method
return x+y;
}
public void dis(int k) { //implemented method
[Link]("====dis(k)=====");
[Link]("The value of k:"+k);
}
public void access(int z) { //non implemented method
[Link]("=====access(z)====");
[Link]("The value of z:"+z);
}
}

[Link]
===================
package p1;

public class Interfacemain1 {


public static void main(String[] args) {
//Arithmetic ob=new Arithmetic(); //Error
Addition ob=new Addition();
int sum=[Link](12,13);
[Link]("Sum:"+sum);
[Link](123);
[Link](124);
}

output:

full stack java batch-21 Page 2


Sum:25
====dis(k)=====
The value of k:123
=====access(z)====
The value of z:124

faq:

What is the difference between

(i) Implemented methods


(ii) Non implemented methods

(i) Implemented methods

The methods which are taked from the interface and constructed body are known as
Implemented methods

(ii)
Non Implemented method

The methods which are not taken from the interface are known as non implemented
methods

full stack java batch-21 Page 3


14-3-2025
Friday, March 14, 2025 8:10 PM

Rule 10:

Interfaces can be implemented to any number of implementation classes without any


restriction

package p1;

public interface Compare {


public int comparision(int x,int y);
}

package p1;

public class Greatervalue implements Compare {


public int comparision(int x,int y) {
if(x>y) return x;
else return y;
}
}

package p1;

public class Smallervalue implements Compare {


public int comparision(int x,int y) {
if(x<y) return x;
else return y;
}
}

package p1;

import [Link];

public class Interfacemain1 {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
[Link]("Enter the value-1");
int v1=[Link]();

full stack java batch-21 Page 1


int v1=[Link]();
[Link]("Enter the value-2:");
int v2=[Link]();
[Link]("====Choice======");
[Link]("[Link]\n [Link]");
switch([Link]())
{
case 1:
Greatervalue gt=new Greatervalue();
int r1=[Link](v1, v2);
[Link]("GreaterValue:"+r1);
break;
case 2:
Smallervalue sv=new Smallervalue();
int r2=[Link](v2, v1);
[Link]("SmallerValue:"+r2);
break;
default:
[Link]("Invalid Choice......");
}
}
}

output:

Enter the value-1


5
Enter the value-2:
6
====Choice======
[Link]
[Link]
2
SmallerValue:5

Rule 11:

From java8 version onwards Interface can be declared with concrete methods.

Concrete Methods inside interface

The following are the concerete methods within the interface

a)static concrete method(java8)


b)default concrete method(java 8)
c)private concrete method(java 9)
full stack java batch-21 Page 2
c)private concrete method(java 9)

a)static concrete method(java 8)

The concrete methods which are declared in interfaces with 'static' keyword are
known as "static concrete methods".

Static concrete methods will get the memory within the interface and can accessed
with interface_name.

static concrete methods of interface are not available to implementation classes, which
means static concrete methods of interface cannot be accessed by implementation
classname.

package p1;

public interface Test {


public abstract void m1(int x);
public static void m2(int y)
{
[Link]("====Static void m2(y)=======");
[Link]("The value of y:"+y);
}
}

package p1;

public class IClass implements Test {


public void m1(int x) {
full stack java batch-21 Page 3
public void m1(int x) {
[Link]("=====m1(x)======");
[Link]("The value of x:"+x);
}
}

package p1;

public class Interfacemain2 {


public static void main(String[] args) {
IClass ob=new IClass();//Implementation object
ob.m1(11);
//IClass.m2(12);//Error
Test.m2(12);
}
}

ouput:

=====m1(x)======
The value of x:11
====Static void m2(y)=======
The value of y:12

full stack java batch-21 Page 4


15-3-2025
Saturday, March 15, 2025 8:07 PM

default concrete methods:(java8)

The concrete methods in interface which are decalared with "default" keyword are
known as default concrete methods(default concrete methods are non static methods)

Default concrete methods are available to implementation class, which means default
concrete methods will get the memory within the object of implementation classes, and
can be accessed with implementation class object name

ITest
========
package p1;

public interface ITest {


public abstract void m1(int x);
public static void m2(int y)
{
[Link]("=====Static m2(y)========");
[Link]("The value of y:"+y);

}
public default void m3(int z) {
[Link]("====default m3(z)=======");
[Link]("The value of z:"+z);
}
}

IClass
========
package p1;

public class IClass implements ITest {


public void m1(int x) {
[Link]("====m1(x)=======");
[Link]("The value of x:"+x);
}
}

main1
=========

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();

full stack java batch-21 Page 1


IClass ob=new IClass();
ob.m1(11);
ITest.m2(13);
ob.m3(13);
}
}

output:

====m1(x)=======
The value of x:11
=====Static m2(y)========
The value of y:13
====default m3(z)=======
The value of z:13

Private concrete method(java 9)


================
The concrete methods in interfaces which are declared with "private" keyword are
known as private concrete methods which are introduced by java 9 version

private concrete methods are categorized into two types

i) static private concrete methods


ii) non static private concrete methods

private concrete methods in interfaces are accessed with in the interface, which means
private concrete methods are accessed by non private concrete methods of same
interface

Itest
========
package p1;

public interface Itest {


public abstract void m1(int x);
private void dis1(int a)
{
[Link]("=====dis1(a)========");
[Link]("The value of a:"+a);
}
private static void dis2(int b) {
[Link]("====dis1(b)=======");

full stack java batch-21 Page 2


[Link]("====dis1(b)=======");
[Link]("The value of b:"+b);
}
public default void access(int a,int b) {
this.dis1(a);
Itest.dis2(b);
}
}

IClass
========
package p1;

public class IClass implements Itest {


public void m1(int x) {
[Link]("====m1(x)=======");
[Link]("The value of x:"+x);
}
}

main3
=======
package p1;

public class main3 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(11);
[Link](12,13);
}
}

====m1(x)=======
The value of x:11
=====dis1(a)========
The value of a:12
====dis1(b)=======
The value of b:13

[Link] cannot be declared with Blocks and constructors

Rule 13:

Interface can be extended from another interface, which means one interface can
have features of another interface

package p1;

public interface ITest1 {


full stack java batch-21 Page 3
public interface ITest1 {
public abstract void m1(int x);
}

package p1;

public interface ITest2 extends ITest1 {


public abstract void m2(int y);
}

package p1;

public class IClass implements ITest2 {


public void m1(int x) {
[Link]("====m1(x)=====");
[Link]("The value of x:"+x);
}
public void m2(int y) {
[Link]("====m2(y)======");
[Link]("The value of y:"+y);
}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(11);
ob.m2(12);
}
}

output:
====m1(x)=====
The value of x:11
====m2(y)======
The value of y:12

full stack java batch-21 Page 4


17-3-2025
Monday, March 17, 2025 8:17 PM

import [Link].*;
import [Link].*;

public class Solution {

public static void main(String[] args) {


/* Enter your code here. Read input from STDIN. Print output to STDOUT.
Your class should be named Solution. */
Scanner s = new Scanner([Link]);
int n = [Link]();
int sum=0;
while(n!=0){ n=234
int rem = n%10; 234!=0(True)
if(rem%2==0){ 234%10
sum = sum+ rem; rem=4
} rem%2
n =n/10; 4%2==0
} sum=sum+rem
[Link](sum); =0+4
} =4
} sum=4

n=n/10
234/10
n=23

========

step:2
23!=0
True
n=n%10
23%10
rem=3
3%2==1
rem%2!=0
n=n/10
n=23/10
n=2

=======

step 3:
n=2
n!=0
2!=0
full stack java batch-21 Page 1
step 3:
n=2
n!=0
2!=0
rem=n%10
2%10
rem=2
rem%2
sum = sum+ rem;
=4+2
=6

n=n/10
2/10

n=0

output:
6

[Link]

Multiple inheritance using interfaces


full stack java batch-21 Page 2
Multiple inheritance using interfaces

Model-1:

Extracting the features from more than one interface


into a class

package p1;

public interface ITest1 {


public abstract void m1(int x);
}

package p1;

public interface ITest2 {


public abstract void m1(int x);
}

package p1;

public class IClass implements ITest1,ITest2 {


public void m1(int x) {
[Link]("*****m1(x)*****");
[Link]("The value of x:"+x);
}
}

package p1;

full stack java batch-21 Page 3


public class main1 {
public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
}
}

full stack java batch-21 Page 4


18-3-2025
Tuesday, March 18, 2025 8:08 PM

package p1;

public interface ITest1 {


public abstract void m1(int x);
public static void m2(int y)
{
[Link]("******ITest1 static m2(y)*****");
[Link]("The value of y:"+y);
}
}

package p1;

public interface ITest2 {


public abstract void m1(int x);
public static void m2(int y)
{
[Link]("******ITest2 static m2(y)*****");
[Link]("The value of y:"+y);
}
}

package p1;

public class IClass implements ITest1,ITest2 {


public void m1(int x)
full stack java batch-21 Page 1
public void m1(int x)
{
[Link]("*****m1(x)****");
[Link]("The value of x:"+x);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
ITest1.m2(13);
ITest2.m2(14);
}
}

*****m1(x)****
The value of x:12
******ITest1 static m2(y)*****
The value of y:13
******ITest2 static m2(y)*****
The value of y:14

example:

package p1;

public interface ITest1 {


public abstract void m1(int x);
public static void m2(int y)
{
[Link]("**** ITest1 static m2(y)*****");
[Link]("The value of y:"+y);
}
public default void m3(int z) {
[Link]("*****ITest1 default m3(z)******");
[Link]("The value of z:"+z);
}
}

package p1;

full stack java batch-21 Page 2


public interface ITest2 {
public abstract void m1(int x);
public static void m3(int y)
{
[Link]("*****ITest2 static m2(y)*****");
[Link]("The value of y:"+y);
}
public default void m33(int z) {
[Link]("****ITest2 default m33(Z)*****");
[Link]("The value of z:"+z);
}
}

package p1;

public class IClass implements ITest1,ITest2 {


public void m1(int x)
{
[Link]("*****m1(x)*****");
[Link]("The value of x:"+x);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
ITest1.m2(13);
ITest2.m3(14);
ob.m3(44);
ob.m33(25);
}
}

full stack java batch-21 Page 3


19-3-2025
Wednesday, March 19, 2025 8:08 PM

Model:2

Extracting the features from one class and any number of interfaces into a class
(class extends from one class and can be implemented from any number of interfaces)

package p1;

public class PClass {


public void m1(int x) {
[Link]("****m1(x)*****");
[Link]("The value of x:"+x);
}
}

package p1;

public interface ITest {


public abstract void m2(int y);
}

package p1;

public class IClass extends PClass implements ITest {


public void m2(int y) {
[Link]("****m2(y)*****");
[Link]("The value of y:"+y);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
ob.m2(13);
}
}

full stack java batch-21 Page 1


}

****m1(x)*****
The value of x:12
****m2(y)*****
The value of y:13

package p1;
full stack java batch-21 Page 2
package p1;

public class PClass {


public void m1(int x) {
[Link]("*****m1(x)*****");
[Link]("The value of x:"+x);
}
public void dis(int k)
{
[Link]("****dis(k)******");
[Link]("****The value of k:"+k);
}
}

package p1;

public interface ITest {


public abstract void m2(int y);
public abstract void dis(int k);
}

package p1;

public class IClass extends PClass implements ITest {


public void m2(int y) {
[Link]("****m2(y)*****");
[Link]("The value of y:"+y);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
ob.m2(13);
[Link](123);
}
}

*****m1(x)*****
The value of x:12
****m2(y)*****
The value of y:13
****dis(k)******
****The value of k:123

full stack java batch-21 Page 3


****The value of k:123

Model:3

Extracting the features from more than one interface into a interface
(Interface extending from more than one interface)

package p1;

public interface Itest1 {


public abstract void m1(int x);
}

package p1;

public interface Itest2 {


public abstract void m2(int y);
}

package p1;

public interface Itest3 extends Itest1,Itest2 {


public abstract void m3(int z);
}

package p1;

public class IClass implements Itest3 {


public void m1(int x)
{
[Link]("====m1(x)=====");
[Link]("The value of x:"+x);
}
public void m2(int y)
{
[Link]("===m2(y)=====");
[Link]("The value of y:"+y);
}
public void m3(int z)
{
[Link]("===m3(z)=====");
[Link]("The value of z:"+z);
}
}

full stack java batch-21 Page 4


}

package p1;

public class main1 {


public static void main(String[] args) {
IClass ob=new IClass();
ob.m1(12);
ob.m2(13);
ob.m3(14);
}
}

====m1(x)=====
The value of x:12
===m2(y)=====
The value of y:13
===m3(z)=====
The value of z:14

full stack java batch-21 Page 5


20-3-2025
Thursday, March 20, 2025 8:07 PM

Abstract classes
------------------

The classes which are declared with "abstract" keyword are known as abstract classes

Abstract classes can be declared with both abstract methods and concerete methods

we must use "abstract" keyword to declare abstract methods in abstract classes

Abstract classes cannot be instantiated , which means we cannot create object for abstract
classes

This abstract class are extended to a class using "extends" keyword and the classes are
known as "Extended classes or Implemented classes"

package p1;

full stack java batch-21 Page 1


public abstract class AClass {
public abstract void m1(int x);
public void m2(int y) {
[Link]("===m2(y)=====");
[Link]("The value of y:"+y);
}
}

package p1;

public class EClass extends AClass {


public void m1(int x) {
[Link]("===m1(x)====");
[Link]("The value of x:"+x);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
//AClass ob=new AClass();//Error
EClass ob=new EClass();
ob.m1(12);
ob.m2(13);
}
}

===m1(x)====
The value of x:12
===m2(y)=====
The value of y:13

What is the difference between

(i) interface
(ii)Abstract class

Components in interface are automatically public, but components in abstract class are
automatically default

Blocks and constructors are not available in interfaces, but abstract classes can hold blocks
and constructors

"abstract" keyword is mandatory to declare abstract methods in interfaces, but abstract


keyword is not mandatory to declare abstract methods in abstract classes

Abstract classes can hold variables, abstract methods, concrete methods,blocks, constructors

full stack java batch-21 Page 2


What is the difference between

(a) class
(b)Abstract class

class can hold only concrete methods but abstract class can hold both abstract methods
and concrete methods

Class be instantiated , but abstract classes cannot be instantiated

full stack java batch-21 Page 3


full stack java batch-21 Page 4
21-3-2025
Friday, March 21, 2025 8:06 PM

Generalization Process:

The process in which one object created holding all the members of PClass and only
overriding members from the CClass is known as Generalization Process

The Generalization process can also be applied on interfaces and abstract class

syntax:

PClass ob=(PClass) new CClass();


ITest ob=(ITest) new IClass();
AClass ob=(AClass) new EClass();

This generalization process is also called as Upcasting Process

[Link]

package p1;
full stack java batch-21 Page 1
package p1;

public class PClass {


public void m1(int x) {
[Link]("====PClass m1(x)====");
[Link]("The value of x:"+x);
}
public void m2(int y) {
[Link]("===PClass m2(y)===");
[Link]("The value of y:"+y);
}
}

[Link]

package p1;

public class CClass extends PClass {


public void m1(int x) {
[Link]("====CClass m1(x)(overriding)======");
[Link]("The value of x:"+x);
}
public void m3(int z) {
[Link]("====CClass m3(z)====");
[Link]("The value of z:"+z);
}
}

[Link]

package p1;

public class main1 {


public static void main(String[] args) {
[Link]("=====Class Generalization======");
PClass ob1=(PClass)new CClass();
ob1.m1(12);
ob1.m2(13);
//ob1.m3(14);//Error
}
}

=====Class Generalization======
====CClass m1(x)(overriding)======
The value of x:12
===PClass m2(y)===
The value of y:13

full stack java batch-21 Page 2


full stack java batch-21 Page 3
22-3-2025
Saturday, March 22, 2025 8:15 PM

[Link]

package p1;

public class PClass {


public void m1(int x) {
[Link]("====PClass m1(x)====");
[Link]("The value of x:"+x);
}
public void m2(int y) {
[Link]("===PClass m2(y)====");
[Link]("The value of y:"+y);
}
}

[Link]

package p1;

public interface ITest {


public abstract void dis1(int a);
public default void dis2(int b)
{
[Link]("====ITest Default dis2(b)====");
[Link]("The value of b:"+b);
}
}
[Link]

package p1;

public class CClass extends PClass implements ITest {


public void m1(int x) {
[Link]("===CClass m1(x)(Overriding)====");
[Link]("The value of x:"+x);
}
public void m3(int z) {
[Link]("====CClass m3(z)====");
[Link]("==The value of x:"+z);
}
public void dis1(int a) {
[Link]("=====Implemented dis1(a)=====");
[Link]("The value of a:"+a);
}
}

full stack java batch-21 Page 1


output:

===Class Generalization====
===CClass m1(x)(Overriding)====
The value of x:12
===PClass m2(y)====
The value of y:13
=====Implemented dis1(a)=====
The value of a:23
====ITest Default dis2(b)====
The value of b:34

What is abstraction process?

The process of hiding the implementation and showing the functionality is known as
abstraction.

We perform abstraction process using interfaces and abstract classes

What is encapsulation process?

The process of binding all the programming components into a single unit is known as
encapsulation

full stack java batch-21 Page 2


what is the difference between

i) class in c++
ii) class in java

class in c++

class in c++ can hold variables and functions but cannot hold main()

class in java
class in java can hold variables,methods,blocks, constructors and main()

Innerclasses
---------------

Innerclasses in java:

The process of declaring class inside the class is known as innerclass or nested class

Innerclasses in java are categorized into two types

a) Member inner class


b) Anonymous inner class
full stack java batch-21 Page 3
b) Anonymous inner class

a)Member Inner class

The inner classes which are declared as members of a class are known as member inner
classes

These member inner classes are categorized into two types

a)Static member inner classes


b)Non static member inner classes

a)static member inner classes

The inner classes which are declared with static keyword are known as static inner
classes

i)static member inner classes can be declared with both static and non static
members.

ii) Instance methods of static member inner classes will have behaviour like static
methods and can acccess only static members of outer classes, but cannot access
instance members of outer class
iii) The static members of static member inner class can access only static members
of outer class

full stack java batch-21 Page 4


Object creation syntax of static member inner class:

outerclass_name.Innerclass_name ob=new outerclass_name.Innerclass_name();

[Link]

package p1;

public class Class1 {


public int a=1;
public static int b=20;
public void m1()
{
[Link]("***OuterClass m1()*****");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}//Outer class method
public static class SubClass1{
public int x=100;
public static int y=20;
public void m2() {
[Link]("****InnerClass m2()*****");
[Link]("The value of x:"+x);
[Link]("The value of y:"+y);
//[Link]("The value of a:"+a);//Error
[Link]("The value of b:"+b);
}
}
}

[Link]

package p1;

public class main1 {


public static void main(String[] args) {
Class1 ob1=new Class1();
ob1.m1();
Class1.SubClass1 ob2=new Class1.SubClass1();
ob2.m2();
}
}

output:

***OuterClass m1()*****

full stack java batch-21 Page 5


***OuterClass m1()*****
The value of a:1
The value of b:20
****InnerClass m2()*****
The value of x:100
The value of y:20
The value of b:20

full stack java batch-21 Page 6


24-3-2024
Monday, March 24, 2025 8:09 PM

Non static member inner classes

The member inner classes which are declared without static keyword are known as
Non static member inner classes

The non static member inner classes are categorized into two types

a)Instance member inner class


b)Local member inner class

a)Instance member inner class

The non static member inner classes which are declared outside the methods of outer
classes are known as instance member inner classes

coding rules

[Link] member inner classes can be declared with both static members and non
static members
[Link] methods of instance member inner classes can access all members of outer
class directly
[Link] methods of instance member inner classes can access only static members of
outer class

Object creation of instance member inner classes:

Outerclass_name.innerclass_name ob=Outerclass_object.new innerclass_name();

package p1;

public class Class1 {


public int a=10;
public static int b=20;
public void m1() {
[Link]("*****OuterClass m1()*****");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}//outerclass method
public class Subclass1{
public int x=100;
public static int y=200;
public void m2()
{
full stack java batch-21 Page 1
{
[Link]("*****InnerClass Instance m2()****");
[Link]("The value of x:"+x);
[Link]("The value of y:"+y);
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
public static void m22()
{
[Link]("***Innerclass static m22()******");
//[Link]("The value of x:"+x);//Error
[Link]("The value of y:"+y);
//[Link]("The value of a:"+a);//Error
[Link]("The value of b:"+b);

}
}
}

package p1;

public class main1 {


public static void main(String[] args) {
//Outerclass object
Class1 ob1=new Class1();
ob1.m1();
Class1.Subclass1 ob2=[Link] Subclass1();
ob2.m2();
Class1.Subclass1.m22();
}
}

*****OuterClass m1()*****
The value of a:10
The value of b:20
*****InnerClass Instance m2()****
The value of x:100
The value of y:200
The value of a:10
The value of b:20
***Innerclass static m22()******
The value of y:200
The value of b:20

b)Local member inner class

The process of declaring inner classes inside the method of outer classes are known as
full stack java batch-21 Page 2
The process of declaring inner classes inside the method of outer classes are known as
local member innerclasses

Local member inner classes can be declared inside both static and instance methods of
outerclasses

Local member inner classes in instance method of outerclasses are called as instance
member inner classes

Local member inner classes in static method of outer classes are called as static local
member inner classes

Coding rule:

Local member inner classes objects are created inside the method where innerclasses
are declared

full stack java batch-21 Page 3


25-3-2025
Tuesday, March 25, 2025 8:22 PM

package p1;

public class Class1 {


public int a=10;
public static int b=20;
public void m1()
{
class Subclass1
{
public void m2()
{
[Link]("****m2()");
[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
}//Instance local member inner class
Subclass1 ob2=new Subclass1();
ob2.m2();
}
public static void m11()
{
class Subclass2{
public void m22()
{
//[Link]("The value of a:"+a);
[Link]("The value of b:"+b);
}
}//static local member inner class
Subclass2 ob22=new Subclass2();
ob22.m22();
}
}

package p1;

public class main1 {


public static void main(String[] args) {
Class1 ob1=new Class1();
ob1.m1();//outerclass instance method call
Class1.m11();//outerclass static method call
}
}

full stack java batch-21 Page 1


****m2()
The value of a:10
The value of b:20
The value of b:20

Anonymous inner classes

The process of declaring the classes without name are known as


anonymous inner classes, and these anonymous classes are always
declared as Innerclasses and known as anonymous inner classes

These anonymous innerclasses are divided into two types

[Link] innerclass as class extension


[Link] innerclass as implementation class

package p1;

public class PClass {


public void m1(int x) {
[Link]("====PClass m1(x)=====");
[Link]("The value of x:"+x);
}
public void m2(int y) {
[Link]("==PClass m2(y)===");
[Link]("The value of y:"+y);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
PClass ob1=new PClass()
{
public void m1(int x)
{
[Link]("===CClass m1(x)====");
[Link]("The value of x:"+x);
}

full stack java batch-21 Page 2


}
public void m3(int z) {
[Link]("==CClass m3(z)====");
[Link]("The value of z:"+z);
}
};
ob1.m1(12);
ob1.m2(13);
//ob1.m3(14);
}

===CClass m1(x)====
The value of x:12
==PClass m2(y)===
The value of y:13

package p1;

public interface ITest {


public abstract void dis1(int a);
public default void dis2(int b) {
[Link]("The value of b:"+b);
}
}

package p1;

public class main1 {


public static void main(String[] args) {
ITest ob2=new ITest()

{
public void dis1(int a)
{
[Link]("===dis1(a)====");
[Link]("The value of a:"+a);
}
};
ob2.dis1(23);
ob2.dis2(45);
}
}

full stack java batch-21 Page 3


=dis1(a)====
The value of a:23
The value of b:45

Define lambda expression?(java8-new feature)

The process of declaring method without name is known as lambda


expression and which is also known as anonymous method

Syntax of lambda expression:

(para_list)->
{
method_body
}

full stack java batch-21 Page 4


26-3-2025
Wednesday, March 26, 2025 8:07 PM

Define lambda expression?(java8-new feature)

The process of declaring method without name is known as lambda


expression and which is also known as anonymous method

Syntax of lambda expression:

(para_list)->
{
method_body
}

Note:

The interface abstract method is attached with lambdaexpression and


we execute lambda expression with abstract method

syntax:

interface Iarithmetic
{
public abstract void calculate(int x, int y);
}

Iarthimetic ob=(int x,int y)-->


{
//method body
};

Rule:1

Lambda expression cannot acccess variable from the interface


directly, we have to access with interface_name;

Rule 2:

The interface which is providing abstract method to hold lambda


expression must be declared with only one abstract method

full stack java batch-21 Page 1


what is the difference between
a) Normal Interface
b) Functional Interface

Normal Interface:

The interface which can be declared with more number of abstract


methods is known as normal interface

Functional interface

The interface which is declared with single abstract method is


known as functional interface

package p1;

public class main1 {


public static void main(String[] args) {
IArthimetic ob=(int x, int y)->
{
[Link]("===Calculate(x,y)====");
[Link]("Sum:"+(x+y));
[Link]("The value of z:"+IArthimetic.z);
};
[Link](12, 13);
[Link](123);
}
}

package p1;

public interface IArthimetic {


public int z=300;
public abstract void calculate(int x,int y);
public default void dis(int k) {
[Link]("===default dis(k)===");
[Link]("The value of k:"+k);
[Link]("The value of z:"+z);

}
}

full stack java batch-21 Page 2


===Calculate(x,y)====
Sum:25
The value of z:300
===default dis(k)===
The value of k:123
The value of z:300

Innerclasses inside interface

we can declare inner classes inside the interface and are


automatically static member inner classes

package p1;

public interface ITest {


public static class Subclass1{
public void m1(int x)
{
[Link]("****ITest innerclass m1(x)****");
[Link]("The value of x:"+x);
}
}//static member innerclass
}//outer Interface

package p1;

public class main1 {


public static void main(String[] args) {
ITest.Subclass1 ob1=new ITest.Subclass1();
ob1.m1(12);
}
}

output:

****ITest innerclass m1(x)****


The value of x:12

Exception Handling in java:


full stack java batch-21 Page 3
Exception Handling in java:

Define exception?

The disturbance which is occurred from the application is known as


exception

Define exception handling process?

The process which is used to handle the exception is known as


exception handling process

The following blocks are used in exception handling process

[Link]
[Link]
[Link]

[Link]

"try block will hold the statements which are going to raise
the exception

try
{

//statements
}

[Link]

"Catch block will hold the value thrown from the try block and
the required msg is generated if the value received from the
try block is not within the input range

package p1;

import [Link].*;

public class Exception1 {


full stack java batch-21 Page 4
public class Exception1 {
public static void main(String[] args) {
Scanner s=new Scanner([Link]);
try {
[Link]("Enter the BasicSal:");
int bSal=[Link]();//Exception of Non-integer Input
int totSal=bSal+12*bSal;
[Link]("BasicSal:"+bSal);
[Link]("TotSal:"+totSal);
}//end of try
catch(InputMismatchException ob)
{
[Link]("Enter only Integer Basic Sal...");
}
}
}

output:

Enter the BasicSal:


12000
BasicSal:12000
TotSal:156000

full stack java batch-21 Page 5


27-3-2025
Thursday, March 27, 2025 8:09 PM

Execution behaviour of try block:

When an exception is raised in try block one object is created for


Exception_type_class its reference is thrown on to the memory of [Link] reference
is then caught by the appropriate catch block for handling

[Link]

"catch" block will hold the value thrown from the try block and then required msg
is generated if the value received from try block is not within the input range

User defined exception

step 1: The user defined class must be extended from predefined Exception class

step 2: The userdefined class must be declared with parameterized constructor with
string as parameter

step3: This parameterized constructor will take the message while object creation
and pass the message to the pclass

step 4: use try block to hold program statements


full stack java batch-21 Page 1
step 4: use try block to hold program statements

step 5: declare the condition to raise exception

step 6: If the condition is true, then create object for userdefined class and while
object creation pass exception msg as parameter

step 7: use "throw" keyword to throw the object reference onto catch block

Program:

package p1;
import [Link].*;
public class Exception1 extends Exception {
public Exception1(String msg)
{
super(msg);
}
public static void main(String[] args) {
Scanner s=new Scanner([Link]);
try
{
[Link]("Enter the BasicSal:");
int bSal=[Link](); //Exception
if(bSal<12000)
{
Exception1 ob=new Exception1("Invalid Bsal");
throw ob;
}
int totSal=bSal+12*bSal;
[Link]("BasicSal:"+bSal);
[Link]("TotSal:"+totSal);
}//end of try
catch(Exception1 ob)
{
[Link]([Link]());
}
catch(InputMismatchException ob) {
[Link]("Enter only Integer BasicSal....");
}
finally
{
[Link]();
}
}
}

output:
full stack java batch-21 Page 2
output:
Enter the BasicSal:
11000
Invalid Bsal

full stack java batch-21 Page 3


28-3-2025
Friday, March 28, 2025 8:11 PM

Faq:

what is the difference between

[Link]()
[Link]()
[Link]()

getMessage():

getMessage() method is used to display only exception message from the object

toString()

toString() is used to display exception-msg with the class name from where the
exception is raised

printStackTrace()

printStackTrace() will display the complete details of exception like


class_name,exception message and line_no

package p1;
import [Link].*;
public class Exception1 extends Exception {
public Exception1(String msg)
{
super(msg);
}
public static void main(String[] args) {
Scanner s=new Scanner([Link]);
try
{
[Link]("Enter the BasicSal:");
int bSal=[Link](); //Exception
if(bSal<12000)
{
Exception1 ob=new Exception1("Invalid Bsal");
throw ob;
}
full stack java batch-21 Page 1
}
int totSal=bSal+12*bSal;
[Link]("BasicSal:"+bSal);
[Link]("TotSal:"+totSal);
}//end of try
catch(Exception1 ob)
{
//[Link]([Link]());
//[Link]([Link]());
[Link]();
}
catch(InputMismatchException ob) {
[Link]("Enter only Integer BasicSal....");
}
finally
{
[Link]();
}
}
}

ouput:

Enter the BasicSal:


11000
p1.Exception1: Invalid Bsal
at exception5/[Link]([Link])

Write a program to validate student rollNo

Read RollNo
==>rollno must be length 10 digits, else we should raise exception

Program:

package p1;

import [Link];

public class ExceptionMain extends Exception {


public ExceptionMain(String msg)
{
super(msg);
}
public static void main(String[] args) {
Scanner s=new Scanner([Link]);
try {
full stack java batch-21 Page 2
try {
[Link]("Enter the Roll no:");
String rollno=[Link]();
if([Link]()!=10)//Exception Condition
{
ExceptionMain ob=new ExceptionMain("Invalid RollNo...");
throw ob;
}
[Link]("RollNo:"+rollno);
}//end of try
catch(ExceptionMain ob)
{
[Link]([Link]());
}
}
}

output:
Enter the Roll no:
1234567890
RollNo:1234567890

The exceptions raised from the applications are categorized into two types

a)unchecked exception
b)checked exception

unchecked exception:

The exceptions which are not identified by the compiler at compilation stage
will be raised at execution stage are known as unchecked exceptions or runtime
exceptions

checked exceptions

The exceptions which are identified by the compiler at compilation stage are known as
checked exceptions

forName() method

forName() method is used to load the class at runtime or execution time


forName() method is available inside [Link]

Note:
full stack java batch-21 Page 3
Note:

"new" keyword cannot create object for classes loaded at runtime which means
"new" keyword will create object for the classes loaded at compilation stage

we will use "newInstance() method to create objects for classes loaded at runtime.

[Link]

package p1;

public class Display {


public void dis(int k) {
[Link]("==dis(k)====");
[Link]("The value of k:"+k);
}
}

[Link]

package p2;

public class Exception1 {


public static void main(String[] args) {
try {
Class c=[Link]("[Link]");
[Link] ob=([Link])[Link]();
[Link](123);
}
catch(ClassNotFoundException ob) {
[Link]();
}
catch(InstantiationException ob1) {
[Link]();
}
catch(IllegalAccessException ob2) {
[Link]();
}
}
}

output:

==dis(k)====

full stack java batch-21 Page 4


==dis(k)====
The value of k:123

full stack java batch-21 Page 5


29-3-2025
Saturday, March 29, 2025 8:10 PM

Challenge-9

Lisa always forgets her birthday which is on th 5th July. So develop a function/method
which will be helpful to remember her birthday. The function/method checkBirthday return
an integer 1, if it is her birthday else return 0. the function/method checkBirthday accepts
two [Link], a string representing the month of her birth and day, an integer
representing the data of her birthday.

program:

import [Link].*;
import [Link].*;

public class Solution {

public static void main(String[] args) {


/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class
should be named Solution. */
Scanner s=new Scanner([Link]);
String s1=[Link]();
int n=[Link]();
if(n==5 && [Link]("july")){
[Link]("1");
}else{
[Link]("0");
}

}
}

full stack java batch-21 Page 1


throws keyword:

"throws" keyword is added with method signature and ignore exception in


current method and raise at method call.

package p2;

public class Exception1 {


public static void main(String[] args) throws
ClassNotFoundException,InstantiationException,IllegalAccessException
{
Class c=[Link]("[Link]");
[Link] ob=([Link])[Link]();
[Link](123);
}

throw keyword

throw keyword is used to throw the object reference onto catch block in the
process of handling exception.

faq:

What is the difference between


(i)import statement
(ii)forName() method
full stack java batch-21 Page 2
import statement

"import statement" will make the class available at compilation stage

forName() method:

forName() is used to load the class at runtime or execution time.

full stack java batch-21 Page 3


1-4-2025
Tuesday, April 1, 2025 8:45 PM

products = {"Laptop", "Mobile", "Headphones", "Tablet"};

stock = {5, 10, 15, 8};

cart = {0, 0, 0, 0}

prices = {50000, 20000, 3000, 15000}

public void displayProducts() {


[Link]("\nAvailable Products:");
for (int i = 0; i < [Link]; i++) {
[Link]((i + 1) + ". " + products[i] + " - ₹" + prices[i] + " - Stock: " + stock[i]);
}
}

[Link] - ₹5000 -Stock:5


[Link] - ₹2000 -Stock:10

[Link]();
[Link]("Enter product number: ");
1
int productIndex = [Link]() - 1;
productIndex=1-1
productIndex=0
[Link]("Enter quantity: ");
Enter quantity:1
int quantity = [Link]();
quantity=1
[Link](productIndex, quantity);
break;

full stack java batch-21 Page 1


1-4-2025
Tuesday, April 1, 2025 8:45 PM

products = {"Laptop", "Mobile", "Headphones", "Tablet"};

stock = {5, 10, 15, 8};

cart = {0, 0, 0, 0}

prices = {50000, 20000, 3000, 15000}

public void displayProducts() {


[Link]("\nAvailable Products:");
for (int i = 0; i < [Link]; i++) {
[Link]((i + 1) + ". " + products[i] + " - ₹" + prices[i] + " - Stock: " + stock[i]);
}
}

[Link] - ₹5000 -Stock:5


[Link] - ₹2000 -Stock:10

[Link]();
[Link]("Enter product number: ");
1
int productIndex = [Link]() - 1;
productIndex=1-1
productIndex=0
[Link]("Enter quantity: ");
Enter quantity:1
int quantity = [Link]();
quantity=1
[Link](productIndex, quantity);

"Only " + stock[productIndex] + " " + products[productIndex] + "(s) left."

Only+stock[0]+" "+products[0]+(s) left


only 5 Laptop(s) left

cart[productIndex] += quantity;
stock[productIndex] -= quantity;

cart[productIndex] += quantity;
cart[0]+=1
cart[0]=cart[0]+1
cart[0]=0+1
cart[0]=1

cart={1,0,0,0}

stock[productIndex] -= quantity;
stock[productIndex]=stock[productIndex]-quantity;
stock[0]=stock[0]-quantity
stock[0]=5-1
stock[0]=4
stock = {4, 10, 15, 8};

full stack java batch-21 Page 1


[Link](quantity + " " + products[productIndex] + "(s) added to cart.");
1 Laptop(s) added to cart

[Link] from the cart


====================
[Link]("Enter product number to remove: ");
int removeIndex = [Link]() - 1;
[Link]("Enter quantity to remove: ");
int removeQuantity = [Link]();

[Link](removeIndex, removeQuantity);
break;

cart[productIndex] -= quantity;
stock[productIndex] += quantity;

cart[productIndex] -= quantity;
cart[productIndex]=cart[productIndex]-quantity
cart[0]=cart[0]-1
cart[0]=1-1
cart[0]=0

cart={0,0,0,0}

stock = {4, 10, 15, 8};


stock[productIndex] += quantity;
stock[0]=stock[productIndex]+quantity
stock[0]=stock[0]+1
stock[0]=4+1
stock[0]=5

stock = {5, 10, 15, 8};

[Link](quantity + " " + products[productIndex] + "(s) removed from cart.");

1 Laptop(s) removed from the cart

public double calculateTotal() {


double total = 0;
for (int i = 0; i < [Link]; i++) {
total += cart[i] * prices[i];
}
return total;
}

cart={1,0,0,0}

full stack java batch-21 Page 2


total += cart[i] * prices[i];
total=total+cart[i]*prices[i]
total=total+cart[0]*prices[0]
=0+1*50000
=50000

full stack java batch-21 Page 3


3-4-2025
Thursday, April 3, 2025 8:07 PM

explain the difference between final keyword, finally block, finalize() ?

finally keyword in java

The finally block in java is used to executed important code regardless of whether an
exception occurs or not.

class FinallyExample
{
public static void main(String[] args){
int result=10/0;
[Link]("Hai");
}
}

output:
D:\>
D:\>java FinallyExample
Exception in thread "main" [Link]: / by zero
at [Link]([Link])

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

int result=10/0;
}finally{
[Link]("Hai");
}
}
}

example:

class FinallyExample
{
full stack java batch-21 Page 1
{
public static void main(String[] args){
try{

int result=10/0;
}
catch(ArithmeticException ob){
[Link]("cannot divide by zero");
}
finally{
[Link]("Hai");
}
}
}

D:\>java FinallyExample
cannot divide by zero
Hai

finalize()

Garbage collection in java

Grabage collection(GC) in java is the process of automatically reclaiming memory by


removing objects that are no longer reachable or used by the program. It helps in
efficient memory management

How garabage collection works

1. Automatic process: java uses an automatic garabage collector to identify and


remove unused objects
2. Grabage collector(GC) Execution: The GC runs in the background, we can request
it using [Link]()

class FinalizeExample{
public void finalize(){
[Link]("Garbage collector has remove an object:");
}
public static void main(String[] args){
full stack java batch-21 Page 2
public static void main(String[] args){
FinalizeExample ob1=new FinalizeExample();
ob1=null;
[Link]();
}
}

class FinalizeExample{
public void finalize(){
[Link]("Garbage collector has remove an object:");
}
public static void main(String[] args){
FinalizeExample ob1=new FinalizeExample();
FinalizeExample ob2=new FinalizeExample();
ob1=null;
ob2=null;
[Link]();
}
}

D:\>java FinalizeExample
Garbage collector has remove an object:

D:\>javac [Link]
[Link]: warning: [removal] finalize() in Object has been deprecated and
marked for removal
public void finalize(){
^
1 warning

D:\>java FinalizeExample
Garbage collector has remove an object:

D:\>javac [Link]
[Link]: warning: [removal] finalize() in Object has been deprecated and
marked for removal
public void finalize(){
^
1 warning

full stack java batch-21 Page 3


D:\>java FinalizeExample
Garbage collector has remove an object:
Garbage collector has remove an object:

D:\>

finalize()

The finalize() method is used for garbage collection before an object is destroyed

It is called by the garbage collector (GC) when an object is no longer in use.

full stack java batch-21 Page 4


4-4-2025
Friday, April 4, 2025 8:08 PM

Final Variables(Constants)

When a variable is declared as final, its value cannot be changed after initialization
It must be initialized at the time of declaration

class Example{
final int max_speed=120;
void display(){
max_speed=150;
[Link]("max speed:"+max_speed);
}
}

D:\>javac [Link]
[Link]: error: cannot assign a value to final variable max_speed
max_speed=150;
^
1 error

Final Methods(Prevents Overriding)

A method declared as final cannot be overridden in a subclass

class Parent{
final void show(){
[Link]("This is a final method.");
}
}
class Child extends Parent{
void show(){
[Link]("Child class method.");
}
}

output:
D:\>javac [Link]
[Link]: error: show() in Child cannot override show() in Parent
void show(){
full stack java batch-21 Page 1
void show(){
^
overridden method is final
1 error

Final Classes(Prevent Inheritance)

A class declared as final cannot be inherited by another class

final class Vehicle{


void run(){
[Link]("Vehicle is running");
}
}

class Car extend Vehicle{


void display(){
[Link]("Car is running");
}
}

output:
D:\>javac [Link]
[Link]: error: cannot inherit from final Vehicle
class Car extends Vehicle{
^
1 error

Hierarchy of exception Handling:

Exception class is a parent class in java

It can handle both checked exceptions and unchecked [Link] class is


The root class of all exceptions and errors in java Programming

full stack java batch-21 Page 2


CheckedExceptions

[Link]
[Link]
[Link]
[Link]
[Link]

Unchecked Exceptions

[Link]
[Link]
[Link] BoundsException
[Link]

ClassNotFoundException

class ExceptionExample{
public static void main(String[] args){
try{
[Link]("abc");
[Link]("Class loaded Successfully!");
}catch(ClassNotFoundException e){
[Link]("Class Not Found");
}
}
}

output:

D:\>javac [Link]

D:\>java ExceptionExample
Class Not Found

InstantiationException
================
abstract class Vehicle{
abstract void start();
}
full stack java batch-21 Page 3
}

class exceptionexample{
public static void main(String[] args)
{
try{
Vehicle obj=[Link]();
}catch(InstantiationException e)
{
[Link]("Error:Cannot Instantiate an abstract class");
}catch(IllegalAccessException e){

[Link]("Illegal access error");


}
}
}

output:
1 error

D:\>javac [Link]
Note: [Link] uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

D:\>java exceptionexample
Error:Cannot Instantiate an abstract class

Define [Link] exception?

[Link] is raised when we perform operations on


Nonprimitive datatype variables holding null values

class Exception1{
public static String str;
public static void main(String[] args){
[Link]("Value of str:"+str);
int len=[Link]();
[Link]("length of str"+len);
}
}

full stack java batch-21 Page 4


ouput:

D:\>java Exception1
Value of str:null
Exception in thread "main" [Link]: Cannot invoke
"[Link]()" because "[Link]" is null
at [Link]([Link])

full stack java batch-21 Page 5


5-4-2025
Saturday, April 5, 2025 8:06 PM

Arthmetic Exception,ArrayIndexOutOfBoundsException
=========================================

class Exception1{
public static void main(String[] args){
try{
int a=10,b=0,c;
c=a/b;
[Link](c)
}
catch(ArithmeticException a)
{
[Link]("cannot divide by zero");
}
try
{
int a[]={10,20,30,40};
[Link](a[5]);
}
catch(ArrayIndexOutOfBoundsException b);
{
[Link]("Beyond the array limit");
}
}
}

output:
D:\>java Exception1
cannot divide by zero
Beyond the array limit

NoSuchElementsException

class Exception1{
public static void main(String[] args){
Scanner s=new Scanner("");//Empty input source
try{
[Link]("Enter a number:")
int number=[Link]();
full stack java batch-21 Page 1
int number=[Link]();
[Link]("you entered:" + number);
}catch (NoSuchElementException e){
[Link]("No input available to read");
}
}
}

D:\>javac [Link]

D:\>java Exception1
Enter a number:
No input available to read

[Link]
multithreading
[Link]
[Link]
[Link]

oracle
ui

advance java

4capstone

linkedin optimization
github customization
portfolio website
resume preparation

polymorphism

The ability to appear in more forms is called as polymorphism . In polymorphism one


thing can exhibits in more than one form
polymorphism is a greek word poly means many and morphism means forms

full stack java batch-21 Page 2


Method Overloading

Two methods are said to be overloaded methods if and only if two methods are having
same name but differen argument list.

we can overload the methods in two ways


[Link] the different number of arguments to the same methods
[Link] the same number of arguments with different data types

if we want to overload one class is enough


It is possible to overload any number of methods

Types of overloading

[Link] overloading
[Link] overloading
[Link] overloading

Method Overloading
=============
class Overloading
{
void m1(char ch)
{
[Link]("Char-arg method");
}
void m1(int i)
{
[Link]("int-arg method");
full stack java batch-21 Page 3
[Link]("int-arg method");
}
void m1(int i, int j){
[Link]("2 arg int method");
}
void m1()
{
[Link]("hello");
}
public static void main(String [] args)
{
Overloading ob=new Overloading1();
ob.m1('a');
ob.m1(10);
ob.m1(10,20);
ob.m1();

}
}

output:
D:\>java Overloading
Char-arg method
int-arg method
2 arg int method
hello

Constructor overloading

The constructors are having same name but different arguments list such type of
constructors are called as overloaded constructors

class Main1
{
Main1()
{
[Link]("0-arg constructor");
}
Main1(int i)
{
[Link]("1-arg constructor");
full stack java batch-21 Page 4
[Link]("1-arg constructor");
}
Main1(char ch,int i)
{
System .[Link] ("Constructor with different data types");
}
public static void main(String[] args){
Main1 ob1=new Main1();//calling of zero argument constructor
Main1 ob2=new Main1(10);//calling of one argument constructor
Main1 ob3=new Main1('a',100);//calling of two argument constructor
}
}

output:
D:\>java Main1
0-arg constructor Tomorrow there is a class
1-arg constructor Monday there is no class
Constructor with different data types

full stack java batch-21 Page 5


6-4-2025
Sunday, April 6, 2025 8:08 PM

2444
4
output:
3

import [Link].*;
import [Link].*;

public class Solution {

public static void main(String[] args) {


Scanner s=new Scanner([Link]); n=2444
int n=[Link](); d=4
int d=[Link](); 2444>0(True)
int rem=0; rem=n%10
int count=0;
while(n>0){
rem=n%10;
if(d==rem){
count++;
}
n=n/10;
}
[Link](count);
}
}

full stack java batch-21 Page 1


Operator overloading:

one operator can act as more than one form is called as operator overloading. The only one
operator overloaded in java is '+'

class Operator
{
public static void main(String[] args)
full stack java batch-21 Page 2
public static void main(String[] args)
{
String str1="java";
String str2="Programming";
[Link](str1);
[Link](str2);
[Link](str1+str2);
int a=10;
int b=20;
[Link](a);
[Link](b);
[Link](a+b);

}
}

output:
D:\>java Operator
java
Programming
javaProgramming
10
20
30

Runtime polymorphism

Method overriding

If same methods with same name are present both in parent class and child class then parent
class method is overrided by child class method

In overriding concept the child class and parent class method signatures must be same
otherwise we will get compilation error

The parent class method is called-->overridden method


The child class method is called-->overriding method

If we want to achieve method overriding we need two classes(parent and child)

[Link]

class PClass
{
void m1()
{
full stack java batch-21 Page 3
{
[Link]("I am learning python programming");
}
void m2()
{
[Link]("I am learning ui programming");
}
}

class CClass extends PClass{


void m1()
{
super.m1();
[Link]("I am learning java programming");
}
public static void main(String[] args){
CClass ob1=new CClass();
ob1.m1(); Tomorrow there is no class
ob1.m2();
next class is on tuesday
}
}

output:

I am learning python programming


I am learning java programming
I am learning ui proramming

Multithreading

Thread is a separate path sequential execution


The independent execution of a program is called as thread
Thread is light weight process
Execution of more than one thread at a time is called as multithreading
Multithreading is used in designing of games

There are two different ways to create thread concept

[Link] a class that extending standard and default [Link] class


[Link] a class that implementing [Link] Interface

full stack java batch-21 Page 4


8-4-2025
Tuesday, April 8, 2025 8:13 PM

[Link] a class that extending standard and default [Link] class

Execution of Thread Program:

1) Whenever we are calling [Link]() method, the jvm search for the start() in the child
class but the start() is not present in the child class so jvm goes to the parent class
and will call Thread class and search for start() method
2) In the Thread class start() method is available hence jvm is executing start()
method
3) Whenever the thread class start() method is executed , it is responsible to register
the child class inside the Thread Scheduler and the start() will call the run()
4) Finally the run() automatically executed whenever we are calling start()
5) wheneve we are giving a chance to the thread class start() then only a new thread
will be created

class MyThread extends Thread


{
public void run()
{
for(int i=0;i<10;i++)
{
[Link]("User defined Thread");
}
}
class ThreadProgram
{
public static void main(String[] args)
{
MyThread ob=new MyThread();
[Link]();
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
}
}

full stack java batch-21 Page 1


D:\>java Threadprogram
main Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread

D:\>java Threadprogram
main Thread
main Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
main Thread
main Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
main Thread
main Thread
full stack java batch-21 Page 2
main Thread
User defined Thread
User defined Thread

D:\>java Threadprogram
main Thread
main Thread
main Thread
main Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
main Thread
main Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread

D:\>java Threadprogram
main Thread
main Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
main Thread
main Thread
User defined Thread
main Thread
main Thread
main Thread
full stack java batch-21 Page 3
main Thread
main Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread

D:\>java Threadprogram
main Thread
main Thread
main Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
User defined Thread

D:\>javac [Link]

D:\>java Threadprogram
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
full stack java batch-21 Page 4
User defined Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread

class MyThread extends Thread


{
public void start()
{
for(int i=0;i<10;i++)
{
[Link]("User defined Thread");
}
}
class ThreadProgram
{
public static void main(String[] args)
{
MyThread ob=new MyThread();
[Link]();
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
}
}
}

output:

D:\>java Threadprogram
User defined Thread
User defined Thread
User defined Thread
full stack java batch-21 Page 5
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread

class MyThread extends Thread


{
public void run()
{
for(int i=0;i<10;i++)
{
[Link]("User defined Thread");
}
invigilator
}
class ThreadProgram
{
class
public static void main(String[] args)
{
MyThread ob=new MyThread();
[Link]();
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
}
}
}
full stack java batch-21 Page 6
}

D:\>java Threadprogram
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
main Thread
User defined Thread
User defined Thread

full stack java batch-21 Page 7


full stack java batch-21 Page 8
9-4-2025
Wednesday, April 9, 2025 8:07 PM

Thread life cycle:

Life cycle stages are

1)New
2)Ready
3)Running State
4)Blocked state/Wating state/non-running state
5)Dead state

New state

MyThread ob=new MyThread();

Ready state

[Link]()

Running state

If the thread scheduler allocate cpu memory for particular thread, then Thread goes
to running state.

Blocked state

If the running thread goes to the sleeping state then the thread is said to be in
blocked state

Dead state

If the logic execution of a thread program is completed , that means the execution of
run() is completed then our thread program reaches to a dead state

Thread methods

getName()

The getName() is used to get the Name of the thread


full stack java batch-21 Page 1
The getName() is used to get the Name of the thread

class MyThread extends Thread


{
public void run()
{
[Link]("User defined Thread");
}
}

class Threadprogram1
{
public static void main(String[] args)
{
MyThread t=new MyThread();
[Link]();
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
[Link]([Link]());
}
}

output

D:\>java Threadprogram1
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
User defined Thread
main Thread
main Thread
main Thread
main Thread
Thread-0

setName()

The setName() is used to change the name of the thread inside the Thread scheduler
full stack java batch-21 Page 2
The setName() is used to change the name of the thread inside the Thread scheduler

Example

class MyThread extends Thread


{
public void run()
{
[Link]("User defined Thread");
}
}

class Threadprogram1
{
public static void main(String[] args)
{
MyThread t=new MyThread();
[Link]();
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
[Link]("codingbrains")
[Link]([Link]());
}
}

output:
D:\>java Threadprogram1
main Thread
main Thread
User defined Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
main Thread
codingbrains

full stack java batch-21 Page 3


setPriority()

Every Thread in java has some priority. it may be default priority by JVM or we
can provide customized priority

The valid range of thread priority is 1-10 where 1 is the lowest priority and 10 is the
highest priority

class MyThread extends Thread


{
public void run()
{
for(int i=0;i<=10;i++)
{
[Link]("User defined Thread");
}
}
}

class Threadprogram1
{
public static void main(String[] args)
{
MyThread t=new MyThread();
[Link]();
[Link](10);
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
}
}

class MyThread extends Thread


{
public void run()
{
for(int i=0;i<=10;i++)
{
[Link]("User defined Thread");
full stack java batch-21 Page 4
[Link]("User defined Thread");
}
}
}

class Threadprogram1
{
public static void main(String[] args)
{
MyThread t=new MyThread();
[Link]();
[Link](5);
for(int i=0;i<10;i++)
{
[Link]("main Thread");
}
}
}

activeCount()

The activeCount() method of Thread class is used to return the number of active
threads of the current thread group.

class MyThread extends Thread


{
public void run()
{
for(int i=0;i<=10;i++)
{
[Link]("User defined Thread");
}
}
}

class Threadprogram1
{
public static void main(String[] args)
{
MyThread t=new MyThread();
[Link]();
[Link]([Link]());
}
full stack java batch-21 Page 5
}
}

output:
D:\>java Threadprogram1
2
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread

sleep():

The sleep() method causes the current Thread to sleep for a specified amount of time
in milliseconds

class Thread1 extends Thread


{
public void run()
{
for(int i=0;i<10;i++)
{
try
{
[Link](3000);
[Link]("user defined Thread");
}
catch(InterruptedException e)
{
[Link]("Exception found")
}
}
}
}
class ThreadMain
{
full stack java batch-21 Page 6
{
public static void main(String[] args)
{
Thread t1=new Thread1();
[Link]();
}
}

class Thread1 extends Thread


{
public void run()
{
for(int i=0;i<10;i++)
{

[Link](3000);
[Link]("user defined Thread");
}
}
}

class ThreadMain
{
public static void main(String[] args)
{
Thread t1=new Thread1();
[Link]();
}
}

D:\>javac [Link]
[Link]: error: unreported exception InterruptedException; must be caught
or declared to be thrown
[Link](3000);
^
1 error

join()

full stack java batch-21 Page 7


If a thread want to wait until the completing of some other thread we should go for
join method

class Thread1 extends Thread


{
public void run()
{
for(int i=0;i<5;i++)
{
try
{
[Link](3000);
[Link]("hi");
}
catch(InterruptedException e)
{
[Link]("Exception Found");
}
}
}
}

class Thread2 extends Thread


{
public void run()
{
for(int i=0;i<5;i++)
{
try
{
[Link](3000);
[Link]("hello");
}
catch(InterruptedException e)
{
[Link]("Exception Found");
}
}
}
}
class ThreadMain
full stack java batch-21 Page 8
class ThreadMain
{
public static void main(String[] args)
{
Thread1 t1=new Thread1();
Thread2 t2=new Thread1();
[Link]();
[Link]();
[Link]();
}
}

activecount()
Interface
Files
enum
collections
oracle
ui

full stack java batch-21 Page 9


10-4-2025
Thursday, April 10, 2025 8:12 PM

isAlive():

This method checks whether the Thread is present in the Thread Scheduler or not and
returns the boolean value as output

class Thread1 extends Thread


{
public void run()
{
for(int i=0;i<10;i++)
{
[Link]("User defined Thread");
}
}
}

class ThreadMain
{
public static void main(String[] args)
{
Thread1 t1=new Thread1();
[Link]();
[Link]([Link]());
}
}

output:
D:\>java ThreadMain
true
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
full stack java batch-21 Page 1
User defined Thread

creating a class that implementing [Link] Interface

class MyThread implements Runnable{

public void run()


{
for(int i=0;i<10;i++)
{
[Link]("User defined Thread");
}
}
class ThreadProgram{
public static void main(String[] args){
MyThread ob=new MyThread();
Thread thread=new Thread(ob);
[Link]();
for(int i=0;i<10;i++){
[Link]("main thread")
}
}
}

D:\>javac [Link]
[Link]: error: ';' expected
[Link]("main thread")
^
[Link]: error: reached end of file while parsing
}
^
2 errors

D:\>javac [Link]
[Link]: error: reached end of file while parsing
}
^
1 error

D:\>javac [Link]

full stack java batch-21 Page 2


D:\>java ThreadProgram
main thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
User defined Thread

D:\>java ThreadProgram
main thread
main thread
User defined Thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
User defined Thread
main thread
User defined Thread
User defined Thread
User defined Thread
main thread
main thread
User defined Thread
main thread
full stack java batch-21 Page 3
main thread
main thread

D:\>java ThreadProgram
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
main thread
User defined Thread
User defined Thread
User defined Thread
main thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread

D:\>java ThreadProgram
main thread
main thread
main thread
main thread
main thread
main thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
main thread
User defined Thread
User defined Thread
User defined Thread
User defined Thread
full stack java batch-21 Page 4
User defined Thread
User defined Thread
User defined Thread
User defined Thread

D:\>

File Handling in Java: File


File()
In java, file handling definition usually refers to how we work with files- [Link]
defining,creating, reading, writing or manipulating them using classes from
[Link] package

In java,the method createNewFile() is used to create a new,empty file .

package p1;

import [Link];
import [Link];

public class File1 {


public static void main(String[] args) throws IOException{
File f=new File("D:/TestFiles1/[Link]");
[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];

public class File1 {


public static void main(String[] args) throws IOException{
File f=new File("D:/TestFiles1/[Link]");
//[Link]([Link]());
[Link]([Link]());
}
}

package p1;
full stack java batch-21 Page 5
package p1;

import [Link];
import [Link];
isHidden()
public class File1 {
public static void main(String[] args) throws IOException{
File f=new File("D:/TestFiles1/[Link]");
if([Link]());
[Link]();
[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];

public class File1 {


public static void main(String[] args) throws IOException{
File f=new File("D:/TestFiles1/[Link]");
//if([Link]());
//[Link]();
[Link]([Link]());
}
}

full stack java batch-21 Page 6


11-4-2025
Friday, April 11, 2025 8:17 PM

package p1;

import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("D:/TestFiles3/[Link]");
//[Link]([Link]());
[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("D:/TestFiles3/[Link]");
//[Link]([Link]());
[Link](true);
[Link]([Link]());
}
}

full stack java batch-21 Page 1


package p1;

import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("./[Link]");
[Link]([Link]());
//[Link](true);
//[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("./Resources/");
[Link]([Link]());
//[Link](true);
//[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];

full stack java batch-21 Page 2


import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("./Resources/Test");
[Link]([Link]());
//[Link](true);
//[Link]([Link]());
}
}

package p1;

import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("D:\\java batch-21 eclipse\\filehandling3");
[Link]([Link]([Link]()));
//[Link](true);
//[Link]([Link]());
}
}

output:

[.classpath, .project, .settings, bin, Resources, [Link], src]

toString: Returns the name of the file or folder as string

getName()

full stack java batch-21 Page 3


It returns the last part of the path

package p1;

import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("D:\\java batch-21 eclipse\\filehandling3");
[Link]([Link]());
//[Link](true);
//[Link]([Link]());
}
}

To read the data inside the file

[Link]
[Link]
[Link]
[Link]

package p1;

import [Link];
import [Link];
full stack java batch-21 Page 4
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException {
File f=new File("./[Link]");
FileInputStream fis=new FileInputStream(f);
int asciicode;
while((asciicode=[Link]())!=-1) {
[Link]((char)asciicode);
}
}
}

full stack java batch-21 Page 5


12-4-2025
Saturday, April 12, 2025 8:15 PM

package p1;

import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
Scanner s=new Scanner(file);
while([Link]())
{
[Link]([Link]());
}
}
}

package p1;

import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
FileReader fr=new FileReader(file);
int asciicode;
while((asciicode=[Link]())!=-1) {
[Link]((char)asciicode);
}
full stack java batch-21 Page 1
}
}
}

package p1;

import [Link];
import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
FileReader fr=new FileReader(file);
BufferedReader br=new BufferedReader(fr);
String line="";
while((line=[Link]())!=null) {
[Link]((line));
}
}
}

Writing a data into a file:

Different ways of writing the data into text files

[Link]
[Link]
[Link]

package p1;

import [Link];
full stack java batch-21 Page 2
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
FileOutputStream fos=new FileOutputStream(file);
[Link](72);
[Link](69);
[Link](76);
[Link](76);
[Link](79);
}
}

package p1;

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
String s="welcome";
FileWriter fw=new FileWriter(file);
[Link](s);
[Link]();
full stack java batch-21 Page 3
[Link]();
}
}

package p1;

import [Link];
import [Link];
import [Link];
import [Link];

public class File3 {


public static void main(String[] args) throws IOException{
File file=new File("./[Link]");
if(![Link]())
[Link]();
String s="welcome";
FileWriter fw=new FileWriter(file);
BufferedWriter bw=new BufferedWriter(fw);
[Link](s);
[Link]();
}
}

[Link] java
enum [Link] java
collections [Link]
oracle [Link]
ui==>html, css, bootstrap

3 projects

github deploy
ui
database
advance java java

full stack java batch-21 Page 4


4capstone projects

resume preparation
portfolio website
github customization
linkedin optimization

full stack java batch-21 Page 5


13-4-2025
Sunday, April 13, 2025 8:06 PM

In java,enum(short for enumeration) is a special data type, that enables a variable to be


a set of predefined constant. It is used when you have a fixed set of related constants-
like day of week, direction,month of the year ,etc

class TestEnum{
enum Day{

SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY
}

public static void main(String[] args){


Day today=[Link]
if(today==[Link]){
[Link]("It's Friday!,Time to enjoy");
}
}
}

Day--This is the name of enum type you have defined


today-This is the variable name
[Link]- accessing the FRIDAY constant from the day enum

D:\>javac [Link]

D:\>java TestEnum
It's Friday!,Time to enjoy

Array:
In java, an array holds a fixed number of values of a single Type, arrays are used to store
multiple values in a single variable,

class DayArrayExample{

public static void main(String[] args){


String[] days={

"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY
full stack java batch-21 Page 1
String[] days={

"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY
","SATURDAY"
};

String today=days[5];
if([Link]("FRIDAY")){
[Link]("It's Friday!,Time to enjoy");
}else if([Link]("MONDAY")){
[Link]("Back to work");
} else{
[Link]("Just another day...");
}
}
}
D:\>java DayArrayExample
It's Friday!,Time to enjoy

class DayArrayExample{

public static void main(String[] args){


String[] days={

"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SA
TURDAY"
};

String today=days[7];
if([Link]("FRIDAY")){
[Link]("It's Friday!,Time to enjoy");
}else if([Link]("MONDAY")){
[Link]("Back to work");
} else{
[Link]("Just another day...");
}
}
}

D:\>javac [Link]

full stack java batch-21 Page 2


D:\>java DayArrayExample
Exception in thread "main" [Link]: Index 7 out of
bounds for length 7
at [Link]([Link])

Enum will give compile time errors, Array will give only run time errors

valueOf()

class EnumInput{
enum Day{
SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY
}
public static void main(String[] args){
Scanner s=new Scanner([Link]);
[Link]("Enter the day of the week:"); friday
String input=[Link]().trim().toUpperCase(); friday
try{ friday
Day today=[Link](input); //Convert string to enum constant
switch(today){
case MONDAY:
[Link]("Back to Work!");
break;
case FRIDAY:
[Link]("It is a friday,time to enjoy");
break;
default:
[Link]("Just another day");
}
}catch(IllegalArgumentException e){
[Link]("Invalid Day [Link] try again");
}
}
}

The valuOf method in enum is a built in method in the Enum class , It is used to
convert a string data into corresponding enum constant

compareTo()

In java, the compareTo method is predefined from Enum class, and it is used to
full stack java batch-21 Page 3
In java, the compareTo method is predefined from Enum class, and it is used to
compare two enum constants based on their ordinal values( i.e., their position in the
enum definition)

enum Day{
SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY
}
class EnumCompareExample{
public static void main(String[] args)
{
Day day1=[Link]; result=[Link]()-[Link]()
Day day2=[Link]; =1-5
int result=[Link](day2); =-4
if(result==0){
[Link]("Both days are same");
}else if(result<0){
[Link]("Day 1 comes before day2");
}else{
[Link]("Day 1 comes after day 2 in the enum");
}
}
[Link](result);
}
}

D:\>java EnumCompareExample
Day 1 comes before day2
-4

full stack java batch-21 Page 4


16-4-2025
Wednesday, April 16, 2025 8:06 PM

values()

The values() method in enum is an automatically generated method. It returns an


array of all constants defined in the enum, in the order in which they are declared This
is a very useful method when you need to access all the values of an enum at once

enum Day{
SUNDAY,
MONDAY, alldays=[
TUESDAY, SUNDAY,
WEDNESDAY, MONDAY,
THURSDAY, TUESDAY,
FRIDAY, WEDNESDAY,
SATURDAY THURSDAY,
} FRIDAY,
class EnumExample{ SATURDAY]
public static void main(String[] args){
Day allDays[]=[Link]();
for(Day x:allDays){
[Link](x);
}
}
}
output:
D:\>javac [Link]

D:\>java EnumExample
SUNDAY
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY

ordinal()

The ordinal() in enum is used to retrieve the position of an enum constant in its enum
declaration, starting from 0 for the first constant, 1 for the second, and so [Link] is
full stack java batch-21 Page 1
declaration, starting from 0 for the first constant, 1 for the second, and so [Link] is
predefined method.

enum Day{
SUNDAY,
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY
}
class EnumExample{
public static void main(String[] args)
{
Day day1=[Link];
Day day2=[Link];
[Link]([Link]());
[Link]([Link]())
}
}

D:\>java EnumExample
0
3

full stack java batch-21 Page 2


16-4-2025
Wednesday, April 16, 2025 8:39 PM

Collections frame work:

Collections framework provides many interfaces and their implemented classes,


inorder to store group of elements in a single entity

An array is a fixed size , ordered collection of elements that are of the same data type,
stored in continous memory [Link] element is accessed using index, starting
from 0

Disadvantages of arrays over collections

Fixed array

Arrays have fixed length, once created you cannot grow or shrink them dynamically
collections dynamic resizing

int numbers[]={10,20,30,40}

for(int i=0;i<[Link];i++)
{
[Link](numbers[i])
}

Collections framework provides built in method

add()
remove()
contains()
clear()

Collections framework is divided into two categories: Collection interface, map


interface

Collection interface in java is divided into three main subinterfaces

[Link]
[Link]
full stack java batch-21 Page 1
[Link]
[Link]

List interface is implemented in three ways

[Link]
[Link]
[Link] List

full stack java batch-21 Page 2


18-4-2025
Friday, April 18, 2025 8:11 PM

package p1;

import [Link];

public class VectorProgram {


public static void main(String[] args) {
//Create a vector of Strings
Vector<String> fruits=new Vector<>();

//Add elements to the vector

[Link]("Apple");
[Link]("Banana");
[Link]("Mango");
[Link]("Orange");

//print the vector

[Link]("Fruits in the Vector:" +fruits);

//Access individual elements

[Link]("First Fruit:"+[Link](0));

//Print size and capacity of vector

[Link]("Size:"+[Link]());
[Link]("Capacity:"+[Link]());

//checks if a vector contains an element

if([Link]("Grapes")) {
[Link]("Banana is in the list.");
}

//Remove an element

[Link]("Apple");
[Link]("After removing Apple:" +fruits);

}
full stack java batch-21 Page 1
}
}

output:

Fruits in the Vector:[Apple, Banana, Mango, Orange]


First Fruit:Apple
Size:4
Capacity:10
After removing Apple:[Banana, Mango, Orange]

package p1;

import [Link];

public class VectorOperations {


public static void main(String[] args) {
Vector<Integer> numbers=new Vector<>();

//Add the elements to the vector

[Link](10);
[Link](20);
[Link](30);
[Link](40);

//print the vector


[Link]("Vector after addition:" +numbers);

//Accessing the elements by index

[Link]("Element at index 2:"+[Link](2)); //output:30

//Checking if an element is present

if([Link](20)) {
[Link]("The vector contains 20");
}

//Removing an element by value

[Link]([Link](20));//Removes 20
[Link]("Vector after removing 20:" +numbers);
full stack java batch-21 Page 2
[Link]("Vector after removing 20:" +numbers);

//Removing an element by Index

[Link](1); //Removes element 30


[Link]("Vector after removing element at index 1:" +numbers);

//Adding an element at specific index

[Link](1,25);//Adds 25 at index 1
[Link]("Vector after adding 25 at index 1:" +numbers);

//Get the size of vector

[Link]("Size of the vector:" +[Link]());

//Clear all elements in the vector

[Link]();
[Link]("Vector after clearing all elements:"+numbers);
}
}

output:

Vector after addition:[10, 20, 30, 40]


Element at index 2:30
The vector contains 20
Vector after removing 20:[10, 30, 40]
Vector after removing element at index 1:[10, 40]
Vector after adding 25 at index 1:[10, 25, 40]
Size of the vector:3
Vector after clearing all elements:[]

full stack java batch-21 Page 3


17-4-2025
Thursday, April 17, 2025 8:07 PM

A vector is a class in java that implements the List interface provides growable
array of objects

The default capacity of vector in java is 10

Capacity is the size of the array that holds the elements

When the number of elements exceeds the current capacity , it automatically


increases usually by doubling the present capacity

size() -->no of elements present inside the vector


capacity()--> capacity refers to the amount of space allocated for elements

package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector v1=new Vector();
[Link]("suresh");
[Link]("Capacity:"+[Link]());
[Link]("Size:"+[Link]());
}
}

package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector v1=new Vector();
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
full stack java batch-21 Page 1
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link]("suresh");
[Link](v1);
[Link]("Capacity:"+[Link]());
[Link]("Size:"+[Link]());
}
}

package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector v1=new Vector();
[Link]("suresh");
[Link]("rajesh");
[Link](0,"kumar");
[Link](v1);
[Link]("Capacity:"+[Link]());
[Link]("Size:"+[Link]());
}
}

package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector v=new Vector();
[Link]("Java");
[Link](101);
full stack java batch-21 Page 2
[Link](101);
[Link](45.67);
[Link](true);
[Link]("Vector elements:"+v);
}
}

Vector elements:[Java, 101, 45.67, true]

When we use a raw type(vector without generics) the


collection allows all data type values
If we want to write a type-safe code we should generics
concept inside the collectio

Why to use generics?

Generics allows you to specify the exact type of objects that


a collection can hold. This provides a compile time error
when a type mismatch occurs

package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector<String> fruits= new Vector<>();
[Link]("Apple");
[Link]("Banana");
[Link]("Mango");
[Link]("Orange");
[Link]("Vector elements:"+fruits);
}
}

Vector elements:[Apple, Banana, Mango, Orange]

full stack java batch-21 Page 3


package p1;

import [Link];

public class v11 {


public static void main(String[] args) {
Vector<String> fruits= new Vector<>();
[Link](1);
[Link]("Banana");
[Link]("Mango");
[Link]("Orange");
[Link]("Vector elements:"+fruits);
}
}

Exception in thread "main" [Link]: Unresolved compilation problem:


The method add(int, String) in the type Vector<String> is not applicable for the arguments (int)

at V1/[Link]([Link])

full stack java batch-21 Page 4


19-4-2025
Saturday, April 19, 2025 8:06 PM

Iterator:

The iterator interface is part of [Link] package, it provides methods to iterate over a
collection(such as list,set,queue)

package p1;

import [Link];
import [Link];

public class IteratorExample {


public static void main(String[] args) {
//Create a Vector and add elements
Vector <String> vector=new Vector<>();
[Link]("Java");
[Link]("Python");
[Link]("C++");
[Link]("JavaScript");

//Obtain an Iterator for the vector


Iterator<String> iterator=[Link]();
//when you call [Link](), you are invoking iterator() on vector object

//Use the Iterator to traverse through the vector


while([Link]()) {
[Link]([Link]()); //print each element
}
//The hasNext() method is used to check if there are more elements left in
//the collection while iterating through it.
}
}

ArrayList
=========

An ArrayList is a resizable array in Java that is a part of the collection framework.


Unlike regular arrays, an arraylist can grow or shrink dynamically, and it provides
many useful methods to manipulate the data.
It is present in the [Link] package
full stack java batch-21 Page 1
It is present in the [Link] package

When you create an arraylist without specifying the capacity, java initializes it with a
default capcity of 10

Quiz application
=============

package p1;

import [Link];
import [Link];

public class QuizApp {


public static void main(String[] args) {
Scanner scanner=new Scanner([Link]);

//Create a list of questions

ArrayList<String> questions=new ArrayList<>();


[Link]("What is the capital of India?");
[Link]("Which language is used for Android Development?");
[Link]("what is the value of 5+3?");
[Link]("Which planet is known as the Red planet?");
[Link]("Who wrote 'Romeo and juliet'?");

ArrayList<String> answers=new ArrayList<>();


[Link]("Delhi");
[Link]("Java");
[Link]("8");
[Link]("Mars");
[Link]("Shakespeare");

int score=0;

for(int i=0;i<[Link]();i++) {
[Link]("Q" + (i+1) + ":" + [Link](i));
[Link]("Your answer: ");
String userAnswer=[Link]();

if([Link]([Link](i))) {
[Link]("Correct ✅");
score++;
}else {
[Link]("Wrong ❌. Correct answer:" +[Link](i));
}
}

}
}

full stack java batch-21 Page 2


full stack java batch-21 Page 3
21-4-2025
Monday, April 21, 2025 8:19 PM

Quiz Applications

package p1;
import [Link].*;

public class QuizApp {


public static void main(String[] args) {
Scanner scanner=new Scanner([Link]);

//Create a list of questions

ArrayList<String> questions=new ArrayList<>();


[Link]("What is the capital of India?");
[Link]("Which language is used for Android Development?");
[Link]("what is the value of 5+3?");
[Link]("Which planet is known as the Red planet?");
[Link]("Who wrote 'Romeo and juliet'?");

ArrayList<String> answers=new ArrayList<>();


[Link]("Delhi");
[Link]("Java");
[Link]("8");
[Link]("Mars");
[Link]("Shakespeare");

int score=0;

for(int i=0;i<[Link]();i++) {
[Link]("Q" + (i+1) + ":" + [Link](i));
[Link]("Your answer: ");
String userAnswer=[Link]();

if([Link]([Link](i))) {
[Link]("Correct ✅");
score++;
}else {
[Link]("Wrong ❌. Correct answer:" +[Link](i));
}
}
//Final Score

[Link](" Quiz Completed");


[Link]("Your Score:" + score + "out of " + [Link]());
}
}

LinkedList

A linked list in java is a linear data structure that stores elements in non contiguous
memory locations. Each element( called as node) contains two parts

[Link]- the actual value


[Link](or pointer) - a link to the next node

In java Linkedlist is a class that is a part of [Link] package

LinkedList<String> list=new LinkedList<>();

full stack java batch-21 Page 1


package p1;

import [Link];

public class LinkedListExample {


public static void main(String[] args) {
LinkedList<String> cities=new LinkedList<>();

[Link]("Hyderabad");
[Link]("Delhi");
[Link]("Mumbai");
[Link]("Bangalore"); //Adds at Beginning
[Link]("Chennai"); //Adds at Last
[Link]("Cities:" +cities);

//Access by index

[Link]("City at index 2:" +[Link](2));


//Remove by Index

[Link](3);
[Link]("Ater removing index 3:" +cities);

//Remove first and last

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

full stack java batch-21 Page 2


[Link]();
[Link]("Ater removing First Index and Last Index:" +cities);
}
}

Cities:[Bangalore, Hyderabad, Delhi, Mumbai, Chennai]


City at index 2:Delhi
Ater removing index 3:[Bangalore, Hyderabad, Delhi, Chennai]
Ater removing First Index and Last Index:[Hyderabad, Delhi]

full stack java batch-21 Page 3


22-4-2025
Tuesday, April 22, 2025 8:06 PM

Todo application

package p1;

import [Link];
import [Link];

public class ToDoList {


public static void main(String[] args) {
LinkedList<String> tasks = new LinkedList<>();
Scanner scanner = new Scanner([Link]);
int choice;

do {
[Link]("\n TO-DO LIST MENU");
[Link]("1. Add Task");
[Link]("2. View Tasks");
[Link]("3. Remove Task");
[Link]("4. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
[Link](); // consume newline

switch (choice) {
case 1:
[Link]("Enter the task: ");
String x = [Link]();
[Link](x);
[Link]("✅ Task added!");
break;

case 2:
[Link]("\n Your Tasks:");
if([Link]()) {
[Link]("No tasks found");
}else {
full stack java batch-21 Page 1
}else {
for(int i=0;i<[Link]();i++) {
[Link]([Link](i));
}
}
break;

case 3:
[Link]("Enter the task number to remove:");
int taskNum=[Link]();
if(taskNum<=[Link]()) {
[Link](taskNum);
[Link]("❌ Task removed.");
}

}
}while(choice!=4);

}
}

full stack java batch-21 Page 2


23-4-2025
Wednesday, April 23, 2025 8:18 PM

To do list:

package p1;

import [Link];
import [Link];

public class ToDoList {


public static void main(String[] args) {
LinkedList<String> tasks = new LinkedList<>();
Scanner scanner = new Scanner([Link]);
int choice;

do {
[Link]("\n TO-DO LIST MENU");
[Link]("1. Add Task");
[Link]("2. View Tasks");
[Link]("3. Remove Task");
[Link]("4. Exit");
[Link]("Enter your choice: ");
choice = [Link]();
[Link]();
switch (choice) {
case 1:
[Link]("Enter the task: ");
full stack java batch-21 Page 1
[Link]("Enter the task: ");
String x = [Link]();
[Link](x);
[Link]("✅ Task added!");
break;

case 2:
[Link]("\n Your Tasks:");
if([Link]()) {
[Link]("No tasks found");
}else {
for(int i=0;i<[Link]();i++) {
[Link]([Link](i));
}
}
break;

case 3:
[Link]("Enter the task number to remove:");
int taskNum=[Link]();
if(taskNum<[Link]()) {
[Link](taskNum);
[Link]("❌ Task removed.");
}else {
[Link]("⚠ Invalid task number.");
}
break;
case 4:
[Link](" Exiting... Have a productive day!");
break;

}
}while(choice!=4);

}
}

set

A set in java is a collection that doesnot allow duplicate elements. It is a part of java collections
frame work

keypoints about set:

[Link] duplicates is allowed


full stack java batch-21 Page 2
[Link] duplicates is allowed
[Link] will not maintain insertion order
3. Useful when we want to store unique items only

Interfaces in java cannot be instantiated directly, we must use a class that implements
the set [Link] interface is implemented in Hashset class

package p1;

import [Link];

public class Hashset1 {


public static void main(String[] args) {
HashSet<String> animals=new HashSet<>();

[Link]("Cat");
[Link]("Dog");
[Link]("Elephant");
[Link]("Cat");

[Link](animals);
}
}

output:
[Cat, Elephant, Dog]

package p1;

import [Link];

public class Hashset1 {


public static void main(String[] args) {
HashSet<String> set=new HashSet<>();

// Adding element to the HashSet

[Link]("Apple");
[Link]("Banana");
[Link]("Orange");
[Link]("Apple"); //Duplicate, will be ignored

[Link](set);

//Check if an element exists in the set

if([Link]("Apple")) {
[Link]("Apple is in the set");
}else {

full stack java batch-21 Page 3


}else {
[Link]("Apple is not in the set");
}
//Get the size of the set

[Link]("Size of the set:" +[Link]()); //output:3

//Removing an element from the set

[Link]("Banana");
[Link](set);//Output:[Apple,Orange]

//Removing an element that doesnot exists

if([Link]("Mango")) {
[Link]("Mango was removed");
}else {
[Link]("Mango was not found in the set");
}

//Check if the set is empty

if([Link]()) {
[Link]("The set is empty");
}else {
[Link]("The set is not empty");
}

//Clear the set

[Link]();
[Link](set);

//Checking the size after clearing

[Link]("Size of the set after clearing:" +[Link]());


}
}

output:
[Apple, Orange, Banana]
Apple is in the set
Size of the set:3
[Apple, Orange]
Mango was not found in the set
The set is not empty
[]
Size of the set after clearing:0

full stack java batch-21 Page 4


24-4-2025
Thursday, April 24, 2025 8:22 PM

package p1;

import [Link];
import [Link];

public class UserRegistration {


public static void main(String[] args) {
HashSet<String> usernames=new HashSet<>();
Scanner s=new Scanner([Link]);
[Link](" User Registration System(Type 'exit' to quit)");
while(true) {
[Link]("Enter a username:");
String input=[Link]();
if([Link]("exit")) {
break;
}
if([Link](input)) {
[Link]("❌ Username already Taken. Try another one");
}else {
[Link](input);
[Link]("✅ User Registered Successfully");

}
[Link]("Current Registered Users:" +usernames);
[Link]("---------------------------------------");
}
[Link](" Final list of registered usernames:" +usernames);
}
}

output:

User Registration System(Type 'exit' to quit)


Enter a username:
john
✅ User Registered Successfully
Current Registered Users:[john]
---------------------------------------
Enter a username:
suresh
✅ User Registered Successfully
Current Registered Users:[suresh, john]
---------------------------------------
Enter a username:
suresh
❌ Username already Taken. Try another one
Current Registered Users:[suresh, john]
---------------------------------------
Enter a username:
exit
Final list of registered usernames:[suresh, john]

full stack java batch-21 Page 1


Queue

A queue is a linear data structure that follows First-In-First-


Out(FIFO) principle- the element that is added first is removed
first

Elements are added at the rear(end)


Elements are removed from the front(head)

Method Description
add(e) Adds element to the queue
poll() Removes and returns head
peek() Returns head without
removing

A priority queue is a special kind of queue where elements are


ordered based on their natural order

unlike a regular queue(FIFO), a priority queue always returns the


smallest element first

output:

package p1;

import [Link];
import [Link];

public class QueueExample {


public static void main(String[] args) {
Queue<String> queue=new PriorityQueue<>();
[Link]("Customer1");
[Link]("Customer2");
[Link]("Customer3");

full stack java batch-21 Page 2


[Link]("Customer3");
[Link]("Queue:" +queue);//[Customer1,Customer2,Customer3]
while(![Link]()) {
[Link]("Serving:" +[Link]()); //FIFO: 1->2->3
}
}
}

Queue:[Customer1, Customer2, Customer3]


Serving:Customer1
Serving:Customer2
Serving:Customer3

package p1;

import [Link];
import [Link];

public class TicketBookingSystem {


public static void main(String[] args) {
//Create a queue to simulate the line for ticket Booking
Queue<String>ticketQueue=new LinkedList<>();

//Customers arrive and join the queue


[Link]("Customer1");
[Link]("Customer2");
[Link]("Customer3");

[Link]("Initial Ticket Booking Queue:"+ ticketQueue);

//serve customers in the order they arrived

while(![Link]()) {
String customer=[Link]();//Retrieves and removes the head
[Link](customer + " is being Served a ticket");
[Link]("Queue after serving:" +ticketQueue);

//The queue is now empty

}
[Link]("All customers are served");
}
}

Initial Ticket Booking Queue:[Customer1, Customer2, Customer3]


Customer1 is being Served a ticket
Queue after serving:[Customer2, Customer3]

full stack java batch-21 Page 3


Queue after serving:[Customer2, Customer3]
Customer2 is being Served a ticket
Queue after serving:[Customer3]
Customer3 is being Served a ticket
Queue after serving:[]
All customers are served

full stack java batch-21 Page 4


25-5-2025
Friday, April 25, 2025 8:14 PM

package p1;

import [Link];

public class PriorityQueueExample {


public static void main(String[] args) {
PriorityQueue<Integer> pq=new PriorityQueue<>();
[Link](30);
[Link](10);
[Link](20);
[Link]("PriorityQueue:"+pq);
while(![Link]()) {
[Link]("Polled:"+[Link]());
}

output:

PriorityQueue:[10, 30, 20]


Polled:10
Polled:20
Polled:30

Real time example:Call Center simulation system

Example overview:

Simulate a callcenter where incoming customer calls are placed


in queue, and supports the executive to pick them up in the
order they arrive-----First-In ,First-Out(FIFO)

Features:

[Link] incoming calls to the queue


[Link] a call when the execute becomes available
[Link] the waiting calls in real time
[Link] the number of calls served

Program:

full stack java batch-21 Page 1


package p1;

import [Link];
import [Link];
import [Link];

public class CallCenterSimulation {


public static void main(String[] args) {
Scanner s=new Scanner([Link]);
Queue<String> callQueue=new LinkedList<>();
[Link](" Welcome to Call Center Simulation System");
boolean running=true;
while(running) {
[Link]("\nChoose an option:");
[Link]("[Link] Call");
[Link]("[Link] Call");
[Link]("[Link] Waiting Calls");
[Link]("[Link]");

int choice=[Link]();
[Link]();
switch(choice) {
case 1:
[Link]("Enter Caller Name:");
String caller=[Link]();
[Link](caller);
[Link]("Call from "+caller +" added to Queue");
break;
case 2:
if(![Link]()) {
String served=[Link]();
[Link]("Serving call from: " + served);

}else {
[Link]("No calls to serve");
}
break;
case 3:
[Link]("Current Waiting Calls: " +callQueue);
break;
case 4:
running=false;
[Link]("Exiting [Link]!");
break;
}
}
}
}

full stack java batch-21 Page 2


26-4-2025
Saturday, April 26, 2025 8:05 PM

Hashmap

A Hash map is a part of java collections framework and is used to store data in key-
value pairs. It is one of the most commonly used classes for insertion and deletes

package p1;

import [Link];

public class Hashmap1 {


public static void main(String[] args) {
HashMap<Integer,String> map=new HashMap<>();
[Link](10, "Ten");
[Link](5, "Five");
[Link](20, "Twenty");
[Link](1, "One");
[Link](15, "Fifteen");
[Link](map);
}
}

output:
{1=One, 20=Twenty, 5=Five, 10=Ten, 15=Fifteen}

Treemap
A Treemap is a class in java , and it is a part of collection framework, it stores key-
value pairs in a ascending order of keys

package p1;

import [Link];

public class Hashmap1 {


public static void main(String[] args) {
TreeMap<Integer,String> map=new TreeMap<>();
[Link](10, "Ten");
[Link](5, "Five");
[Link](20, "Twenty");
[Link](1, "One");
[Link](15, "Fifteen");
[Link](map);
full stack java batch-21 Page 1
[Link](map);
}
}

{1=One, 5=Five, 10=Ten, 15=Fifteen, 20=Twenty}

PhoneBook

keySet() Returns all keys


get(key) Returns the value for the given key

package p1;

import [Link];

public class PhoneBook {


public static void main(String[] args) {
//Create Hashmap to store contact names and phone numbers

HashMap<String,String> phoneBook=new HashMap<>();

//Adding Contacts

[Link]("Suresh", "9898981234");
[Link]("kishore", "9898981235");
[Link]("kumar", "9898981236");

//Display all contacts

[Link](" PhoneBook Contacts");


for(String name:[Link]())
{
[Link](name + "-" +[Link](name));
}

//search for a contact

String searchName="sai";
if([Link](searchName)) {
[Link]("Found " + searchName + ":" +[Link](searchName));
} else {
full stack java batch-21 Page 2
} else {
[Link](searchName + " not found in phoneBook");
}

//Remove Contact

[Link]("Suresh");
[Link]("After removing Suresh:");
[Link](phoneBook);

}
}

output:

PhoneBook Contacts
Suresh-9898981234
kishore-9898981235
kumar-9898981236
sai not found in phoneBook
After removing Suresh:
{kishore=9898981235, kumar=9898981236}

full stack java batch-21 Page 3


27-4-2025
Sunday, April 27, 2025 8:11 PM

retainAll()

The retainAll() method is used to modify a set by keep only elements that are
present in both the sets

package p1;

import [Link];
import [Link];

public class retain1 {


public static void main(String[] args){

//step 1: Create two arrays

Integer[] array1={1,2,3,4};
Integer[] array2={2,3,5};

//Step 2: Create two Hashsets and add elements from the arrays

Set<Integer> set1=new HashSet<>();


Set<Integer> set2=new HashSet<>();

//Adding elements from array1 to set1

for(Integer x:array1){
[Link](x);
}

//Adding elements from array2 to set2


for(Integer x: array2) {
[Link](x);
}

//step3: Perform retainAll to keep only common element

[Link](set2);

//step 4: Display the result(common elements)

full stack java batch-21 Page 1


//step 4: Display the result(common elements)
[Link]("Common elements:"+set1);

}
}

output:
Common elements:[2, 3]
{1,2,3,4}

set1=[1,2,3,4]

import [Link].*;

public class Main {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

int n = [Link](); // Size of the first array


int[] arr1 = new int[n]; // First array

for (int i = 0; i < n; i++) {


arr1[i] = [Link](); // Read elements of the first array
}

int m = [Link](); // Size of the second array


int[] arr2 = new int[m]; // Second array

for (int i = 0; i < m; i++) {


arr2[i] = [Link](); // Read elements of the second array
}

// Step 1: Convert arr1 and arr2 to sets to remove duplicates


Set<Integer> set1 = new HashSet<>();
Set<Integer> set2 = new HashSet<>();

for (int num : arr1) {


[Link](num);
}
full stack java batch-21 Page 2
}

for (int num : arr2) {


[Link](num);
}

// Step 2: Find the intersection of the two sets


[Link](set2);

// Step 3: Sort the result


List<Integer> resultList = new ArrayList<>(set1);
[Link](resultList);

// Step 4: Print the result


for (int num : resultList) {
[Link](num + " ");
}
}
}

full stack java batch-21 Page 3


28-4-2025
Monday, April 28, 2025 8:13 PM

You are given a list of ages of several individuals. Your task is to count the number of
individuals in each age group. Age groups are defined as follows:
0-9 (inclusive)
10-19 (inclusive)
20-29 (inclusive)
30-39 (inclusive)
40-49 (inclusive)
50 and above

Solution:

import [Link].*;

public class Main{


public static void main(String[] args){
//Read input

Scanner sc=new Scanner([Link]);


int n=[Link]();

List<Integer> ages=new ArrayList<>();

//Read ages into the List

for(int i=0;i<n;i++)
{
[Link]([Link]());
}

//Use a Map to store the count of individuals in each age group

Map<String,Integer> ageGroups=new LinkedHashMap<>();

//Intialize age groups in the map

[Link]("0-9",0);
full stack java batch-21 Page 1
[Link]("0-9",0);
[Link]("10-19",0);
[Link]("20-29",0);
[Link]("30-39",0); [
[Link]("40-49",0); ("0-9",1),
[Link]("50+",0); ("10-19",1),
("20-29",1),
//Classify each age into its respective ("30-39",1),
("40-49",1),
for(int age:ages){ ("50+",1)
if(age>=0 && age<=9){ ]
[Link]("0-9",[Link]("0-9")+1);
}else if(age>=10 && age<=19){ age=5
[Link]("10-19",[Link]("10-19")+1);
}else if(age>=20 && age<=29){
[Link]("20-29",[Link]("20-29")+1);
}else if(age>=30 && age<=39){
[Link]("30-39",[Link]("30-39")+1);
}else if(age>=40 && age<=49){
[Link]("40-49",[Link]("40-49")+1);
}else if(age>=50){
[Link]("50+",[Link]("50+")+1);
}
}
for([Link]<String,Integer>entry:[Link]()) {
[Link]([Link]());
}
}
}

To download and install mysql

[Link]

full stack java batch-21 Page 2


full stack java batch-21 Page 3

You might also like