java apr2023 pdf
java apr2023 pdf
a) What is javadoc?
The javadoc tool is a document generator tool in Java for generating standard documentation in
HTML format.
A command-line argument is the information that directly follows the program's name on the
command line when it is executed.
c) Define Constructor.
A constructor is a special method of a class in Java programming that initializes an object of that
type.
1. Byte
2. Short
3. Integer
In Java, the extends keyword is used to create a subclass that inherits properties and methods
from a parent (or superclass).
1. NullPointerException
2. ArrayIndexOutOfBoundsException
3. ArithmeticException
4. IllegalArgumentException
You can use classes such as FileReader and BufferedReader for this purpose
i)What is AWT?
AWT, or the Abstract Window Toolkit, is a set of APIs provided by Java for creating graphical
user
1. MouseAdapter
2. KeyAdapter
A process in which a call to an overridden method is resolved at run-time rather than compile
time is known as run-time polymorphism.
a) Write a java program to copy the content from one file to another file, while copying change the
case of alphabets.
import java.io.*;
int c;
if (Character.isUpperCase(character)) {
writer.write(Character.toLowerCase(character));
} else if (Character.isLowerCase(character)) {
writer.write(Character.toUpperCase(character));
} else {
writer.write(character);
} catch (IOException e) {
e.printStackTrace();
}
b) Write a java program using swing to accept details of employee (eno, ename, esal) and display it
by clicking on a button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
txtDisplay.setEditable(false);
panel.add(lblEno);
panel.add(txtEno);
panel.add(lblEname);
panel.add(txtEname);
panel.add(lblEsal);
panel.add(txtEsal);
panel.add(btnDisplay);
panel.add(new JScrollPane(txtDisplay));
btnDisplay.addActionListener(new ActionListener() {
txtDisplay.setText(result);
});
frame.add(panel);
frame.setVisible(true);
c) Define abstract class shape with abstract method area (). Write a java program to calculate area
of circle.
abstract class Shape {
a) Write a java program to give Red colour at the background of TextField by clicking on a button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 200);
textField.setHorizontalAlignment(JTextField.CENTER);
JButton button = new JButton("Change Color");
button.addActionListener(new ActionListener() {
@Override
textField.setBackground(Color.RED);
});
frame.setLayout(new BorderLayout());
frame.add(textField, BorderLayout.CENTER);
frame.add(button, BorderLayout.SOUTH);
frame.setVisible(true);
Animal() {
System.out.println("Animal is created");
}
void eat() {
System.out.println("Animal is eating");
}
}
// Child class
class Dog extends Animal {
String color = "Black";
Dog() {
super(); // Calling the parent class constructor
System.out.println("Dog is created");
}
void displayColor() {
System.out.println("Dog color: " + color); // Child class variable
System.out.println("Animal color: " + super.color); // Parent class variable
}
void eat() {
System.out.println("Dog is eating");
}
void parentEat() {
super.eat(); // Calling the parent class method
}
}
2. charAt(int index): This method returns the character at the specified index.
3. substring(int beginIndex, int endIndex): This method returns a new string that is a
substring of the original string, starting from beginIndex and ending at endIndex
• Example:
public class StringExample {
public static void main(String[] args) {
String str = "Hello, World!";
// 1. length() method
int length = str.length();
System.out.println("Length of the string: " + length); // Output: 13