Professional Documents
Culture Documents
SYLLABUS
COURSE OBJECTIVES
Develop and implement Java programs for simple applications that make use of classes, packages and interfaces.
Develop and implement Java programs with arraylist, exception handling and multithreading .
Design applications using file processing, generic programming and event handling.
LIST OF EXPERIMENTS
1. Develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month reading,
current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
First 100 units - Rs. 1 per unit
101-200 units - Rs. 2.50 per unit
201 -500 units - Rs. 4 per unit
501 units - Rs. 6 per unit
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
First 100 units - Rs. 2 per unit
101-200 units - Rs. 4.50 per unit
201 -500 units - Rs. 6 per unit
501 units - Rs. 7 per unit
2. Develop a java application to implement currency converter (Dollar to INR, EURO to INR, Yen to INR and vice versa), distance converter (meter to KM, miles to
KM and vice versa) , time converter (hours to minutes, seconds and vice versa) using packages.
3. Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id, Mobile_no as members. Inherit the classes, Programmer, Assistant
Professor, Associate Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the inherited classes with 97% of BP as DA, 10 % of BP
as HRA, 12% of BP as PF, 0.1% of BP for staff club fund. Generate pay slips for the employees with their gross and net salary.
4. Design a Java interface for ADT Stack. Implement this interface using array. Provide necessary exception handling in both the implementations.
5. Write a program to perform string operations using ArrayList. Write functions for the following
a. Append - add at end
b. Insert – add at particular index
c. Search
d. List all string starts with given letter
6. Write a Java Program to create an abstract class named Shape that contains two integers and an empty method named print Area(). Provide three classes
named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method print Area () that
prints the area of the given shape.
9. Write a java program that implements a multi-threaded application that has three threads. First thread generates a random integer every 1 second and if the
value is even, second thread computes the square of the number and prints. If the value is odd, the third thread will print the value of cube of the number.
10. Write a java program to find the maximum value from the given type of elements using a generic function.
11. Design a calculator using event-driven programming paradigm of Java with the following options.
a) Decimal manipulations
b) Scientific manipulations
12. Develop a mini project for any application using Java concepts.
Exp. No. 1. Develop a Java application to generate Electricity bill. Create a class with the following members: Consumer no., consumer name, previous month
reading, current month reading, type of EB connection (i.e domestic or commercial). Compute the bill amount using the following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
PROGRAM
import java.util.*;
class ElectricityBill
{
int cno;
String cname;
int pr;
int cr;
String atype;
int reading;
double bamount;
public ElectricityBill(int no, String name,int prev, int cur,String acc)
{
this.cno=no;
this.cname=name;
this.pr=prev;
this.cr=cur;
this.atype=acc;
}
public void calculate()
{
reading=cr-pr;
if(atype.compareToIgnoreCase("domestic")==0)
{
if(reading<=100)
bamount=reading*1.0;
if(reading>100 && reading<=200)
bamount=100+((reading-100)*2.50);
if(reading>200 && reading<=500)
bamount=100+250 + (reading-200)*4;
if(reading>500)
bamount=100+250+ 1200+(reading-500)*6;
}
else if(atype.compareToIgnoreCase("commercial")==0)
{
if(reading<=100)
bamount=reading*2.0;
if(reading>100 && reading<=200)
bamount=200+((reading-100)*4.50);
if(reading>200 && reading<=500)
bamount=200+450 + (reading-200)*6;
if(reading>500)
bamount=200+450 +1800+(reading-500)*7;
}
else
{
System.out.println("Invalid Customer Type");
System.exit(0);
}
}
public void displaybill()
{
System.out.println("\t\t Electricity Bill \n");
System.out.println("\t\t________________\n");
System.out.println("customer Name :"+cname);
System.out.println("Customer Number :"+cno);
System.out.println("Customer Type :"+atype);
System.out.println("Total Reading :"+reading);
System.out.println("Total Amount : Rs."+bamount);
}
}
public class EBBill
{
}
catch(Exception ee)
{
System.out.println("Read Error");
}
}
}
OUTPUT
G:\R17OOPSLAB\progs>java EBBill
Enter the Customer No
1
Enter the Customer Name
sivakumar
Previous Month Reading
200
Current Month Reading
280
Account Type
domestic
Electricity Bill
________________
G:\R17OOPSLAB\progs>java EBBill
Enter the Customer No
1
Enter the Customer Name
siva
Previous Month Reading
200
Current Month Reading
450
Account Type
domestic
Electricity Bill
________________
G:\R17OOPSLAB\progs>
G:\R17OOPSLAB\progs>java EBBill
Enter the Customer No
1
Enter the Customer Name
siva
Previous Month Reading
200
Current Month Reading
450
Account Type
commercial
Electricity Bill
________________
G:\R17OOPSLAB\progs>java EBBill
Enter the Customer No
1
Enter the Customer Name
siva
Previous Month Reading
200
Current Month Reading
312
Account Type
jfdlj
Invalid Customer Tpe
G:\R17OOPSLAB\progs>
Exp. No. 2. Develop a java application to implement currency converter (Dollar to INR, EURO to INR, Yen to INR and vice versa), distance converter (meter to KM,
miles to KM and vice versa) , time converter (hours to minutes, seconds and vice versa) using packages.
PROGRAM
package myconverter;
import java.text.*;
class INRtoDOLLAR
{
double value;
class DOLLARtoINR
{
double value;
class INRtoEURO
{
double value;
class EUROtoINR
{
double value;
class INRtoYEN
{
double value;
class YENtoINR
{
double value;
class MILEtoKM
{
double value;
class KMtoMILE
{
double value;
class HOURStoMINUTES
{
double value;
}
}
class MINUTEStoHOURS
{
double value;
class HOURStoSECONDS
{
double value;
class SECONDStoHOURS
{
double value;
import myconverter.*;
class Convert
{
public static void main(String str[])
{
int r=500,d=54,y=350,e=250,h=2,m=324,s=1200,mile=7,km=270;
G:\R17OOPSLAB\progs>java Convert
The Rs. 500 = USD 7.326007326007326
The USD 54 = Rs.3685.5
The Rs. 500 = EURO 6.242197253433209
The EURO 250 = Rs.20025.0
The Rs. 500 = YEN 260.4166666666667
The YEN 350 = Rs.672.0
The 7Mile = 11.200000000000001 KM
The 270 KM = 168.75 Mile
2 Hours = 120.0 Minutes
324 Minutes = 5.4 Hours
2 Hours = 7200.0 Seconcds
1200 Seconds = 5.4 Hours
G:\R17OOPSLAB\progs>
Exp. No. 3. Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id, Mobile_no as members. Inherit the classes, Programmer,
Assistant Professor, Associate Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the inherited classes with 97% of BP as DA, 10
% of BP as HRA, 12% of BP as PF, 0.1% of BP for staff club fund. Generate pay slips for the employees with their gross and net salary.
PROGRAM
import java.io.*;
import java.util.*;
class Employee
{
String ename;
int eid;
String eaddr;
String email;
String emobile;
public void getempdata()
{
Scanner sc= new Scanner(System.in);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("Enter Employee Name ");
ename=br.readLine();
System.out.println("Enter Employee Id ");
eid=sc.nextInt();
System.out.println("Enter Address of Employee ");
eaddr=br.readLine();
System.out.println("Enter E-Mail Id ");
email=br.readLine();
System.out.println("Enter Mobile Nummber ");
emobile=br.readLine();
}
catch(IOException ie)
{
System.out.println(ie);
}
}
}
class Programmer extends Employee
{
int bpay;
double hra;
double da;
double pf;
double sclub;
double gross;
double net;
public Programmer(int pay)
{
bpay=pay;
}
public void calculate()
{
da=bpay*.97;
hra=bpay*.10;
pf=bpay*.12;
sclub=bpay*.01;
gross=bpay+da+hra;
net=gross-(pf+sclub);
}
System.out.println("Employee Id : "+eid);
System.out.println("PF: "+pf);
System.out.println("Staff Club : "+sclub);
System.out.println("Gross Pay : "+gross);
System.out.println("Net Pay : "+net);
}
}
class Inherit2
{
public static void main(String str[])
{
Programmer pr=new Programmer(6000);
AssistantProfessor ap=new AssistantProfessor(16500);
AssociateProfessor asp=new AssociateProfessor(34500);
Professor p= new Professor(36000);
System.out.println("Pay Bill for Programmer ");
pr.getempdata();
pr.calculate();
pr.displaybill();
OUTPUT
G:\R17OOPSLAB\progs>java Inherit2
Pay Bill for Programmer
Enter Employee Name
SIVAKUMAR
Enter Employee Id
1
Enter Address of Employee
PERUNDURAI
Enter E-Mail Id
sivakumar.g@esec.ac.in
Enter Mobile Nummber
9994244540
Employee Name : SIVAKUMAR
Employee Id : 1
Address of Employee :PERUNDURAI
E-Mail Id sivakumar.g@esec.ac.in
Mobile Nummber 9994244540
Basic Pay : 6000
HRA : 600.0
DA : 5820.0
PF: 720.0
Staff Club : 60.0
Gross Pay : 12420.0
Net Pay : 11640.0
Pay Bill for Assistant Professor
Enter Employee Name
SENTHILKUMAR
Enter Employee Id
2
Enter Address of Employee
CHENNAI
Enter E-Mail Id
senthil@gmail.com
Enter Mobile Nummber
9994244541
Employee Name : SENTHILKUMAR
Employee Id : 2
Address of Employee :CHENNAI
E-Mail Id senthil@gmail.com
Mobile Nummber 9994244541
Basic Pay : 16500
HRA : 1650.0
DA : 16005.0
PF: 1980.0
Staff Club : 165.0
Gross Pay : 34155.0
Net Pay : 32010.0
Pay Bill for Associate Professor
Enter Employee Name
KANNAN
Enter Employee Id
3
Enter Address of Employee
ERODE
Enter E-Mail Id
kannan@gmail.com
Enter Mobile Nummber
9994244542
Employee Name : KANNAN
Employee Id : 3
Address of Employee :ERODE
E-Mail Id kannan@gmail.com
Mobile Nummber 9994244542
Basic Pay : 34500
HRA : 3450.0
DA : 33465.0
PF: 4140.0
Staff Club : 345.0
Gross Pay : 71415.0
Net Pay : 66930.0
Pay Bill for Professor
Enter Employee Name
MURALI
Enter Employee Id
4
Enter Address of Employee
SALEM
Enter E-Mail Id
muralik@gmail.com
Enter Mobile Nummber
9994244543
Employee Name : MURALI
Employee Id : 4
Address of Employee :SALEM
E-Mail Id muralik@gmail.com
Mobile Nummber 9994244543
Basic Pay : 36000
HRA : 3600.0
DA : 34920.0
PF: 4320.0
Staff Club : 360.0
Gross Pay : 74520.0
Net Pay : 69840.0
G:\R17OOPSLAB\progs>
Exp. No. 4. Design a Java interface for ADT Stack. Implement this interface using array. Provide necessary exception handling in both the implementations.
PROGRAM
interface StackI {
boolean isEmpty();
this.msg=title;
return "StackError:"+msg;
this.msg=title;
return "StackError:"+msg;
StackImpl(int size)
tos = -1;
else
{
ESEC/CSE/III SEMESTER B.E. CSE 14
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
stck[++tos] = item;
if(tos < 0)
else
return stck[tos--];
if(tos<0)
return true;
else
return false;
class StackTest {
try
catch(StackOverflow sov)
System.out.println(sov);
try
System.out.println("Items in mystack1:");
System.out.println(mystack1.pop());
System.out.println("Items in mystack2:");
System.out.println(mystack2.pop());
}
ESEC/CSE/III SEMESTER B.E. CSE 15
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
catch(StackUnderflow suf)
System.out.println(suf);
if(mystack1.isEmpty())
if(mystack2.isEmpty())
OUTPUT
G:\R17OOPSLAB\progs>java StackTest
Capacity of Stack1 is 5
Item 0 Pushed
Item 1 Pushed
Item 2 Pushed
Item 3 Pushed
Item 4 Pushed
Capacity of Stack2 is 8
Item 0 Pushed
Item 1 Pushed
Item 2 Pushed
Item 3 Pushed
Item 4 Pushed
Item 5 Pushed
Item 6 Pushed
Item 7 Pushed
StackError:Stack Overflow
Items in mystack1:
4
3
2
1
0
Items in mystack2:
7
6
5
4
3
2
1
0
StackError:Stack underflow.
The stack1 is empty
The stack2 is empty
G:\R17OOPSLAB\progs>
Exp. No. 5. Write a program to perform string operations using ArrayList. Write functions for the following
PROGRAM
import java.io.*;
import java.util.*;
class StringOp
{
public static void main(String args[]) throws IOException
{
int ch=0;
String str=null;
ArrayList<String> al= new ArrayList<String>();
do
{
System.out.println("String Operations using ArrayList");
System.out.println("1. Append - add at end ");
System.out.println("2. Insert at particular index");
System.out.println("3. Search");
System.out.println("4. List all string starts with given letter");
System.out.println("5. Exit");
System.out.println("Enter your Choice :");
Scanner sc= new Scanner(System.in);
ch=sc.nextInt();
switch(ch)
{
case 1:
try
{
System.out.println("Enter the String to be appended at end :");
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
}
catch(IOException ie)
{
System.out.println(ie);
}
al.add(str);
System.out.println("Item Added at the end");
break;
case 2:
System.out.println("Enter the Position: ");
try
{
break;
case 4:
System.out.println("The elements of array list are ");
System.out.println(al);
break;
}
}while (ch>0 && ch<5);
}
}
OUTPUT
G:\R17OOPSLAB\progs>javac StringOp.java
G:\R17OOPSLAB\progs>java StringOp
String Operations using ArrayList
1. Append - add at end
2. Insert at particular index
3. Search
4. List all string starts with given letter
5. Exit
Enter your Choice :
1
Enter the String to be appended at end :
siva
Item Added at the end
String Operations using ArrayList
1. Append - add at end
2. Insert at particular index
3. Search
4. List all string starts with given letter
5. Exit
Enter your Choice :
1
Enter the String to be appended at end :
senthil
Item Added at the end
String Operations using ArrayList
1. Append - add at end
2. Insert at particular index
3. Search
4. List all string starts with given letter
5. Exit
Enter your Choice :
1
G:\R17OOPSLAB\progs>
Exp. No.6. Write a Java Program to create an abstract class named Shape that contains two integers and an empty method named print Area(). Provide three
classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method print
Area () that prints the area of the given shape.
PROGRAM
abstract class Shape
{
int no1,no2;
public abstract void printArea();
}
class Rectangle extends Shape
{
public Rectangle(int h,int w)
{
no1=h;
no2=w;
}
public void printArea()
{
System.out.println("Area of Rectangle is "+ (no1*no2));
}
}
class Circle extends Shape
{
public Circle(int r)
{
no1=r;
}
public void printArea()
{
System.out.println("Area of Circle is "+ (3.14*no1*no1));
}
}
class Inherit1
{
public static void main(String str[])
{
Rectangle r= new Rectangle(3,4);
r.printArea();
Circle c= new Circle(5);
c.printArea();
Triangle t= new Triangle(3,4);
t.printArea();
}
}
OUTPUT
G:\R17OOPSLAB\progs>java Inherit1
Area of Rectangle is 12
Area of Circle is 78.5
Area of Triangle is 6
Exp. No. 7. Write a Java program to implement user defined exception handling.
PROGRAM
import java.io.*;
{
String str;
public MobileNumberException(String test)
{
str=test;
}
public String toString()
{
return "MobileNumberException : The Mobile Number has only "+str.length()+" digits / Contains Characters";
}
}
class MobileExp
{
public static void main(String str[])
{
String num=null;
try
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Mobile Number ");
num=br.readLine();
}
catch(IOException ie)
{
System.out.println("IO Error " +ie);
}
try
{
if(num.length()==10 && num.matches("[0-9]+"))
System.out.println("Correct Mobile Number");
else
throw new MobileNumberException(num);
}
catch(MobileNumberException me)
{
System.out.println(me);
}
}
}
OUTPUT
G:\R17OOPSLAB\progs>javac MobileExp.java
G:\R17OOPSLAB\progs>java MobileExp
9994244540
G:\R17OOPSLAB\progs>java MobileExp
9382
G:\R17OOPSLAB\progs>java MobileExp
abdef
G:\R17OOPSLAB\progs>
ESEC/CSE/III SEMESTER B.E. CSE 21
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
Exp. No. 8. Write a Java program that reads a file name from the user, displays information about whether the file exists, whether the file is readable, or writable,
the type of file and the length of the file in bytes.
PROGRAM
import java.io.*;
import java.util.*;
class FileDetails
{
public static void main(String str[])
{
String fname=null;
try
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter File Name ");
fname=br.readLine();
}
catch(IOException ie)
{
System.out.println("IO Error " +ie);
}
File f= new File(fname);
if(f.exists())
System.out.println("File Exists");
else
System.out.println("File Not Available");
if(f.canWrite())
System.out.println("File has Write Permission");
if(f.canRead())
System.out.println("File has Read Permission");
if(f.canExecute())
System.out.println("File has Execute Permission");
System.out.println("File size is :"+f.length());
System.out.println("Last Modified Date :"+new Date(f.lastModified()));
}
}
OUTPUT
G:\R17OOPSLAB\progs>javac FileDetails.java
G:\R17OOPSLAB\progs>java FileDetails
EBBill.java
File Exists
G:\R17OOPSLAB\progs>
Exp. No. 9. Write a java program that implements a multi-threaded application that has three threads. First thread generates a random integer every 1 second and
if the value is even, second thread computes the square of the number and prints. If the value is odd, the third thread will print the value of cube of the number.
PROGRAM
import java.util.*;
class SquareThread extends Thread
{
public int n;
public SquareThread(int no)
{
this.n = no;
System.out.println("Square Thread Started");
start();
}
public void run()
{
System.out.println("The Square of the Random Number " + n + " is "+(n*n));
}
}
class CubeThread extends Thread
{
public int n;
public CubeThread(int no)
{
this.n = no;
System.out.println("Cube Thread Started");
start();
}
public void run()
{
System.out.println("The Cube of the Random Number " + n + " is "+(n*n*n));
}
}
class RandThread extends Thread
{
public RandThread()
{
start();
}
public void run()
{
int v = 0;
Random r = new Random();
try
{
for (int i = 1; i<=10; i++)
{
v = r.nextInt(100);
System.out.println("Generated Random Number is " + v);
if (v % 2 == 0)
new SquareThread(v);
else
new CubeThread(v);
Thread.sleep(1000);
}
}
catch (InterruptedException e)
{
System.out.println("Randon Number Thread Interrupted");
}
}
}
public class MultiThreadDemo
{
OUTPUT
G:\R17OOPSLAB\progs>java MultiThreadDemo
Generated Random Number is 25
Cube Thread Started
The Cube of the Random Number 25 is 15625
Generated Random Number is 96
Square Thread Started
The Square of the Random Number 96 is 9216
Generated Random Number is 84
Square Thread Started
The Square of the Random Number 84 is 7056
Generated Random Number is 45
Cube Thread Started
The Cube of the Random Number 45 is 91125
Generated Random Number is 92
Square Thread Started
The Square of the Random Number 92 is 8464
Generated Random Number is 40
Square Thread Started
The Square of the Random Number 40 is 1600
Generated Random Number is 90
Square Thread Started
The Square of the Random Number 90 is 8100
Generated Random Number is 56
Square Thread Started
The Square of the Random Number 56 is 3136
Generated Random Number is 30
Square Thread Started
The Square of the Random Number 30 is 900
Generated Random Number is 86
Square Thread Started
The Square of the Random Number 86 is 7396
G:\R17OOPSLAB\progs>
Exp. No. 10. Write a java program to find the maximum value from the given type of elements using a generic function.
PROGRAM
import java.util.*;
class Generic1{
findMax( intArray );
findMax( charArray );
findMax(doubleArray);
}
}
OUTPUT
G:\R17OOPSLAB\progs>javac Generic1.java
G:\R17OOPSLAB\progs>java Generic1
The Maximum Element is 50
The Maximum Element is V
The Maximum Element is 22.5
G:\R17OOPSLAB\progs>
Exp. No. 11. Design a calculator using event-driven programming paradigm of Java with the following options.
a) Decimal manipulations
b) Scientific manipulations
PROGRAM
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
ScientificCalculator() {
cont = getContentPane();
cont.setLayout(new BorderLayout());
JPanel textpanel = new JPanel();
tfield = new JTextField(25);
tfield.setHorizontalAlignment(SwingConstants.RIGHT);
tfield.addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent keyevent) {
char c = keyevent.getKeyChar();
if (c >= '0' && c <= '9') {
} else {
keyevent.consume();
}
}
});
textpanel.add(tfield);
buttonpanel = new JPanel();
buttonpanel.setLayout(new GridLayout(8, 4, 2, 2));
boolean t = true;
b1 = new JButton("1");
buttonpanel.add(b1);
b1.addActionListener(this);
b2 = new JButton("2");
buttonpanel.add(b2);
b2.addActionListener(this);
b3 = new JButton("3");
buttonpanel.add(b3);
b3.addActionListener(this);
b4 = new JButton("4");
buttonpanel.add(b4);
b4.addActionListener(this);
b5 = new JButton("5");
buttonpanel.add(b5);
b5.addActionListener(this);
b6 = new JButton("6");
buttonpanel.add(b6);
b6.addActionListener(this);
b7 = new JButton("7");
buttonpanel.add(b7);
b7.addActionListener(this);
b8 = new JButton("8");
ESEC/CSE/III SEMESTER B.E. CSE 26
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
buttonpanel.add(b8);
b8.addActionListener(this);
b9 = new JButton("9");
buttonpanel.add(b9);
b9.addActionListener(this);
eq = new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);
tfield.setText("");
tfield.setText(tfield.getText() + "5");
z = 0;
}
}
if (s.equals("6")) {
if (z == 0) {
tfield.setText(tfield.getText() + "6");
} else {
tfield.setText("");
tfield.setText(tfield.getText() + "6");
z = 0;
}
}
if (s.equals("7")) {
if (z == 0) {
tfield.setText(tfield.getText() + "7");
} else {
tfield.setText("");
tfield.setText(tfield.getText() + "7");
z = 0;
}
}
if (s.equals("8")) {
if (z == 0) {
tfield.setText(tfield.getText() + "8");
} else {
tfield.setText("");
tfield.setText(tfield.getText() + "8");
z = 0;
}
}
if (s.equals("9")) {
if (z == 0) {
tfield.setText(tfield.getText() + "9");
} else {
tfield.setText("");
tfield.setText(tfield.getText() + "9");
z = 0;
}
}
if (s.equals("0")) {
if (z == 0) {
tfield.setText(tfield.getText() + "0");
} else {
tfield.setText("");
tfield.setText(tfield.getText() + "0");
z = 0;
}
}
if (s.equals("AC")) {
tfield.setText("");
x = 0;
y = 0;
z = 0;
}
if (s.equals("log")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
ESEC/CSE/III SEMESTER B.E. CSE 29
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
a=
Math.log(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("1/x")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=1/
Double.parseDouble(tfield.getText());
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("Exp")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.exp(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("x^2")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.pow(Double.parseDouble(tfield.getText()), 2);
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("x^3")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.pow(Double.parseDouble(tfield.getText()), 3);
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("+/-")) {
if (x == 0) {
tfield.setText("-" + tfield.getText());
x = 1;
} else {
tfield.setText(tfield.getText());
}
}
if (s.equals(".")) {
if (y == 0) {
tfield.setText(tfield.getText() + ".");
y = 1;
} else {
tfield.setText(tfield.getText());
}
}
if (s.equals("+")) {
if (tfield.getText().equals("")) {
tfield.setText("");
temp = 0;
ch = '+';
} else {
temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '+';
y = 0;
x = 0;
}
tfield.requestFocus();
}
if (s.equals("-")) {
if (tfield.getText().equals("")) {
tfield.setText("");
temp = 0;
ch = '-';
} else {
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '-';
}
tfield.requestFocus();
}
if (s.equals("/")) {
if (tfield.getText().equals("")) {
tfield.setText("");
temp = 1;
ch = '/';
} else {
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
ch = '/';
tfield.setText("");
}
tfield.requestFocus();
}
if (s.equals("*")) {
if (tfield.getText().equals("")) {
tfield.setText("");
temp = 1;
ch = '*';
} else {
x = 0;
y = 0;
temp = Double.parseDouble(tfield.getText());
ch = '*';
tfield.setText("");
ESEC/CSE/III SEMESTER B.E. CSE 31
CS8383 OBJECT ORIENTED PROGRAMMING LAB LAB MANUAL
}
tfield.requestFocus();
}
if (s.equals("MC")) {
m1 = 0;
tfield.setText("");
}
if (s.equals("MR")) {
tfield.setText("");
tfield.setText(tfield.getText() + m1);
}
if (s.equals("M+")) {
if (k == 1) {
m1 = Double.parseDouble(tfield.getText());
k++;
} else {
m1 += Double.parseDouble(tfield.getText());
tfield.setText("" + m1);
}
}
if (s.equals("M-")) {
if (k == 1) {
m1 = Double.parseDouble(tfield.getText());
k++;
} else {
m1 -= Double.parseDouble(tfield.getText());
tfield.setText("" + m1);
}
}
if (s.equals("Sqrt")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.sqrt(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("SIN")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.sin(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("COS")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.cos(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("TAN")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
Math.tan(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
if (s.equals("=")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
temp1 =
Double.parseDouble(tfield.getText());
switch (ch) {
case '+':
result = temp + temp1;
break;
case '-':
result = temp - temp1;
break;
case '/':
result = temp / temp1;
break;
case '*':
result = temp * temp1;
break;
}
tfield.setText("");
tfield.setText(tfield.getText() + result);
z = 1;
}
}
if (s.equals("n!")) {
if (tfield.getText().equals("")) {
tfield.setText("");
} else {
a=
fact(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}
}
tfield.requestFocus();
}
double fact(double x) {
int er = 0;
if (x < 0) {
er = 20;
return 0;
}
double i, s = 1;
.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
}
ScientificCalculator f = new ScientificCalculator();
f.setTitle("ScientificCalculator");
f.pack();
f.setVisible(true);
}
}
OUTPUT
12. Develop a mini project for any application using Java concepts.
import java.util.Date;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class FileOperation
{
Notepad npd;
boolean saved;
boolean newFileFlag;
String fileName;
String applicationTitle="Notepad - JavaTpoint";
File fileRef;
JFileChooser chooser;
boolean isSave(){return saved;}
void setSave(boolean saved){this.saved=saved;}
String getFileName(){return new String(fileName);}
void setFileName(String fileName){this.fileName=new String(fileName);}
FileOperation(Notepad npd)
{
this.npd=npd;
saved=true;
newFileFlag=true;
fileName=new String("Untitled");
fileRef=new File(fileName);
this.npd.f.setTitle(fileName+" - "+applicationTitle);
chooser=new JFileChooser();
chooser.addChoosableFileFilter(new MyFileFilter(".java","Java Source Files(*.java)"));
chooser.addChoosableFileFilter(new MyFileFilter(".txt","Text Files(*.txt)"));
chooser.setCurrentDirectory(new File("."));
if(!newFileFlag)
{return saveFile(fileRef);}
return saveAsFile();
}
boolean saveAsFile()
{
File temp=null;
chooser.setDialogTitle("Save As...");
chooser.setApproveButtonText("Save Now");
chooser.setApproveButtonMnemonic(KeyEvent.VK_S);
chooser.setApproveButtonToolTipText("Click me to save!");
do
{
if(chooser.showSaveDialog(this.npd.f)!=JFileChooser.APPROVE_OPTION)
return false;
temp=chooser.getSelectedFile();
if(!temp.exists()) break;
if( JOptionPane.showConfirmDialog(
this.npd.f,"<html>"+temp.getPath()+" already exists.<br>Do you want to replace it?<html>",
"Save As",JOptionPane.YES_NO_OPTION
)==JOptionPane.YES_OPTION)
break;
}while(true);
return saveFile(temp);
}
try
{
fin=new FileInputStream(temp);
din=new BufferedReader(new InputStreamReader(fin));
String str=" ";
while(str!=null)
{
str=din.readLine();
if(str==null)
break;
this.npd.ta.append(str+"\n");
}
}
catch(IOException ioe){updateStatus(temp,false);return false;}
finally
{try{din.close();fin.close();}catch(IOException excp){}}
updateStatus(temp,true);
this.npd.ta.setCaretPosition(0);
return true;
}
void openFile()
{
if(!confirmSave()) return;
chooser.setDialogTitle("Open File...");
chooser.setApproveButtonText("Open this");
chooser.setApproveButtonMnemonic(KeyEvent.VK_O);
chooser.setApproveButtonToolTipText("Click me to open the selected file.!");
File temp=null;
do
{
if(chooser.showOpenDialog(this.npd.f)!=JFileChooser.APPROVE_OPTION)
return;
temp=chooser.getSelectedFile();
if(temp.exists()) break;
JOptionPane.showMessageDialog(this.npd.f,
"<html>"+temp.getName()+"<br>file not found.<br>"+
"Please verify the correct file name was given.<html>",
"Open", JOptionPane.INFORMATION_MESSAGE);
} while(true);
this.npd.ta.setText("");
if(!openFile(temp))
{
fileName="Untitled"; saved=true;
this.npd.f.setTitle(fileName+" - "+applicationTitle);
}
if(!temp.canWrite())
newFileFlag=true;
this.npd.ta.setText("");
fileName=new String("Untitled");
fileRef=new File(fileName);
saved=true;
newFileFlag=true;
this.npd.f.setTitle(fileName+" - "+applicationTitle);
}
}// end defination of class FileOperation
/************************************/
public class Notepad implements ActionListener, MenuConstants
{
JFrame f;
JTextArea ta;
JLabel statusBar;
String applicationName="Javapad";
FileOperation fileHandler;
FontChooser fontDialog=null;
FindDialog findReplaceDialog=null;
JColorChooser bcolorChooser=null;
JColorChooser fcolorChooser=null;
JDialog backgroundDialog=null;
JDialog foregroundDialog=null;
JMenuItem cutItem,copyItem, deleteItem, findItem, findNextItem,
replaceItem, gotoItem, selectAllItem;
Notepad()
{
f=new JFrame(fileName+" - "+applicationName);
ta=new JTextArea(30,60);
statusBar=new JLabel("|| Ln 1, Col 1 ",JLabel.RIGHT);
f.add(new JScrollPane(ta),BorderLayout.CENTER);
f.add(statusBar,BorderLayout.SOUTH);
f.add(new JLabel(" "),BorderLayout.EAST);
f.add(new JLabel(" "),BorderLayout.WEST);
createMenuBar(f);
//f.setSize(350,350);
f.pack();
f.setLocation(100,50);
f.setVisible(true);
f.setLocation(150,50);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
fileHandler=new FileOperation(this);
ta.addCaretListener(
new CaretListener()
{
public void caretUpdate(CaretEvent e)
{
int lineNumber=0, column=0, pos=0;
try
{
pos=ta.getCaretPosition();
lineNumber=ta.getLineOfOffset(pos);
column=pos-ta.getLineStartOffset(lineNumber);
}catch(Exception excp){}
if(ta.getText().length()==0){lineNumber=0; column=0;}
statusBar.setText("|| Ln "+(lineNumber+1)+", Col "+(column+1));
}
});
DocumentListener myListener = new DocumentListener()
{
public void changedUpdate(DocumentEvent e){fileHandler.saved=false;}
public void removeUpdate(DocumentEvent e){fileHandler.saved=false;}
public void insertUpdate(DocumentEvent e){fileHandler.saved=false;}
};
ta.getDocument().addDocumentListener(myListener);
WindowListener frameClose=new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
if(fileHandler.confirmSave())System.exit(0);
}
};
f.addWindowListener(frameClose);
//////////////////
/*
if(findReplaceDialog==null)
statusBar.setText("Use Find option of Edit Menu first !!!!");
else
findReplaceDialog.findNextWithSelection();
}
else if(cmdText.equals(editReplace))
{
if(Notepad.this.ta.getText().length()==0)
return; // text box have no text
if(findReplaceDialog==null)
findReplaceDialog=new FindDialog(Notepad.this.ta);
findReplaceDialog.showDialog(Notepad.this.f,false);//replace
}
else if(cmdText.equals(editGoTo))
{
if(Notepad.this.ta.getText().length()==0)
return; // text box have no text
goTo();
}
else if(cmdText.equals(editSelectAll))
ta.selectAll();
else if(cmdText.equals(editTimeDate))
ta.insert(new Date().toString(),ta.getSelectionStart());
else if(cmdText.equals(formatWordWrap))
{
JCheckBoxMenuItem temp=(JCheckBoxMenuItem)ev.getSource();
ta.setLineWrap(temp.isSelected());
}
////////////////////////////////////
else if(cmdText.equals(formatFont))
{
if(fontDialog==null)
fontDialog=new FontChooser(ta.getFont());
if(fontDialog.showDialog(Notepad.this.f,"Choose a font"))
Notepad.this.ta.setFont(fontDialog.createFont());
}
////////////////////////////////////
else if(cmdText.equals(formatForeground))
showForegroundColorDialog();
////////////////////////////////////
else if(cmdText.equals(formatBackground))
showBackgroundColorDialog();
////////////////////////////////////
else if(cmdText.equals(viewStatusBar))
{
JCheckBoxMenuItem temp=(JCheckBoxMenuItem)ev.getSource();
statusBar.setVisible(temp.isSelected());
}
////////////////////////////////////
else if(cmdText.equals(helpAboutNotepad))
{
JOptionPane.showMessageDialog(Notepad.this.f,aboutText,"Dedicated 2 u!",
JOptionPane.INFORMATION_MESSAGE);
}
else
statusBar.setText("This "+cmdText+" command is yet to be implemented");
}//action Performed
void showBackgroundColorDialog()
{
if(bcolorChooser==null)
bcolorChooser=new JColorChooser();
if(backgroundDialog==null)
backgroundDialog=JColorChooser.createDialog
(Notepad.this.f,
formatBackground,
false,
bcolorChooser,
new ActionListener()
backgroundDialog.setVisible(true);
}
void showForegroundColorDialog()
{
if(fcolorChooser==null)
fcolorChooser=new JColorChooser();
if(foregroundDialog==null)
foregroundDialog=JColorChooser.createDialog
(Notepad.this.f,
formatForeground,
false,
fcolorChooser,
new ActionListener()
{public void actionPerformed(ActionEvent evvv){
Notepad.this.ta.setForeground(fcolorChooser.getColor());}},
null);
foregroundDialog.setVisible(true);
}
return temp;
}
JMenuItem createMenuItem(String s, int key,JMenu toMenu,int aclKey,ActionListener al)
{
JMenuItem temp=new JMenuItem(s,key);
temp.addActionListener(al);
temp.setAccelerator(KeyStroke.getKeyStroke(aclKey,ActionEvent.CTRL_MASK));
toMenu.add(temp);
return temp;
}
JCheckBoxMenuItem createCheckBoxMenuItem(String s,
int key,JMenu toMenu,ActionListener al)
{
JCheckBoxMenuItem temp=new JCheckBoxMenuItem(s);
temp.setMnemonic(key);
temp.addActionListener(al);
temp.setSelected(false);
toMenu.add(temp);
return temp;
}
JMenu createMenu(String s,int key,JMenuBar toMenuBar)
{
JMenu temp=new JMenu(s);
temp.setMnemonic(key);
toMenuBar.add(temp);
return temp;
}
/*********************************/
void createMenuBar(JFrame f)
{
JMenuBar mb=new JMenuBar();
JMenuItem temp;
JMenu fileMenu=createMenu(fileText,KeyEvent.VK_F,mb);
JMenu editMenu=createMenu(editText,KeyEvent.VK_E,mb);
JMenu formatMenu=createMenu(formatText,KeyEvent.VK_O,mb);
JMenu viewMenu=createMenu(viewText,KeyEvent.VK_V,mb);
JMenu helpMenu=createMenu(helpText,KeyEvent.VK_H,mb);
createMenuItem(fileNew,KeyEvent.VK_N,fileMenu,KeyEvent.VK_N,this);
createMenuItem(fileOpen,KeyEvent.VK_O,fileMenu,KeyEvent.VK_O,this);
createMenuItem(fileSave,KeyEvent.VK_S,fileMenu,KeyEvent.VK_S,this);
createMenuItem(fileSaveAs,KeyEvent.VK_A,fileMenu,this);
fileMenu.addSeparator();
temp=createMenuItem(filePageSetup,KeyEvent.VK_U,fileMenu,this);
temp.setEnabled(false);
createMenuItem(filePrint,KeyEvent.VK_P,fileMenu,KeyEvent.VK_P,this);
fileMenu.addSeparator();
createMenuItem(fileExit,KeyEvent.VK_X,fileMenu,this);
temp=createMenuItem(editUndo,KeyEvent.VK_U,editMenu,KeyEvent.VK_Z,this);
temp.setEnabled(false);
editMenu.addSeparator();
cutItem=createMenuItem(editCut,KeyEvent.VK_T,editMenu,KeyEvent.VK_X,this);
copyItem=createMenuItem(editCopy,KeyEvent.VK_C,editMenu,KeyEvent.VK_C,this);
createMenuItem(editPaste,KeyEvent.VK_P,editMenu,KeyEvent.VK_V,this);
deleteItem=createMenuItem(editDelete,KeyEvent.VK_L,editMenu,this);
deleteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));
editMenu.addSeparator();
findItem=createMenuItem(editFind,KeyEvent.VK_F,editMenu,KeyEvent.VK_F,this);
findNextItem=createMenuItem(editFindNext,KeyEvent.VK_N,editMenu,this);
findNextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,0));
replaceItem=createMenuItem(editReplace,KeyEvent.VK_R,editMenu,KeyEvent.VK_H,this);
gotoItem=createMenuItem(editGoTo,KeyEvent.VK_G,editMenu,KeyEvent.VK_G,this);
editMenu.addSeparator();
selectAllItem=createMenuItem(editSelectAll,KeyEvent.VK_A,editMenu,KeyEvent.VK_A,this);
createMenuItem(editTimeDate,KeyEvent.VK_D,editMenu,this)
.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
createCheckBoxMenuItem(formatWordWrap,KeyEvent.VK_W,formatMenu,this);
createMenuItem(formatFont,KeyEvent.VK_F,formatMenu,this);
formatMenu.addSeparator();
createMenuItem(formatForeground,KeyEvent.VK_T,formatMenu,this);
createMenuItem(formatBackground,KeyEvent.VK_P,formatMenu,this);
createCheckBoxMenuItem(viewStatusBar,KeyEvent.VK_S,viewMenu,this).setSelected(true);
/************For Look and Feel***/
LookAndFeelMenu.createLookAndFeelMenuItem(viewMenu,this.f);
temp=createMenuItem(helpHelpTopic,KeyEvent.VK_H,helpMenu,this);
temp.setEnabled(false);
helpMenu.addSeparator();
createMenuItem(helpAboutNotepad,KeyEvent.VK_A,helpMenu,this);
replaceItem.setEnabled(true);
selectAllItem.setEnabled(true);
gotoItem.setEnabled(true);
}
if(Notepad.this.ta.getSelectionStart()==ta.getSelectionEnd())
{
cutItem.setEnabled(false);
copyItem.setEnabled(false);
deleteItem.setEnabled(false);
}
else
{
cutItem.setEnabled(true);
copyItem.setEnabled(true);
deleteItem.setEnabled(true);
}
}
public void menuDeselected(MenuEvent evvvv){}
public void menuCanceled(MenuEvent evvvv){}
};
editMenu.addMenuListener(editMenuListener);
f.setJMenuBar(mb);
}
/*************Constructor**************/
////////////////////////////////////
public static void main(String[] s)
{
new Notepad();
}
}
/**************************************/
//public
interface MenuConstants
{
final String fileText="File";
final String editText="Edit";
final String formatText="Format";
final String viewText="View";
final String helpText="Help";
OUTPUT
13.Develop a simple OPAC system for library using even-driven and concurrent programming paradigms of Java. Use JDBC to connect to a back-end database.
Program
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class Library implements ActionListener
{
JRadioButton rbauthor = new JRadioButton("Search by Author Name");
JRadioButton rbbook = new JRadioButton("Search by Book Name");
JTextField textfld = new JTextField(30);
JLabel label = new JLabel("Enter Search Key");
JButton searchbutton = new JButton("Search");
JFrame frame = new JFrame();
JTable table;
DefaultTableModel model;
String query = "select * from library";
public Library()
{
frame.setTitle("Online Public Access Catalog(OPAC)");
frame.setSize(500,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
p1.setLayout(new FlowLayout());
p1.add(label);
p1.add(textfld);
p2.setLayout(new FlowLayout());
p2.add(rbauthor);
p2.add(rbbook);
p2.add(searchbutton);
searchbutton.addActionListener(this);
p3.setLayout(new BorderLayout());
p3.add(p1,BorderLayout.NORTH);
p3.add(p2,BorderLayout.CENTER);
frame.add(p3,BorderLayout.NORTH);
addTable(query);
frame.setVisible(true);
}
public void addTable(String s)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn =
DriverManager.getConnection("jdbc:odbc:Library","","");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(s);
ResultSetMetaData md = rs.getMetaData();
int cols = md.getColumnCount();
model = new DefaultTableModel(1,cols);
table = new JTable(model);
String[] tabledata = new String[cols];
int i=0;
while(i<cols)
{
tabledata[i] = md.getColumnName(i+1);
i++;
}
model.addRow(tabledata);
while(rs.next())
{
for(i=0;i<cols;i++)
tabledata[i] = rs.getObject(i+1).toString();
model.addRow(tabledata);
}
frame.add(table,BorderLayout.CENTER);
conn.close();
}catch(Exception e){}
}
public void actionPerformed(ActionEvent evt)
{
if(rbauthor.isSelected())
query = "select * from library where AuthorName like
'"+textfld.getText()+"%'";
if(rbbook.isSelected())
query = "select * from library where BookName like
'"+textfld.getText()+"%'";
while(model.getRowCount()>0)
model.removeRow(0);
frame.remove(table);
addTable(query);
}
public static void main(String[] args)
{
new Library();
}
OUTPUT
VIVA QUESTIONS
Java & Object Oriented Programming – Fundamentals
1. What is Abstraction?
2. What is Encapsulation?
3. What is the difference between abstraction and encapsulation?
4. What is Java?
5. What are the main features of java?
6. What is the Java Virtual Machine (JVM)?
7. What are the principle concepts of OOPS?
8. What are different types of access modifiers?
9. What is Byte Code?
10. Are JVM's platform independent?
11. How to define a constant variable in Java?
12. Why is the main method declared static?
13. What if the static modifier is removed from the signature of the main() method?
14. What if the main() method is declared as private?
15. What is the difference between a constructor and a method?
16. What is the purpose of garbage collection in Java, and when is it used?
17. What is an abstract class?
18. What is static in java?
19. What is final class?
20. What is the first argument of the String array in main() method?
21. Can an application have multiple classes having main() method?
22. What are wrapper classes?
23. What is the purpose of finalization?
24. How are this() and super() used with constructors?
25. What is the default value of the local variables?
26. How is final different from finally and finalize()?
27. What are the restriction imposed on a static method or a static block of code?
28. What modifiers can be used with a local inner class?
29. Which methods are used to destroy the objects created by the constructor methods?
30. Can an abstract class may be final?
31. Can there be an abstract class with no abstract methods in it?
32. What is static block?
33. What is Unicode?
34. Can you give few examples of final classes defined in Java API?
35. What are Inner Classes?
Inheritance
1. What is the base class of all classes?
2. Does Java support multiple inheritance?
3. What is Overriding?
4. What is Dynamic Binding?
5. How to invoke a superclass version of an Overridden method?
6. How do you prevent a method from being overridden?
7. What is the difference between method overriding and overloading?
8. What do you mean by polymorphism?
9. I don't want my class to be inherited by any other class. What should i do?
10. What is inheritance?
11. Which keyword is used to inherit a class?
12. When can subclasses not access superclass members?
13. Which method is used to call the constructors of the superclass from the subclass?
14. Can a class extnds more than one Class?
Event Handling
1. Difference between Swing and Awt?
2. What is an Applets?
3. What is the highest-level event class of the event-delegation model?
4. What class is the top of the AWT event hierarchy?
5. What event results from the clicking of a button?
6. In which package are most of the AWT events that support the event-delegation model defined?
7. What is the difference between a TextArea and a TextField?
8. What is the immediate super class of Applet class?
9. Which layout is used as their default layout by Window, Frame and Dialog classes?
10. Which event is generated when the position of a scrollbar is changed.
11. What is the difference between choice and list?
12. What is the difference between scrollbar and scrollpane?
13. Which containers use a Flow layout as their default layout?
Exception Handling
1. What are runtime exceptions?
2. What is the difference between error and an exception?
3. Is it necessary that each try block must be followed by a catch block?
4. What are the difference between throw and throws?
5. Does constructors throw exceptions?
6. What is difference between Checked Exception and Unchecked Exception?
7. What is the base class for Error and Exception?
8. What is finally block?
9. Can finally block be used without catch?
10. Can an exception be rethrown?
Threads
1. What is the difference between process and thread?
2. What are the benefits of multi-threaded programming?
3. How can we create a Thread in Java?
4. What are different states in lifecycle of Thread?
5. What is synchronization and why is it important?
6. What method must be implemented by all threads?
7. What invokes a thread's run() method?
8. What is the purpose of the wait(), notify(), and notifyAll() methods?
9. What’s the difference between the methods sleep() and wait()?
10. What is daemon thread and which method is used to create the daemon thread?
11. How can we pause the execution of a Thread for specific time?
12. What do you understand about Thread Priority?
13. What is the difference between yielding and sleeping?
14. What does join() method?
15. What is deadlock?
I/O Handling
1. What is serialization?
2. How do I serialize an object to a file?
3. What happens to the static fields of a class during serialization?
4. What is meant by Stream and what are the types of Streams and classes of the Streams?
5. How do I check for end-of-file when reading from a stream?
6. What class allows you to read objects directly from a stream?
7. What is the purpose of the System class?
8. What is the use of ByteArray Streams?
9. What is the use of PipedStreams?
10. Which is the super class for all the Input Stream classes?
11. Which is the super class for all the Output Stream classes?
12. What is the use of readLine() method?
13. How will you obtain size of the file?
14. What is the advantages of using Pushback streams?
15. Differentiate Character stream and Byte streams.