Thursday, May 25, 2023

Run Python Program Using Command Prompt

   

     1)open notepad write your python code then save using .py              extention



 

2)Go to the file location where you save python program Then click on path and type cmd to open cammand prompt and enter




    
3)On command prompt write python filename.py enter to run        python program

 




Or

1)Open notepad write python code then save code using .py extention







Open command prompt set path of program file using cd enter to run python program write python filename.py and enter

 




   






Monday, April 24, 2023

Slip1 Q.1. Core Java: A) Write a ‘java’ program to display characters from ‘A’ to ‘Z’

  

import java.io.*;

class slip1

{

public static void main(String[] args) {

char ch;

for(ch = 'A'; ch <= 'Z';ch++)

System.out.println("the alphabets are :"+ch);

}

}


Output:

C:\Program Files\Java\jdk1.8.0_144\bin>javac slip1.java


C:\Program Files\Java\jdk1.8.0_144\bin>java slip1

the alphabets are :A

the alphabets are :B

the alphabets are :C

the alphabets are :D

the alphabets are :E

the alphabets are :F

the alphabets are :G

the alphabets are :H

the alphabets are :I

the alphabets are :J

the alphabets are :K

the alphabets are :L

the alphabets are :M

the alphabets are :N

the alphabets are :O

the alphabets are :P

the alphabets are :Q

the alphabets are :R

the alphabets are :S

the alphabets are :T

the alphabets are :U

the alphabets are :V

the alphabets are :W

the alphabets are :X

the alphabets are :Y

the alphabets are :Z

Tuesday, September 20, 2022

Core Java Solve practical Slips


 Slip1 Q.1. Core Java: A) Write a ‘java’ program to display characters from ‘A’ to ‘Z’

 Slip 1 .B)Write a ‘java’ program to copy only non-numeric data from one file to another file


Slip 2.A) Write a java program to display all the vowels from a given string

 

Slips 2.B)Design a screen in Java to handle the Mouse Events such as MOUSE_MOVED and MOUSE_CLICK and display the position of the Mouse_Click in a TextField.


Slip3 Q.1. Core Java: A) Write a ‘java’ program to check whether given number is Armstrong or not. (Use static keyword)


 

Slip 3. B)Define an abstract class Shape with abstract methods area () and volume (). Derive abstract class Shape into two classes Cone and Cylinder. Write a java Program to calculate area and volume of Cone and Cylinder.(Use Super Keyword.)


 

Slip4 Q.1. Core Java: A) Write a java program to display alternate character from a given string.[15M]


 

Slip 4.B) Write a java program using Applet to implement a simple arithmetic calculator.


 


Slip 5.A) Write a java program to display following pattern:

        5

        4 5

        3 4 5

        2 3 4 5 

        1 2 3 4 5 


 

Slip 5.B) Write a java program to accept list of file names through command line. Delete the files having extension .txt. Display name, location and size of remaining files.

 


Slip 6.A) Write a java program to accept a number from user, if it zero then throw user defined Exception “Number Is Zero”, otherwise calculate the sum of first and last digit of that number. (Use static keyword).



Slip 6.B) Write a java program to display transpose of a given matrix.



Slip 7.A) Write a java program to display Label with text “Dr. D Y Patil College”, background color Red and font size 20 on the frame.



Slip 7.B) Write a java program to accept details of ‘n’ cricket player (pid, pname, totalRuns, InningsPlayed, NotOuttimes). Calculate the average of all the players. Display the details of player having maximum average. (Use Array of Object)



slip8 Q.1. Core Java: A) Define an Interface Shape with abstract method area(). Write a java program to calculate an area of Circle and Sphere.(use final keyword) [15 M]



Slip 8.B) Write a java program to display the files having extension .txt from a given directory.

 

Slip 9A)Write a java Program to display following pattern:

            1 

            0 1 

            0 1 0 

            1 0 1 0

 



Slip 9.B) Write a java program to validate PAN number and Mobile Number. If it is invalid then throw user defined Exception “Invalid Data”, otherwise display it. 




Slip 10 A) Write a java program to count the frequency of each character in a given string.

 

Slip 10 B) Write a java program for the following:




Slip 11.A) Write a menu driven java program using command line arguments for thefollowing: 

            1. Addition 

            2. Subtraction 

            3. Multiplication

            4. Division.import java.util.Scanner;

 

Slip 11.B) Write an applet application to display Table lamp. The color of lamp should get change randomly. 


 

SLIP 12.B) Write a java program to display multiplication table of a given number into the List box by clicking on button


 

Slip13 Q.1. Core Java: A) Write a java program to accept ‘n’ integers from the user & store them in an ArrayList collection. Display the elements of ArrayList collection in reverse order. [15 M]


 

Slip 13.B) Write a java program that asks the user name, and then greets the user by name. Before outputting the user's name, convert it to upper case letters. For example, if the user's name is Raj, then the program should respond "Hello, RAJ, nice to meet you!".

 

   Slip 14 A) Write a Java program to calculate power of a number using recursion.

 

Slip 14 B) Write a java program to accept the details of employee (Eno, EName, Sal) and display it on next frame using appropriate event .


 

Slip 15 A) Write a java program to search given name into the array, if it is found then display its index otherwise display appropriate message.


 

Slip 15 B) Write an applet application to display smiley face.


 

Slip 16 A) Write a java program to calculate sum of digits of a given number using recursion.


 

Slip 16 B) Write a java program to accept n employee names from user. Sort them in ascending order and Display them.(Use array of object and Static keyword)


 

SLIP 17.A) Write a java Program to accept ‘n’ no’s through command line and store only armstrong no’s into the array and display that array


 


SLIP 17.B) Define a class Product (pid, pname, price, qty). Write a function to accept the product details, display it and calculate total amount. (use array of Objects)


 

SLIP 18.A) Write a Java program to calculate area of Circle, Triangle & Rectangle.(Use Method Overloading)


 

SLIP 18.B) Write a java program to copy the data from one file into another file, while copying change the case of characters in target file and replaces all digits by ‘*’ symbol.


 

Slip19 Q.1. Core Java: A) Write a Java program to display Fibonacci series using function. [15 M] 


 

SLIP 19.B) Create an Applet that displays the x and y position of the cursor movement using Mouse and Keyboard. (Use appropriate listener)


 

SLIP 20.A) Write a java program using AWT to create a Frame with title “TYBBACA”, background color RED. If user clicks on close button then frame should close.


 

SLIP 20.B) Construct a Linked List containing name: CPP, Java, Python and PHP. Then extend your java program to do the following: 

 i. Display the contents of the List using an Iterator 

 ii. Display the contents of the List in reverse order using a ListIterator



Slip21 Q.1. Core Java: A) Write a java program to display each word from a file in reverse order. [15 M] 


 

Slip 21 B) Create a hash table containing city name & STD code. Display the details of the hash table. Also search for a specific city and display STD code of that city.


 

Slip 22 A) Write a Java program to calculate factorial of a number using recursion.


 

Slip 22 B) Write a java program for the following:

1. To create a file.

2. To rename a file.

3. To delete a file.

4. To display path of a file.


 

Slip 23 A) Write a java program to check whether given file is hidden or not. If not then display its path, otherwise display appropriate message.

 



Slip 23 B) Write a java program to design following Frame using Swing.


 


slip24  Q.1. Core Java: A) Write a java program to count number of digits, spaces and characters from a file. [15 M]


 

Sli24.B) Create a package TYBBACA with two classes as class Student (Rno, SName, Per) with a method disp() to display details of N Students and class Teacher (TID, TName, Subject) with a method disp() to display the details of teacher who is teaching Java subject. (Make use of finalize() method and array of Object)


 


Slip25 Q.1. Core Java: A) Write a java program to check whether given string is palindrome or not. [15 M] 

 


 

Slip 25.B) Create a package named Series having three different classes to print series: 

            i. Fibonacci series 

            ii. Cube of numbers 

            iii. Square of numbers 

Write a java program to generate ‘n’ terms of the above series

NOTE: THIS QUESTION HAS TWO PROGRAMS TO BE WRITTEN AND COMPILED DIFFERENTLY.


Program 1:

Program 2:

 


Slip26 Q.1. Core Java: A) Write a java program to display ASCII values of the characters from a file. [15 M] 


 

Slip 26 B) Write a java program using applet to draw Temple.


 

Slip 27 A) Write a java program to accept a number from user, If it is greater than 1000 then throw user defined exception “Number is out of Range” otherwise display the factors of that number. (Use static keyword)


 

 Slip 27 B) Write a java program to accept directory name in TextField and display list of files and subdirectories in List Control from that directory by clicking on Button.


 

 Slip 28 A) Write a java program to count the number of integers from a given list. (Use Command line arguments).



Slip 28 B) Write a java Program to accept the details of 5 employees (Eno, Ename, Salary) and display it onto the JTable.


 

Slip 29 A) Write a java program to check whether given candidate is eligible for voting or not. Handle user defined as well as system defined Exception.


 

Slip 29 B) Write a java program using Applet for bouncing ball. Ball should change its color for each bounce.


 

Slip 30 A) Write a java program to accept a number from a user, if it is zero then throw user defined Exception “Number is Zero”. If it is non-numeric then generate an error “Number is Invalid” otherwise check whether it is palindrome or not.


 

Slip 30 B) Write a java program to design a following GUI (Use Swing).

 

Advance Java Solve practical Slips

 Slip _1


Q.1. Advanced Java: A) Write a java program to scroll the text from left to right and vice versa continuously.

Slip1A.java

import java.awt.*; 

import java.applet.*;

public class slip1A extends Applet implements Runnable 

 { 

      String banner="Hello "; 

      int state; 

      boolean stopflag; 

            

      public void init() 

      { 

           setBackground(Color.black); 

           setForeground(Color.green); 

      } 

       

      public void start() 

      { 

           Thread t=new Thread(this); 

           stopflag=true; 

           t.start(); 

      } 

       

 public void run() 

      { 

           char ch; 

           try 

           { 

                while(true) 

                { 

                     repaint(); 

                     Thread.sleep(150); 

                     ch=banner.charAt(0); 

                     banner = banner.substring(1,banner.length()); 

                     banner +=ch; 

                      

                } 

           } 

           catch (InterruptedException e) 

           { 

                System.out.println(e); 

           } 

      } 

       

public void stop() 

      { 

           stopflag=false; 

            Thread t=null; 

      } 

       

public void paint(Graphics g) 

      { 

           Font a = new Font("Impact",Font.BOLD,45); 

           g.setFont(a); 

           g.drawString(banner,10,60); 

      } 

       

 }  



Slip1 A html

<html>

<head>

<title>Reverse order</title>

</head>

<body>

<applet code="slip1A.class" height="100" width="350"></applet> 

</body>

</html>


 [15 M] B) Write a socket program in java for chatting application.(Use Swing) [25 M]





 Slip2 :


 A) Write a JSP program to check whether given number is Perfect or not. (Use Include directive). [15 M]

Slip2A.html


<!DOCTYPE html>

<html>

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<form action="Slip2A.jsp" method="post">

Enter Number :

<input type="text" name="num">

<input type="submit" value="submit">

</form>

</body>

</html>



Slip2A.jsp


<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<%

int num = Integer.parseInt(request.getParameter("num"));

int n = num;

    // To store sum of divisors

    int sum = 1;

    // Find all divisors and add them

    for (int i = 2; i * i <= n; i++)

    {

        if (n % i==0)

        {

            if(i * i != n)

                sum = sum + i + n / i;

            else

                sum = sum + i;

        }

    }

    // If sum of divisors is equal to

    // n, then n is a perfect number

    if (sum == n && n != 1)

{

out.println("perfect Number");

}

else

{

out.println("Not perfect Number");

}

%>



 B) Write a java program in multithreading using applet for drawing flag. [25 M]

Slip2B.java

import java.awt.*;

import java.applet.*;

public class slip2B extends Applet

{

public void paint(Graphics g)

{

g.setColor(Color.blue);

g.fillRect(50,20,5,300);

g.setColor(Color.black);

g.drawRect(50,18,3,300);

g.setColor(Color.orange);

g.fillRect(55,20,120,30);

g.setColor(Color.black);

g.drawRect(55,20,118,28);

g.setColor(Color.green);

g.fillRect(55,80,119,30);

g.setColor(Color.black);

g.drawRect(55,80,117,28);

g.setColor(Color.black);

g.drawOval(100,50,30,30);

}

}


Slip2B.html


<html>

   <head>

   </head>

   <body>

         <applet code = "slip2B.class" width = "320" height = "480"></applet>

   </body>

</html>

 

Slip  4


A) Write a Java Program to delete details of students whose initial character of their name is ‘S’. [15 M]

Slip4A.java


import java.sql.*;

public class slip4A

{

public static void main(String arg[])

{

Connection con;

Statement stmt;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

if(con==null)

{

System.out.println("Connection failed");

System.exit(1);

}

System.out.println("Connection established");

stmt=con.createStatement();

int no=stmt.executeUpdate("Delete From Student where sname like'S%' ");

if(no!=0)

System.out.println("data deleted sucessfully");

else

System.out.println("data not deleted");

con.close();

}catch(Exception e)

{

System.out.println(e);

}

}

}


B) Write a SERVLET program that provides information about a HTTP request from a client, such as IP address and browser type. The servlet also provides information about the server on which the servlet is running, such as the operating system type, and the names of currently loaded servlets.



Slip 5


A) Write a JSP program to calculate sum of first and last digit of a given number. Display sum in Red Color with font size 18. [15 M] 

Slip5A.jsp

<!DOCTYPE html>

<html>

<body>

<%! int n,rem,r; %>

<% n=Integer.parseInt(request.getParameter("num"));

if(n<10)

{

out.println("Sum of first and last digit is ");

%><font size=18 color=red><%= n %>

<%

}

else

{

rem=n%10;

do

{

r=n%10;

n=n/10;

}while(n>0);

n=rem+r;

out.println("Sum of first and last digit is ");

%><font size=18 color=red><%= n %>

<%

}

%>

</body>

</html>


Slip5A.html

<html>

<body>

<form method=post action="Slip5A.jsp">

Enter Any Number : <Input type=text name=num>

<input type=submit value=Display>

</form>

</body>

</html>



B) Write a java program in multithreading using applet for Traffic signal. [25 M]


Slip5B.html


<html>

   <head>

   </head>

   <body>

         <applet code = "slip2B.class" width = "320" height = "480"></applet>

   </body>

</html>


Slip5B.java

import java.awt.*;

import java.applet.*;

public class slip5B extends java.applet.Applet implements Runnable

{

int r,g1,y,i;

Thread t;

public void init()

{

r=0;g1=0;y=0;

t=new Thread(this);

t.start();

}

public void run()

{

try

{

for(i=24;i>=1;i--)

{

t.sleep(100);

if(i>=16 && i<24)

{

g1=1;

repaint();

}

if(i>=8 && i<16)

{

y=1;

repaint();

}

if(i>=1 && i<8)

{

r=1;

repaint();

}

}

if(i==0)

{

run();

}

}catch(Exception e){}

}

public void paint(Graphics g)

{

g.drawOval(100,100,100,100);

g.drawOval(100,225,100,100);

g.drawOval(100,350,100,100);

if(r==1)

{

g.setColor(Color.red);

g.fillOval(100,100,100,100);

g.drawOval(100,350,100,100);

r=0;

}

if(g1==1)

{

g.setColor(Color.green);

g.fillOval(100,225,100,100);

g.drawOval(100,225,100,100);

g1=0;

}

if(y==1)

{

g.setColor(Color.yellow);

g.fillOval(100,350,100,100);

g.drawOval(100,350,100,100);

y=0;

}

}

}


Slip  7  


A) Write a JSP script to validate given E-Mail ID. [15 M]

Slip7A.html

<!DOCTYPE html>

<html>

<head>

<meta charset="ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

<form name=f1 action="slip7A.jsp">

<fieldset>

<legend>Enter Email Id...!!!</legend>

        Enter Email Id:<input type="text" name="t1" >

</fieldset>

<div align=center>

<input type="submit" name="Submit" value="Submit">

</div>

</form>


</body>

</html>


Slip7A.jsp

<html>

<body>

<%@ page language="java" %>

<%

        String email=request.getParameter("t1");

        if(email.contains("@") && email.contains("."))

        {

        out.println("Given Email Id is Valid");

        }

        else        {

        out.println("Given Email id is not Valid");

        }

        %>

</body>

</html>




 B) Write a Multithreading program in java to display the number’s between 1 to 100 continuously in a TextField by clicking on button. (use Runnable Interface)



Slip 8


A) Write a Java Program to display all the employee names whose initial character of a name is ‘A’. [15 M] 

Slip8A.java

import java.sql.*;

public class slip8A

{

public static void main(String arg[])

{

Connection con;

Statement stmt;

ResultSet rs;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

if(con==null)

{

System.out.println("Connection failed");

System.exit(1);

}

System.out.println("Connection established");

stmt=con.createStatement();

rs=stmt.executeQuery("Select * From employee where ename like'A%' ");

while(rs.next())

{

System.out.println("\n"+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

}

rs.close();

con.close();

}catch(Exception e)

{

System.out.println(e);

}

}

}




B) Write a java program in multithreading using applet for Digital watch. [25 M] 

Slip8B.html


<html>  

<body>  

<applet code="slip8B.class" width="300" height="300">  

</applet>  

</body>  

</html>  


Slip8.java

import java.applet.*;  

import java.awt.*;  

import java.util.*;  

import java.text.*;  

  

public class slip8B extends Applet implements Runnable {  

  

   Thread t = null;  

   int hours=0, minutes=0, seconds=0;  

   String timeString = "";  

  

   public void init() {  

      setBackground( Color.green);  

   }  

  

   public void start() {  

        t = new Thread( this );  

        t.start();  

   }  

  

    

   public void run() {  

      try {  

         while (true) {  

  

            Calendar cal = Calendar.getInstance();  

            hours = cal.get( Calendar.HOUR_OF_DAY );  

            if ( hours > 12 ) hours -= 12;  

            minutes = cal.get( Calendar.MINUTE );  

            seconds = cal.get( Calendar.SECOND );  

  

            SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");  

            Date date = cal.getTime();  

            timeString = formatter.format( date );  

  

            repaint();  

            t.sleep( 1000 );  // interval given in milliseconds  

         }  

      }  

      catch (Exception e) { }  

   }  

  

    

  public void paint( Graphics g ) {  

      g.setColor( Color.blue );  

      g.drawString( timeString, 50, 50 );  

   }  

}  


Slip 9

A) Write a Java Program to create a Emp (ENo, EName, Sal) table and insert record into it. (Use PreparedStatement Interface) [15 M] 

Slip9.java

import java.io.*;

import java.sql.*;

class slip9A

{

public static void main(String arg[])throws IOException

{

try

{

Connection con;

Statement stmt;

PreparedStatement ps;

ResultSet rs;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

System.out.println("connection established....");

stmt=con.createStatement();

ps=con.prepareStatement("insert into Emp values(?,?,?)");

System.out.println("Enter the eno:");

int Eno=Integer.parseInt(br.readLine());

ps.setInt(1,Eno);

System.out.println("Enter the ename:");

String Ename=br.readLine();

ps.setString(2,Ename);

System.out.println("Enter the salary:");

int Sal=Integer.parseInt(br.readLine());

ps.setInt(3,Sal);

ps.executeUpdate();

System.out.println("record inserted....");

rs=stmt.executeQuery("select * from Emp");    

while(rs.next())

{

System.out.println("\n"+rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));

} 

rs.close();

stmt.close();

con.close();

}catch(Exception e)

{

System.out.println(e);

}

}

}


B) Write a JSP program to create an online shopping mall. User must be allowed to do purchase from two pages. Each page should have a page total. The third page should display a bill, which consists of a page total of whatever the purchase has been done and print the total. (Use Session)


Slip11


A) Write a java program to display IPAddress and name of client machine.[15 M] 

import java.net.InetAddress;

public class slip10A 

{

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

    {

        InetAddress IP = InetAddress.getLocalHost();

        System.out.println("IP of my system is := "+IP.getHostAddress());

    }    

}


B) Write a Java program to display sales details of Product (PID, PName, Qty, Rate, Amount) between two selected dates. (Assume Sales table is already created).


Slip12

A) Write a java program to count the number of records in a table. [15 M]

Slip12A

import java.sql.*;


class slip12A

{

            public static void main(String args[])

            {

                        Connection con;

                        Statement stmt;                                             

                        try

                        {

                                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

                                    con=DriverManager.getConnection("jdbc:odbc:shamal");

                                    if(con==null)

                                    {

                                                System.out.println("Connection Failed.......");

                                                System.exit(1);

                                    }

                                    System.out.println("Connection Established......");

                                    stmt=con.createStatement();

                                    ResultSet rs=stmt.executeQuery("select * from Student");


                                    int cnt=0;

                                    while(rs.next())

                                    {

                                                cnt++;

                                    }

                                    System.out.println("Number of records in Table are:"+cnt);

                        }


                        catch(Exception e)

                        {

                                    System.out.println(e);


                        }

            }

}

 B) Write a program in java which will show lifecycle (creation, sleep, and dead) of a thread. Program should print randomly the name of thread and value of sleep time.

The name of the thread should be hard coded through constructor. The sleep time of a thread will be a random integer in the range 0 to 4999.


Slip13


A) Write a java program to display name of currently executing Thread in multithreading. [15 M]

Slip13A

import java.sql.*;

public class slip13A extends Thread

{

public void run()

{

System.out.println(Thread.currentThread().getName());

}

public static void main(String arg[])

{

slip13A t1=new slip13A();

slip13A t2=new slip13A();

t1.start();

t2.start(); 

}

}


 B) Write a JSP program to display the details of College (CollegeID, Coll_Name, Address) in tabular form on browser.


Slip  14

A) Write a JSP program to accept Name and Age of Voter and check whether he is eligible for voting or not. [15 M]

Slip14.html


<html>

<body>

<form action="slip14A.jsp" method="get">

Enter Name:<input type="text" name="name"/>

<br>

Enter Age:<input type="text" name="age"/>

<br>

<input type="submit"/>


</form>

</body>

</html>


Slip14.jsp


<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>

<body>

<%String name = request.getParameter("name");%>

<%int age = Integer.parseInt(request.getParameter("age"));%>

<%if(age >=18)

{

out.println(name + "\nAllowed to vote");

}

else

{

out.println(name + "\nNot allowed to vote");

}

%>

</body>

</html>


 B) Write a Java program to display given extension files from a specific directory on server machine.


Slip 15

A) Write a java program to display each alphabet after 2 seconds between ‘a’ to ‘z’. [15 M] 

Slip15A.java

public class slip15A extends Thread

{

char c;

public void run()

{

for(c = 'A'; c<='Z';c++)

{

System.out.println(""+c);

try


{

Thread.sleep(3000);

}

catch(Exception e)

{

e.printStackTrace();

}

}

}

public static void main(String args[])

{

slip15A t = new slip15A();

t.start();

}

}

B) Write a Java program to accept the details of Student (RNo, SName, Per, Gender, Class) and store into the database. (Use appropriate Swing Components and PreparedStatement Interface).


Slip18


A) Write a java program to calculate factorial of a number. (Use sleep () method). [15 M] 

Slip18A

import java.io.*;

class slip18A{

public static void main(String arg[])throws InterruptedException

{

int i,fact=1;

int number=5;

for(i=1;i<=number;i++)

{

Thread.sleep(2000);

fact=fact*i;

}

System.out.println("factorial of "+number+" is:"+fact);

}

}


B) Write a java program for simple standalone chatting application. [25 M]


Slip   20

A) Write a JDBC program to delete the details of given employee (ENo EName Salary). Accept employee ID through command line. [15 M] 

Slip20 A

import java.sql.*;

class slip20A

{

public static void main(String a[])

{

Connection con;

PreparedStatement ps;

ResultSet rs;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

if(con==null)

{

System.out.println("Connection Failed....");

System.exit(1);

}

System.out.println("Connection Established...");

ps=con.prepareStatement("select * from employee where eid=?");

int id = Integer.parseInt(a[0]);

ps.setInt(1,id);


rs=ps.executeQuery();

System.out.println("eno\t"+"ename\t"+"department\t"+"sal"); 

while(rs.next())

{

System.out.println("\n"+rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3)+"\t"+rs.getInt(4));

}

con.close();

}

catch(Exception e)

{

System.out.println(e);

}

}

}


B) Write a java program in multithreading using applet for drawing temple.

Slip20B.java

import java.applet.Applet;

import java.awt.*;

     

public class slip20B extends Applet

{

      public void paint(Graphics g)

      {

            g.drawRect(100,150,90,120);

            g.drawRect(130,230,20,40);

            g.drawLine(150,100,100,150);

            g.drawLine(150,100,190,150);

            g.drawLine(150,50,150,100);

            g.drawRect(150,50,20,20);



      }

}


Slip20 html

<html>

<head>

<title>Insert here</title>

</head>

<body>

<applet code=slip20B.class width=300 height=300></applet>

</body>

</html>


Slip21 

A) Write a java program to display name and priority of a Thread. [15 M] 

Slip21A.java

import java.io.*;

import java.sql.*;

public class slip21A implements Runnable

{

public void run()

{

  System.out.println(Thread.currentThread()); // This method is static.

}

public static void main(String[] args) 

{

slip21A a = new slip21A();

 Thread t = new Thread(a, "NewThread");

 t.setPriority(2); // Setting the priority of thread.

 

 System.out.println("Priority of Thread: " +t.getPriority());

 System.out.println("Name of Thread: " +t.getName());

 t.start();

  }

}


B) Write a SERVLET program in java to accept details of student (SeatNo, Stud_Name, Class, Total_Marks). Calculate percentage and grade obtained and display details on page.


Slip22

A) Write a java program to display Date and Time of Server machine on client machine. [15 M] 


B) Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form.

Slip22.html

<html>

<body>

<form method=get action="slip22B.jsp">

Enter Account No. : <input type=text name=ano><br><br>

Enter Account Type:<input type=text name=type><br><br>

Enter Balance : <input type=text name=bal><br><br>

<input type=submit value="Save">

</form>

</body>

</html>


Slip22B.jsp

<html>

<body>

<%@ page import="java.sql.*;" %>

<%! int ano,bal;

       String type;  %>

<%

      ano=Integer.parseInt(request.getParameter("ano"));

      type=request.getParameter("type");

      bal=Integer.parseInt(request.getParameter("bal"));

      try{

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

            Connection cn=DriverManager.getConnection("jdbc:odbc:shamal");

            PreparedStatement s=cn.prepareStatement("insert into Account values(?,?,?)");

            s.setInt(1,ano);

            s.setString(2,type);

            s.setInt(3,bal);

            s.executeUpdate();

            out.println("Record is saved");

            Statement st=cn.createStatement();

            ResultSet rs=st.executeQuery("select * from Account");

%>

<table border="1" width="40%">

<%      while(rs.next())

            {

%>

<tr> <td><%= rs.getInt("ano") %></td>

            <td><%= rs.getString("type") %></td>

            <td><%= rs.getInt("bal") %></td>

</tr>

<%

            }

            cn.close();

          }catch(Exception e)

            {      

                   out.println(e);      

            }

%>

</body>

</html>


Slip24

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. [15 M] 

Slip24A.html

<html>

<body>

<form method=get action="slip24.jsp">

Enter Any Number : <input type=text name=num><br><br>

<input type=submit value="Display">

</form>

<body>

</html>


Slip24A.jsp

<html>

<body>

<font color=red>

<%! int i,n;

       String s1;

%>

<%   s1=request.getParameter("num");

         n=s1.length();

         i=0;

         do

         {

           char ch=s1.charAt(i);

           switch(ch)

            {

                case '0': out.println("Zero  ");break;

                case '1': out.println("One  ");break;

                case '2': out.println("Two  ");break;

                case '3': out.println("Three  ");break;

                case '4': out.println("Four ");break;

                case '5': out.println("Five  ");break;

               case '6': out.println("Six  ");break;

               case '7': out.println("Seven  ");break;

               case '8': out.println("Eight  ");break;

               case '9': out.println("Nine  ");break;

           }

           i++;

         }while(i<n);

%>

</font>

</body>

</html>

B) Write a menu driven program in Java for the following: Assume Emp table with attributes ( ENo, EName, salary, Desg ) is already created. 1. Insert 2. Update 3. Delete 4. Search 5. Display 6. Exit.

Slip25B

import java.io.*;

import java.awt.*;

import javax.swing.*;

import java.sql.*;

import java.awt.event.*;

class slip25B extends JFrame implements ActionListener

{

JLabel l1;

JTextArea t1,t2;

JButton b1,b2,b3;

public static void main(String arg[])throws IOException

{

System.out.println("hello world");

new slip25B( );

}

slip25B()

{

l1=new JLabel("Type DDL Query");

t1=new JTextArea(30,30);

t2=new JTextArea(30,30);

b1=new JButton("Create Table");

b2=new JButton("Alter Table");

b3=new JButton("Drop Table");

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

setVisible(true);

setLayout(new GridLayout(2,3));

setSize(500,500);

add(l1);

add(t1);

add(t2);

add(b1);

add(b2);

add(b3);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent ae)

{

if(ae.getSource()==b1)

{

try

{

Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

String query=t1.getText();

Statement stmt=con.createStatement();

stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Table created");

stmt.close();

con.close();

}

catch(Exception e)

{

System.out.println(e);

}

}

if(ae.getSource()==b2)

{

try

{

Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

String query=t1.getText();

Statement stmt=con.createStatement();

stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Table Altered");

stmt.close();

con.close();

}

catch(Exception e)

{

System.out.println(e);

}

}

if(ae.getSource()==b3)

{

try

{

Connection con;

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

con=DriverManager.getConnection("jdbc:odbc:shamal");

String query=t1.getText();

Statement stmt=con.createStatement();

stmt.executeUpdate(query);

JOptionPane.showMessageDialog(null,"Table drop");

stmt.close();

con.close();

}

catch(Exception e)

{

System.out.println(e);

}

}

}

}