0% found this document useful (0 votes)
25 views

java apr2023 pdf

Uploaded by

gauravborkar262
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

java apr2023 pdf

Uploaded by

gauravborkar262
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Q1) Attempt any Eight of the following :

a) What is javadoc?

The javadoc tool is a document generator tool in Java for generating standard documentation in
HTML format.

b) What are command line argument?

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.

d) List any two wrapper classes.

1. Byte
2. Short
3. Integer

e) Write the use of extends key word.

In Java, the extends keyword is used to create a subclass that inherits properties and methods
from a parent (or superclass).

f) Define functional interface.

A functional interface is an interface that contains only one abstract method

g) List any two uncheck exception.

1. NullPointerException
2. ArrayIndexOutOfBoundsException
3. ArithmeticException
4. IllegalArgumentException

h) How to open file in read mode?

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

interfaces (GUIs) applications.

j) Give the names of any two Adaptor class.

1. MouseAdapter
2. KeyAdapter

Q2) Attempt any FOUR of the following :

a) Differentiate between String and StringBuffer class.

b) State any four features of java.

1. Simple: Java is a simple language


2. Object-oriented: Java is object-oriented language like C++, Python etc
3. Interactive: Java is called as interactive because code of Java supports CGI
4. Secure: Java is aimed to be used in networked or distributed environments.

c) What is polymorphism? How to implement it at compile time?

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.

and is implemented through method overloading or operator overloading

d) How to define and handle user defined exception?

Step 1: Define a Custom Exception

Step 2: Use and Handle the Custom Exception

e) What is listener? How to inherit it in program?


Q3) Attempt any TWO of the following :

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.*;

public class CopyFileWithCaseChange {

public static void main(String[] args) {

File inputFile = new File("input.txt");

File outputFile = new File("output.txt");

try (BufferedReader reader = new BufferedReader(new FileReader(inputFile));

BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {

int c;

while ((c = reader.read()) != -1) {

char character = (char) c;

if (Character.isUpperCase(character)) {

writer.write(Character.toLowerCase(character));

} else if (Character.isLowerCase(character)) {

writer.write(Character.toUpperCase(character));

} else {

writer.write(character);

System.out.println("Content copied and case changed successfully!");

} 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.*;

public class EmployeeDetails {

public static void main(String[] args) {

JFrame frame = new JFrame("Employee Details");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(300, 200);

JPanel panel = new JPanel();

panel.setLayout(new GridLayout(4, 2));

JLabel lblEno = new JLabel("Employee Number:");

JTextField txtEno = new JTextField();

JLabel lblEname = new JLabel("Employee Name:");

JTextField txtEname = new JTextField();

JLabel lblEsal = new JLabel("Employee Salary:");

JTextField txtEsal = new JTextField();

JButton btnDisplay = new JButton("Display");

JTextArea txtDisplay = new JTextArea();

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() {

public void actionPerformed(ActionEvent e) {

String eno = txtEno.getText();

String ename = txtEname.getText();

String esal = txtEsal.getText();

String result = "Employee Number: " + eno + "\n"

+ "Employee Name: " + ename + "\n"

+ "Employee Salary: " + esal;

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 {

abstract double area();

calculate area of circle.

public class Main {

public static void main(String[] args)

Circle circle = new Circle(5);

System.out.println("The area of the circle is: " + circle.area());

Q4) Attempt any Two of the following

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;

public class TextFieldBackgroundColor {

public static void main(String[] args) {

JFrame frame = new JFrame("Change Background Color");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(300, 200);

JTextField textField = new JTextField("Click the button to turn me red");

textField.setHorizontalAlignment(JTextField.CENTER);
JButton button = new JButton("Change Color");

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

textField.setBackground(Color.RED);

});

frame.setLayout(new BorderLayout());

frame.add(textField, BorderLayout.CENTER);

frame.add(button, BorderLayout.SOUTH);

frame.setVisible(true);

b) Explain the uses of super keyword with example.


Example:
// Parent class
class Animal {
String color = "White";

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
}
}

public class TestSuper {


public static void main(String[] args) {
Dog dog = new Dog();
dog.displayColor();
dog.eat();
dog.parentEat();
}
}

c) What is string? Explain its any three method with an example.


• A string in Java is an object that represents a sequence of characters
• Strings are widely used for storing and manipulating text data
• Types:

1. length(): This method returns the length of the string.

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

// 2. charAt(int index) method


char ch = str.charAt(7);
System.out.println("Character at index 7: " + ch); // Output: W

// 3. substring(int beginIndex, int endIndex) method


String substr = str.substring(7, 12);
System.out.println("Substring from index 7 to 12: " + substr); // Output:
World
}
}

Q5) Attempt any ONE of the following :

a) Explain the execution process of java program.


1. Writing the Code:
2. Compiling the Code
3. Loading the Bytecode
4. Bytecode Verification
5. Just-In-Time (JIT) Compilation
6. Executing the Code

b) Explain MVC architecture in details.


• MVC stands for a Model View Controller
• MVC is a software design pattern that separates an application into three main
interconnected components
• That are:
1. Model: Manages the data, logic, and rules of the application.
2. View: Represents the presentation layer of the application.
3. Controller: Acts as an intermediary between the Model and the View.

You might also like