Advance Java Final PDF
Advance Java Final PDF
package [Link].parta1;
EIGHTY(80), NINETY(90);
// Constructor
NumberWord(int value)
[Link] = value;
PAGE:
// Method to get word for exact number
if ([Link] == n)
return [Link]();
return "";
if (n == 0)
return "ZERO";
if (n >= 1000)
n %= 1000;
if (n >= 100)
{
PAGE:
result += getWord(n / 100) + " HUNDRED ";
n %= 100;
if (n >= 20)
n %= 10;
if (n > 0)
result += getWord(n);
return [Link]();
--------
package [Link].parta1;
import [Link];
int n;
[Link]([Link](n));
OUTPUT:
Enter a Number 78
SEVENTY EIGHT
Enter a Number 0
ZERO
Enter a Number -7
OUT OF RANGE
OUT OF RANGE
PAGE:
REGISTRATION NUMBER: U05SD24S0038
Find the second maximum and second minimum in a set of numbers using auto boxing
and unboxing.
import [Link];
import [Link];
import [Link];
Set<Integer>sortedset=new TreeSet<Integer>();
int n;
n=[Link]();
if(n<2)
else
[Link]([Link]());
Integer[]arr=[Link](new Integer[0]);
OUTPUT:
82067
9804
PAGE:
REGISTRATION NUMBER: U05SD24S0038
Write a menu driven program to create an Arraylist and perform the following
operations
v) Displaying all the elements vi) Adding an element between two elements
package [Link].parta3;
import [Link];
import [Link];
import [Link];
int choice=7;
ArrayList<Integer>alist=new ArrayList<Integer>();
int val,fval,pos;
do
[Link]("-----menu program---");
[Link]("[Link]");
[Link]("[Link]");
PAGE:
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link] in between");
[Link]("[Link]");
choice=[Link]();
switch(choice)
case 1:
[Link]("Enter a number:");
val=[Link]();
[Link](val);
break;
case 2:
[Link]("sorting--");
[Link](alist);
[Link]("sorting completed");
case 3:
fval=[Link]();
if([Link](fval))
[Link]("replacement completed");
else
break;
case 4:
Integer r=[Link]();
if([Link](r))
[Link](r);
[Link]("element is removed");
else
break;
case 5:
[Link](alist);
break;
PAGE:
case 6:
pos=[Link]();
if(pos<[Link]())
val=[Link]();
[Link](pos,val);
[Link]("element inserted");
else
break;
case 7:
[Link]("Thank you");
return;
default:
}while(true);
PAGE:
OUTPUT:
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
Enter a number:7
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
1
PAGE:
Enter a number:6
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
Enter a number:4
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
5
PAGE:
[7, 6, 4]
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
sorting--sorting completed
replacement completed
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
[0, 6, 7]
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
element inserted
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
[0, 6, 5, 7]
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
element is removed
PAGE:
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
[0, 6, 5, 7]
-----menu program---
[Link]
[Link]
[Link]
[Link]
[Link]
[Link] in between
[Link]
Thank you
PAGE:
REGISTRATION NUMBER: U05SD24S0038
Write a java program to find words with even number of characters in a string, then
swap the pair of characters in those words and also toggle the characters in a given
string EX: Good Morning everyone
package [Link].parta4;
import [Link];
[Link]("Enter a string:");
String str=[Link]();
String[]words=[Link](" ");
if ([Link]()%2==0)
{
PAGE:
char[]ch=[Link]();
for(int i=0;i<[Link]-1;i+=2)
char temp=ch[i];
ch[i]=ch[i+1];
ch[i+1]=temp;
[Link]();
char c=[Link](i);
if ([Link](c))
[Link]([Link](c));
else if([Link](c))
[Link]([Link](c));
else
[Link](c);
PAGE:
}
OUTPUT:
Enter a string:
HELLO JAVA
AJAV
Write a Servlet program that accepts the age and name and displays if the user is
eligible for voting or not
package com;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* @author S26
*/
/**
* methods.
PAGE:
* @throws ServletException if a servlet-specific error occurs
*/
[Link]("text/html;charset=UTF-8");
/* TODO output your page here. You may use following sample code. */
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Servlet vote</title>");
[Link]("</head>");
[Link]("<body>");
String name=[Link]("uname");
int age=[Link]([Link]("age"));
if(age<18)
else
PAGE:
{
[Link]("<a href=\"[Link]\">HOME</a>");
[Link]("</body>");
[Link]("</html>");
[Link]
<!DOCTYPE html>
<!--
-->
<html>
<head>
<meta charset="UTF-8">
<style>
table{
background-color:aqua;
width:200px;
PAGE:
margin-top: 100px;
margin-left: auto;
margin-right: auto;
border:solid 2px;
td{
padding:5px;
</style>
</head>
<body>
<table>
<tr>
</tr>
<tr>
</tr>
<tr>
PAGE:
</tr>
</table>
</form>
</body>
</html>
OUTPUT:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h4>Fibonacci Series</h4>
<%
int a=0,b=1,c,i;
[Link](a+" "+b+" ");
for(i=1;i<=8;i++)
c=a+b;
[Link](c+" ");
a=b;
b=c;
%>
<%
PAGE:
int pno=2,count=1;
boolean isprime;
while(count<=10)
isprime=true;
for(i=2;i<=pno/2;i++)
if(pno%i==0)
isprime=false;
break;
if(isprime)
[Link](pno+" "
);count++;
pno++;
%>
</body>
</html>
OUTPUT:
PAGE:
REGISTRATION NUMBER:
NAME:
PAGE:
PROGRAM NO: PART A – 7
Write a Java Servlet program to Download a file and display it on the screen. (A link
has to be provided in HTML. When the link is clicked corresponding file has to be
displayed/downloaded on the screen.)
1. [Link]
<!DOCTYPE html>
<html>
<head>
<title>File Download</title>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
</head>
<body>
<a href="FileDownloader?filename=[Link]">
Download my CV
</a>
</body>
</html>
2. [Link]
package com;
import [Link].*;
PAGE:
import [Link].*;
import [Link].*;
import [Link];
[Link]("text/plain");
OutputStream os = [Link]();
int i = 0;
[Link](i);
[Link]();
[Link]();
}
PAGE:
OUTPU:
REGISTRATION NUMBER:
NAME:
Write a menu driven JDBC program to perform basic operations with Student Table.
PAGE:
package b1;
import [Link].*;
import [Link];
try
[Link]("[Link]");
"jdbc:mysql://localhost:3306/partb1", "root","rootbca123");
Statement st = [Link]( );
PAGE:
String sql;
do
[Link]("5. Exit");
ch = [Link]();
[Link]();
switch(ch)
case 1:
regno = [Link]();
[Link]();
try
[Link](sql);
[Link]("Record Inserted");
catch(SQLException e)
break;
case 2:
PAGE:
[Link]("Enter Reg No : ");
regno = [Link]();
if ([Link](sql)==1)
else
break;
case 3:
regno = [Link]();
[Link]();
if ([Link](sql)==1)
else
break;
PAGE:
case 4:
regno = [Link]();
ResultSet rs =[Link](sql);
if ([Link]())
[Link]("\nStudent Details");
[Link]("-----------------------");
[Link]("Reg No : "+[Link](1));
[Link]("Name : "+[Link](2));
else
break;
case 5:
[Link]();
default:
[Link]("Wrong Choice");
}while(ch!=5);
catch(Exception e)
[Link](e);
• Create a table named STDTABLE with the following fields and constraints:
-----------------------------------------------------------------
-----------------------------------------------------------------
-----------------------------------------------------------------
OUTPUT:
[Link]
[Link]
[Link]
[Link]
[Link]
Enter Choice : 1
SOWMYA
2005-08-15
MANGALORE
IB
BCA
Inserted
[Link]
[Link]
[Link]
[Link]
[Link]
Enter Choice : 4
[Link]
[Link]
[Link]
[Link]
Enter Choice : 3
Updated
[Link]
[Link]
[Link]
[Link]
[Link]
Enter Choice : 2
Deleted
[Link]
[Link]
[Link]
[Link]
[Link]
Enter Choice : 2
Not Found
PAGE:
REGISTRATION NUMBER:
NAME:
Write a menu driven JDBC program to perform basic operations with Bank Table.
PAGE:
MENU
3. Amount Withdrawal (Maintain minimum balance 500 Rs) 4. Display all information
5. Exit
BANK TABLE
--------------------------------------------------------
--------------------------------------------------------
package partb2;
import [Link].*;
import [Link];
try
[Link]("[Link]");
Connection con=[Link]
Statement st = [Link]();
String sql;
do
PAGE:
{
[Link]("5. Exit");
ch = [Link]();
switch(ch)
case 1:
accno = [Link]();
amount = [Link]();
try
PAGE:
[Link](sql);
[Link]("Account Added");
catch(SQLException e)
break;
case 2:
accno = [Link]();
amount = [Link]();
if ([Link](sql)= =1)
[Link]("Amount Deposited");
else
break;
case 3:
PAGE:
accno = [Link]();
ResultSet rs =[Link](sql);
if ([Link]())
amount = [Link]();
if (bal-amount>=500)
where acc_no="+accno;
[Link](sql);
[Link]("Amount Withdrawn");
else
else
break;
PAGE:
// ===== DISPLAY =====
case 4:
[Link]("\nAccNo\tName\tAddress\tBalance");
while([Link]())
[Link]([Link](1)+"\t"+ [Link](2)+"\t"+
[Link](3)+"\t"+ [Link](4));
break;
case 5:
[Link]();
[Link]("Thank You");
break;
default:
[Link]("Wrong Choice");
}while(ch!=5);
catch(Exception e)
[Link](e);
}
PAGE:
}
• Create a table named BANK with the following fields and constraints:
--------------------------------------------------------
OUTPUT:
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 1
Account Added
1. Add Account
2. Deposit Amount
PAGE:
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 4
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 2
Amount Deposited
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
PAGE:
Enter Choice : 3
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 3
Amount Withdrawn
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 3
1. Add Account
2. Deposit Amount
3. Withdraw Amount
4. Display Accounts
5. Exit
Enter Choice : 5
Thank You
PAGE:
Write a Java class called Tax with methods for calculating Income Tax. Have this class
as a servant and create a server program and register in the rmiregistry. Write a client
program to invoke these remote methods of the servant and do the calculations. Accept
Inputs interactively.
import [Link].*;
2. Servant — [Link]
import [Link].*;
import [Link].*;
PAGE:
super();
double tax;
tax = 0;
tax = (300000 * 0.05) + (300000 * 0.10) + (300000 * 0.15) + (income - 1200000) * 0.20;
else
return tax;
3. Server — [Link]
PAGE:
import [Link].*;
try
[Link]("rmi://[Link]/RMI/TAX", obj);
catch(Exception e)
[Link](e);
import [Link].*;
import [Link].*;
PAGE:
{
try
catch(Exception e)
[Link](e);
PAGE:
REGISTRATION NUMBER: U05SD24S0038
Write a Java class called SimpleInterest with methods for calculating simple interest.
PAGE:
Have this class as a servant and create a server program and register in the
rmiregistry.
Write a client program to invoke these remote methods of the servant and do the
import [Link].*;
// Servant — [Link]
import [Link].*;
import [Link].*;
super();
return (p * t * r) / 100;
}
PAGE:
}
// Server — [Link]
import [Link].*;
try
[Link]("rmi://[Link]/PrgmB4", obj);
[Link]("Server Running...");
catch(Exception e)
[Link](e);
import [Link].*;
import [Link].*;
PAGE:
{
try
SimpleInterest SI =
(SimpleInterest) [Link]("rmi://[Link]/PrgmB4");
double p = [Link]();
double t = [Link]();
double r = [Link]();
catch(Exception e)
[Link](e);
OUTPUT :
PAGE:
REGISTRATION NUMBER:
NAME:PROGRAM NO:
PART B-5
PAGE:
Write a Java JSP program to get student information through HTML, create a Java
Bean class, populate the Bean and display the same information through another JSP
page.
[Link]
<!DOCTYPE html>
<!--
<html>
<head>
<title>Student Info</title>
<meta charset="UTF-8">
</head>
<body>
<table>
<tr>
<td>Register No:</td>
</tr>
<tr>
<td>Name:</td>
PAGE:
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Course:</td>
</tr>
<tr>
<td>Semester:</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</body>
</html>
[Link] (Note: Should be created by right clicking on Source Packages New Java
Class Name it as Student Package: com Finish)
package com;
import [Link];
PAGE:
public class Student implements Serializable {
public Student() {
return regno;
[Link] = regno;
return name;
[Link] = Name;
[Link] = course;
return sem;
[Link] = sem;
webNewJSP)
<%--
Document : Firstpage
<%@page import="[Link]"%>
PAGE:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</jsp:useBean>
</body>
</html>
<%--
Document : secondpage
<!DOCTYPE html>
PAGE:
<html>
<head>
<title>Second Page</title>
</head>
<body>
<table border="1">
<tr>
<td>Register No:</td>
<td>${[Link]}</td>
</tr>
<tr>
<td>Name:</td>
<td>${[Link]}</td>
</tr>
<tr>
<td>Course:</td>
<td>${[Link]}</td>
</tr>
<tr>
<td>Semester:</td>
<td>${[Link]}</td>
</tr>
</table>
PAGE:
</body>
</html>
OUTPU:
PAGE:
REGISTRATION NUMBER:
NAME:
Write a menu driven program to create a linked list and perform the following
operations.
PAGE:
a. To Insert some Elements at the Specified Position
package partb7;
import [Link].*;
char ch;
do
[Link]("\n MENU");
[Link]("a. Insert");
[Link]("b. Swap");
[Link]("c. Reverse");
[Link]("d. Compare");
[Link]("x. Exit");
PAGE:
[Link]("Enter Choice: ");
ch = [Link]().toLowerCase().charAt(0);
switch(ch)
case 'a':
[Link](pos-1, num);
[Link](list);
else
[Link]("Invalid Position");
break;
case 'b':
int p1 = [Link]();
int p2 = [Link]();
PAGE:
if (p1>=1 && p2>=1 && p1<=[Link]() && p2<=[Link]())
[Link](p1-1, [Link](p2-1));
[Link](p2-1, temp);
[Link](list);
else
[Link]("Invalid Position");
break;
case 'c':
[Link]("Reverse : ");
Iterator<Integer> it =[Link]();
while([Link]())
[Link]();
break;
case 'd':
if ([Link](list2))
else
PAGE:
[Link]("Lists are Not Equal");
break;
case 'e':
[Link](alist);
break;
case 'x':
[Link]("Thank You");
break;
default:
[Link]("Wrong Choice");
}while(ch!='x');
OUTPUT:
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
PAGE:
e. Convert to ArrayList
x. Exit
Enter Choice: 1
Wrong Choice
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice: a
Enter Position: 2
Enter Element: 4
Invalid Position
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice : a
PAGE:
Enter Position : 1
Enter Element : 4
[4]
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice : a
Enter Position : 2
Enter Element : 5
[4, 5]
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice : b
[5, 4]
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice : c
Reverse : 4 5
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice: d
PAGE:
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice : e
[5, 4]
MENU
a. Insert
b. Swap
c. Reverse
d. Compare
e. Convert to ArrayList
x. Exit
Enter Choice: x
Thank You
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
PAGE:
REGISTRATION NUMBER:
NAME:
PAGE:
Implement a java application based on the MVC design pattern. Input student Rollno,
name, marks in three subjects. Calculate result and grade and display the result in neat
format.
1. [Link]
package partb8;
public StudentModel(String rno, String name, int m1, int m2, int m3)
{
[Link] = rno;
[Link] = name;
this.m1 = m1;
this.m2 = m2;
this.m3 = m3;
}
PAGE:
return "Fail";
if(per>=90)
return "A";
else if(per>=80)
return "B";
else if(per>=70)
return "C";
else if(per>=60)
return "D";
else
return "E";
}
2. [Link]
package partb8;
PAGE:
StudentModel model;
StudentView view;
3. [Link]
package partb8;
[Link]([Link]+"\t"+[Link]+"\t"+s.m1+"\t"+s.m2+"\t"+s.m3+"\t"+
[Link]()+"\t"+[Link]());
[Link]("---------------------------------------------------");
}
4. [Link]
package partb8;
import [Link];
[Link]();
}
OUTPUT
89
78
---------------------------------------------------
PAGE:
---------------------------------------------------
90
89
---------------------------------------------------
---------------------------------------------------
PAGE: