Practical No 8 to 14 Java
Practical No 8 to 14 Java
1321057
Practical No. 8
Aim: Write a program to demonstrate the use of stringtokenizer class.
Source Code:
import java.util.StringTokenizer;
while (tokenizer.hasMoreTokens()) {
System.out.println(token);
System.out.println("Hii, I am Badal");
while (csvTokenizer.hasMoreTokens()) {
System.out.println(token);
}
BCA - 4th (A) Roll No. 1321057
Output:
BCA - 4th (A) Roll No. 1321057
Practical No. 9
Aim: Write a program to implements applet in java.
Source Code:
HelloWorld.java
import java.applet.Applet;
import java.awt.Graphics;
HelloWorld.html
<html>
<head>
<title>Applet in java</title>
</head>
<body>
<applet code="HelloWorld" width=200 height=60>
</applet>
</body>
</html>
Output:
BCA - 4th (A) Roll No. 1321057
Practical No. 10
Aim: Write a program to apply the concept of exception handling in classes.
Source Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class ExceptionDemo {
try {
} catch (FileNotFoundException e) {
try {
int num1 =
= 0;
} catch (ArithmeticException e) {
try {
} catch (CustomException e) {
BCA - 4th (A) Roll No. 1321057
System.out.println(e.getMessage());
try {
} catch (NumberFormatException e) {
try {
} catch (ArrayIndexOutOfBoundsException e) {
} finally {
super(message);
}
BCA - 4th (A) Roll No. 1321057
Output:
BCA - 4th (A) Roll No. 1321057
Practical No. 11
Aim: Write a program to create a frame, button, text box, and label.
Source Code:
import javax.swing.*;
import java.awt.*;
class registration {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
30);
30);
JTextField(); lastNameField.setBounds(100,
frame.add(firstNameLabel);
frame.add(firstNameField);
BCA - 4th (A) Roll No. 1321057
frame.add(lastNameLabel);
frame.add(lastNameField);
frame.add(submitButton);
frame.setLayout(null);
frame.setVisible(true);
Output:
BCA - 4th (A) Roll No. 1321057
Practical No. 12
Aim: Write a program to create a button. When the button is click , an
appropriate message should be displayed in the dialog box.
Source Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class actionlistener {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
30);
30);
submitButton.addActionListener(new ActionListener() {
});
frame.add(firstNameLabel);
frame.add(firstNameField);
frame.add(lastNameLabel);
frame.add(lastNameField);
frame.add(submitButton);
frame.setLayout(null);
frame.setVisible(true);
}
BCA - 4th (A) Roll No. 1321057
Output:
BCA - 4th (A) Roll No. 1321057
String b;
copy()
{ a=1
1;
b="badal";
System.out.println(a+""+b);
copy(copy ref) {
a=ref.a;
b=ref.b;
System.out.print(a+" "+b);
class copcons {
} }
Output:
BCA - 4th (A) Roll No. 1321057
//Default Constructor
class boy{
int a;
Float b;
boy() {
a=10;
void display() {
System.out.print(a+" "+b);
class decons{
obj.display();
Output: