Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers

December 15, 2022

A) Write a JSP script to accept a String from a user and display it in reverse order.

Answer :

<%@ page language="java" %>
<html>
<head>
  <title>Reverse String Example</title>
</head>
<body>
  <h1>Reverse String Example</h1>

  <form method="post">
    Enter a String: <input type="text" name="inputString"><br><br>
    <input type="submit" value="Reverse">
  </form>

  <br><br>

  <%
    String inputString = request.getParameter("inputString");
    if (inputString != null && !inputString.isEmpty()) {
      String reversedString = new StringBuilder(inputString).reverse().toString();
      out.println("Original String: " + inputString + "<br>");
      out.println("Reversed String: " + reversedString);
    }
  %>

</body>
</html>

Output :

 

B) Write a java program in multithreading using applet for moving car.

Answer :

import java.applet.Applet;

import java.awt.*;

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 29 Answers

December 15, 2022


A) Write a java program using multithreading for the following:

1. Display all the odd numbers between 1 to n.

2. Display all the prime numbers between 1 to n.

Answer :

import java.io.*;

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 29 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 29 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 28 Answers

December 15, 2022

A) Write a java program for the implementation of synchronization.

Answer :

class msg {

    synchronized void dis(){

        System.out.println("Hi");

    }

    synchronized void disp(){

        System.out.println("Bye");

    }

}

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 28 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 28 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers

December 15, 2022

A) Write a JSP script to accept the details of Teacher (TID, TName, Desg, Subject ,

Qualification) and display it on the browser. Use appropriate controls for accepting

data.

Answer :

<%@ page language="java" %>
<html>
<head>
  <title>Teacher Details Example</title>
</head>
<body>
  <h1>Teacher Details Example</h1>

  <form method="post">
    TID: <input type="text" name="tid"><br><br>
    TName: <input type="text" name="tname"><br><br>
    Desg: <input type="text" name="desg"><br><br>
    Subject: <input type="text" name="subject"><br><br>
    Qualification: <input type="text" name="qualification"><br><br>
    <input type="submit" value="Submit">
  </form>

  <br><br>

  <%
    String tid = request.getParameter("tid");
    String tname = request.getParameter("tname");
    String desg = request.getParameter("desg");
    String subject = request.getParameter("subject");
    String qualification = request.getParameter("qualification");

    if (tid != null && !tid.isEmpty() && tname != null && !tname.isEmpty() &&
        desg != null && !desg.isEmpty() && subject != null && !subject.isEmpty() &&
        qualification != null && !qualification.isEmpty()) {
      out.println("<h3>Teacher Details:</h3>");
      out.println("TID: " + tid + "<br>");
      out.println("TName: " + tname + "<br>");
      out.println("Desg: " + desg + "<br>");
      out.println("Subject: " + subject + "<br>");
      out.println("Qualification: " + qualification + "<br>");
    }
  %>

</body>
</html>

Output :

 

B) Write a Java Program for the implementation of scrollable ResultSet. Assume

Teacher table with attributes (TID, TName, Salary, Subject) is already created.

Answer :

import java.sql.*;

public class ScrollableResultSetExample {

  public static void main(String[] args) {

    try {
      // Connect to database
      Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");

      // Create statement with scrollable ResultSet
      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = stmt.executeQuery("SELECT * FROM Teacher");

      // Move to last row
      rs.last();

      // Get row count
      int rowCount = rs.getRow();

      System.out.println("Total number of rows: " + rowCount);

      // Move to first row
      rs.first();

      // Print all rows
      while (rs.next()) {
        System.out.println("TID: " + rs.getInt("TID") +
                           ", TName: " + rs.getString("TName") +
                           ", Salary: " + rs.getDouble("Salary") +
                           ", Subject: " + rs.getString("Subject"));
      }

      // Move to previous row
      rs.previous();

      // Print the data of the previous row
      System.out.println("Previous Row Data: TID=" + rs.getInt("TID") +
                         ", TName=" + rs.getString("TName") +
                         ", Salary=" + rs.getDouble("Salary") +
                         ", Subject=" + rs.getString("Subject"));

      // Move to next row
      rs.next();

      // Print the data of the next row
      System.out.println("Next Row Data: TID=" + rs.getInt("TID") +
                         ", TName=" + rs.getString("TName") +
                         ", Salary=" + rs.getDouble("Salary") +
                         ", Subject=" + rs.getString("Subject"));

      // Move to first row again
      rs.first();

      // Close ResultSet, statement, and connection
      rs.close();
      stmt.close();
      conn.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }

  }

}

Output :


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 26 Answers

December 15, 2022

A) Write a java program to display list of college names from college table. (Assume

College table (CID, CName, addr) is already created.

Answer :

import java.sql.*;

 

class Slip26A {

    public static void main(String args[]) throws Exception {

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 26 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 26 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 25 Answers

December 15, 2022

A) Write a Java program to accept a number through client terminal, send it to the

Server, Server calculates its factors and sends it to the client.

Answer :

//Client

import java.io.*;

import java.net.*;

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 25 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 25 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers

December 15, 2022


A) Create a JSP page to accept a number from a user and display it in words:

Example: 123 – One Two Three. The output should be in red color.

Answer :

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Number to Words Converter</title>
<style>
    .red-text {
        color: red;
    }
</style>
</head>
<body>
    <h1>Number to Words Converter</h1>
    <form action="convert.jsp" method="post">
        <label for="number">Enter a number:</label>
        <input type="text" id="number" name="number" />
        <br /><br />
        <input type="submit" value="Convert to Words" />
    </form>

    <%-- Check if the number parameter is present in the request --%>
    <% if (request.getParameter("number") != null) { %>
        <%-- Convert the number to words --%>
        <%
            String number = request.getParameter("number");
            String[] words = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
            String result = "";
            for (int i = 0; i < number.length(); i++) {
                int digit = Character.getNumericValue(number.charAt(i));
                result += words[digit] + " ";
            }
        %>
        <%-- Display the result in red color --%>
        <h2><span class="red-text"><%= result %></span></h2>
    <% } %>
</body>
</html>

Output :

 

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 23 Answers

December 15, 2022

Q.1. Advanced Java:

A) Write a Java Program to display the details of College(CID, CName, address, Year)

on JTable.

Answer :

import java.sql.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class CollegeDetailsProgram extends JFrame {
    private JTable table;

    public CollegeDetailsProgram() {
        setTitle("College Details");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(500, 500);

        // Create a table model with column names
        String[] columnNames = {"CID", "CName", "Address", "Year"};
        DefaultTableModel model = new DefaultTableModel(columnNames, 0);

        // Connect to the database and retrieve the college details
        try {
            // Step 1: Load the JDBC driver
            Class.forName("com.mysql.jdbc.Driver");

            // Step 2: Establish the connection to the database
            String url = "jdbc:mysql://localhost/mydatabase";
            String username = "root";
            String password = "password";
            Connection connection = DriverManager.getConnection(url, username, password);

            // Step 3: Retrieve the college details from the database
            String query = "SELECT * FROM college";
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(query);
            while (resultSet.next()) {
                String cid = resultSet.getString("CID");
                String cname = resultSet.getString("CName");
                String address = resultSet.getString("Address");
                int year = resultSet.getInt("Year");
                model.addRow(new Object[]{cid, cname, address, year});
            }

            // Step 4: Close the database resources
            resultSet.close();
            statement.close();
            connection.close();
        } catch (ClassNotFoundException e) {
            System.out.println("JDBC driver not found.");
        } catch (SQLException e) {
            System.out.println("SQL exception occurred: " + e.getMessage());
        }

        // Create the JTable and add it to the JFrame
        table = new JTable(model);
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane);

        // Show the JFrame
        setVisible(true);
    }

    public static void main(String[] args) {
        new CollegeDetailsProgram();
    }
}

Output :

 

B) Write a SERVLET application to accept username and password, search them into

database, if found then display appropriate message on the browser otherwise display

error message.

Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 23 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 23 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5
Powered by Blogger.