Correct
Correct
try {
for (char c = 'A'; c <= 'Z'; c++){
System.out.print(" " + c);
sleep(2000);
}
}
catch (Exception e) {
System.out.println(e);
}
}
}
Slip – 1b
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
EmployeeB(){
setSize(150,300);
setVisible(true);
setLayout(new FlowLayout());
l1 = new JLabel("ENo");
l2 = new JLabel("EName");
l3 = new JLabel("Designation");
l4 = new JLabel("Salary");
t1 = new JTextField(20);
t2 = new JTextField(20);
t3 = new JTextField(20);
t4 = new JTextField(20);
b1 = new JButton("insert");
b2 = new JButton("Clear");
add(l1); add(t1);
add(l2); add(t2);
add(l3); add(t3);
add(l4); add(t4);
add(b1); add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
Class.forName("org.postgres.Driver");
con =
DriverManager.getConnection("jdbc:postgres://localhost/DB","postgres","");
PreparedStatement pstm ;
pstm.executeUpdate();
JOptionPane.showMessageDialog(this,"Submittted");
} catch (Exception e) {
System.out.println(e);
}
}
new EmployeeB();
}
}
Slip – 2a
import java.util.*;
btnblink.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnblink)
{
t.start();
}
}
public void run()
{
int i = 0 ;
try
{
do
{
i++;
lbldisp.setText("BLINKING TEXT : - "+i);
t.sleep(2000);
}while(true);
}
catch(Exception e)
{
}
}
}
class Slip4A
{
public static void main(String[] args) throws Exception
{
BlinkText bt = new BlinkText();
try
{
do
{
bt.lbldisp.setText("");
Thread.sleep(2000);
}while(true);
}
catch(Exception e)
{
}
}
}
Slip -7b
import java.sql.*;
import java.util.*;
class slip3A
{
public static void main(String[] args) throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
System.out.println("Got Connection:-"+con);
System.out.println("Table DROPED");
String query1 ="create table product(pid integer, pname text, price integer)";
stmt1.executeUpdate(query1);
System.out.println("Table Created");
stmt1.close();
int n = 1 ,c = 0;
System.out.println("Enter Product Information to Insert ");
for(int i = 0 ;i<n;i++)
{
System.out.println("Enter Pid:-");
int id = sr.nextInt();
System.out.println("Enter Pname:-");
String name = sr.next();
System.out.println("Enter Pprice:-");
int price = sr.nextInt();
pstmt.setInt(1,id);
pstmt.setString(2,name);
pstmt.setInt(3,price);
pstmt.executeUpdate();
c = i+1;
System.out.println(c+" - Record Updated");
}
rs.close();
con.close();
}
}
Slip- 3b
import java.util.*;
System.out.println(l);
while(true){
System.out.println("\n1. add element at the end ");
System.out.println("2. Delete 1st element in the list ");
System.out.println("3. Display the content of list in reverse order ");
System.out.print("Enter Choice : ");
int ch = sc.nextInt();
switch(ch) {
case 1:
System.out.println("Enter String t add at the end ");
s=sc.next();
l.addLast(s);
System.out.println(l);
break;
case 2:
System.out.println("After delete the 1st element : ");
l.remove(0);
System.out.println(l);
break;
case 3:
System.out.println("Content in reverse : ");
Iterator i = l.descendingIterator();
while (i.hasNext()) {
System.out.println(i.next());
}
break;
default: System.exit(0);
}
}
}
}
Slip - 4b
import java.util.*;
String c;
int n;
while(true)
{
System.out.println("\n1. Add a city and its STD code ");
System.out.println("2. Remove city ");
System.out.println("3. search city and display its STD code ");
System.out.println("4. show ");
System.out.print("Enter choice : ");
int ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.print("\nEnter City name : ");
c = sc.next();
System.out.print("Enter its STD code : ");
n = sc.nextInt();
h.put(c,n);
break;
case 2:
System.out.print("\nEnter City name : ");
c = sc.next();
if(h.containsKey(c))
{
h.remove(c);
}
else {
System.out.println("City is not present in collection ");
}
break;
case 3:
System.out.print("Enter City name : ");
c = sc.next();
if(h.containsKey(c))
{
System.out.println("\nCITY : "+c+" STD CODE : "+h.get(c));
}
else {
System.out.println("\nCity is not present in collection ");
}
break;
case 4: System.out.println(h);
break;
default: System.exit(0);
break;
}
sc.close();
}
}
}
Slip – 5a
import java.util.*;
h.put(mn, s);
}
Enumeration e = h.keys();
while(e.hasMoreElements())
{
key = e.nextElement();
System.out.println(key +"\t"+ h.get(key));
}
}
}
Slip – 29b
import java.util.*;
int i,p;
System.out.println("Enter Number 1 by 1 : ");
for(i=0;i<n;i++)
{
p = sc.nextInt();
l.add(p);
}
while(true)
{
System.out.println("\n 1. Add element at 1st pos ");
System.out.println("2. Delete last Element ");
System.out.println("3. Display the size of Link list");
System.out.println("4. Display Link list");
System.out.print("Enter your Choice");
int ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.print("Enter No. to add at 1st pos : ");
p = sc.nextInt();
l.addFirst(p);
break;
case 2:
l.removeLast();
System.out.println("last element is deleted ");
break;
case 3:
System.out.println("Size of list is "+ l.size());
break;
case 4:
Iterator m = l.iterator();
while(m.hasNext()){
System.out.print(" "+m.next());
}
break;
default: System.exit(0);
}
}
}
}
Slip – 6a
import java.util.*;
if(t.contains(s_num)){
System.out.println("Number is present. ");
}
else
System.out.println("Number is not present. ");
}
}
Slip- 7a
import java.util.*;
int num;
Square(int n)
{
num = n;
}
int num;
Cube(int n)
{
num = n;
}
try {
while(true)
{
n = r.nextInt(100);
System.out.println("Num : "+n);
if(n%2==0)
{
Square s = new Square(n);
s.start();
}
else{
Cube c = new Cube(n);
c.start();
}
Thread.sleep(2000);
}
} catch (Exception e) {
System.out.println(e);
}
}
Slip – 8a
import java.util.*;
public String s;
public int n;
nthread(String s , int n)
{
this.s=s;
this.n=n;
}
t1.start();
t2.start();
t3.start();
}
}
Slip – 16a
import java.util.*;
int i;
String c;
System.out.println(t);
}
}
Slip -9a
/*
Write a Java program to create a thread for moving a ball inside a panel vertically. The
ball should be created when the user clicks on the start button
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
}
}
public void paint(Graphics g)
{
g.drawOval(x,y,20,20);
}
}
class Slip9A
{
public static void main(String[] args) throws Exception
{
Ball b = new Ball();
}
}
Slip- 17a
import java.util.*;
int i,p;
System.out.println("Enter Number 1 by 1 : ");
for(i=0;i<n;i++)
{
p = sc.nextInt();
t.add(p);
}
System.out.println(t);
}
}
add(lblrno); add(tfrno);
add(lblname); add(tfname);
add(lblper); add(tfper);
add(btnclear); add(btnfind);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnfind)
{
jdbc();
}
}
void jdbc()
{
try
{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
JOptionPane.showMessageDialog
(this,"Got Connection:-"+con);
}
catch(Exception e)
{
}
}
public static void main(String[] args)
{
new Slip10B();
}
}
Slip -,13b
import java.util.*;
int cc = rsmd.getColumnCount();
System.out.println("Doner Table Column Count-"+cc);
for(int i =1;i<=cc;i++)
{
System.out.println("Column No:-"+i);
System.out.println("Column Name:-"+rsmd.getColumnName(i));
System.out.println("Column Type:-"+rsmd.getColumnType(i));
}
}
}
Slip -19a
import java.util.*;
int i,p;
System.out.println("Enter Number 1 by 1 : ");
for(i=0;i<n;i++)
{
p = sc.nextInt();
l.add(p);
}
System.out.println(l);
Slip – 12b
/*
Write a Java Program to create a PROJECT table with field’s project_id, Project_name,
Project_description, Project_Status. Insert values in the table. Display all the details
of the PROJECT table in a tabular format on the screen.(using swing).
*/
import java.awt.*;
import javax.swing.*;
import java.sql.*;
class DataBaseMetaData
{
public static void main(String args[])
{
Connection con=null;;
Statement stm = null;
ResultSet rs = null;
try{
Class.forName("org.postgresql.Driver");
//System.out.print("\ndriver loaded");
con =
DriverManager.getConnection("jdbc:postgresql://localhost/te021","postgres","postgres");
//System.out.println("\nConnection Establish");
stm=con.createStatement();
}
catch(Exception e)
{
System.out.println("\nError : "+e);
}
}
}
Slip – 17b
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
btnstart.addActionListener(this);
}
t.start();
}
}
Slip – 22a
import java.util.*;
import java.sql.*;
class slip18B
{
public static void main(String[] args) throws Exception
{
int eid,esal; String ename;
Scanner sr = new Scanner(System.in);
Class.forName("org.postgresql.Driver");
System.out.println("Driver Loaded And Registered");
do
{
System.out.println
("Menu\n1. Insert \n2. Update \n3. Display \n4. Exit \nEnter Choice.");
int ch = sr.nextInt();
switch(ch)
{
case 1 :
String query = "insert into emp1 values(?,?,?)";
PreparedStatement pstmt = con.prepareStatement(query);
System.out.println("Emp id:-");
eid = sr.nextInt();
System.out.println("Emp name:-");
ename = sr.next();
System.out.println("Emp Sal:-");
esal = sr.nextInt();
pstmt.setInt(1,eid);
pstmt.setString(2,ename);
pstmt.setInt(3,esal);
pstmt.executeUpdate();
System.out.println("Record Inserted");
break;
case 2 :
//updating sal from id
String query2 = "update emp1 set esal=? where eid=?";
PreparedStatement pstmt2 = con.prepareStatement(query2);
System.out.println("Emp id to update :-");
eid = sr.nextInt();
pstmt2.setInt(2,eid);
pstmt2.setInt(1,esal);
System.out.println(pstmt2);
pstmt2.executeUpdate();
System.out.println("Record Updated");
break;
case 3 :
String query3 = "Select * from emp1";
PreparedStatement pstmt3 = con.prepareStatement(query3);
ResultSet rs = pstmt3.executeQuery();
System.out.println("Emp-id \t Emp-name \t Emp-sal");
while(rs.next())
{
System.out.println
(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));
}
break;
case 4 :
con.close();
System.exit(0);
break;
default : System.out.println
("Enter Choice between 1 to 4 ");
}
System.out.println
("Enter \n0. To Exit \n1. To Continue");
op = sr.nextInt();
}
while(op != 0);
}
}
Slip- 21a
import java.util.*;
class slip21A
{
public static void main(String args[])
{
int i,n;
String name;
LinkedList<String> list = new LinkedList<>();
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of subjects: ");
n=sc.nextInt();
System.out.println("Enter name of the subject: ");
for(i=0;i<n;i++)
{
name=sc.next();
list.add(name);
}
Iterator t=list.iterator();
System.out.println("sub names: ");
while(t.hasNext())
{
System.out.println(t.next());
}
}
}
Slip
import java.util.*; -23b
public class cmdN {
public static void main(String[] args) {
int i;
LinkedList<String> t = new LinkedList<>();
for(i=0;i<args.length;i++)
{
t.add(args[i]);
}
Slip–23a
import java.util.*;
int n = s.length();
char ch;
try {
System.out.println("Vowels are");
for(int i=0; i < n ; i++)
{
ch = s.charAt(i);
if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' ||
ch=='E' || ch=='I' || ch=='O' || ch=='U')
{
System.out.println(" "+ch);
Thread.sleep(2000);
}
}
} catch (Exception e) {}
}
}
Slip- 26a
import java.sql.*;
class Slip24B
{
public static void main(String[] args) throws Exception
{
int id = Integer.parseInt(args[0]);
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
System.out.println("Got Connection:-"+con);
Slip – 27a
/*
Write a Java Program to display the details of College (CID, CName, address, Year) on
JTable.
*/
import java.awt.*;
import javax.swing.*;
import java.sql.*;
Slip -25b
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
btnclear.addActionListener(this);
btncreate.addActionListener(this);
btnalter.addActionListener(this);
btndrop.addActionListener(this);
jdbc();
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btnclear)
{
tfquery.setText("");
}
else if (ae.getSource()==btncreate)
{
jdbc_create();
}
else if(ae.getSource()==btnalter)
{
jdbc_alter();
}
else if(ae.getSource()==btndrop)
{
jdbc_drop();
}
}
void jdbc()
{
try
{
Class.forName("org.postgresql.Driver");
con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
JOptionPane.showMessageDialog
(this,"Got Connection:-"+con);
}
catch(Exception e)
{
}
}
void jdbc_create()
{
try
{
// JOptionPane.showMessageDialog (this,"Created Button Clicked");
}
catch(Exception e)
{
JOptionPane.showMessageDialog
(this,"Create :-"+e);
}
}
void jdbc_alter()
{
try
{
JOptionPane.showMessageDialog
(this,"Alter Button Clicked");
//alter table tbl_name alter column col_name set data type new_datatype;
Statement stmt2 = con.createStatement();
String query2 = tfquery.getText();
stmt2.executeUpdate(query2);
JOptionPane.showMessageDialog
(this,"Table Altered");
}
catch(Exception e)
{
JOptionPane.showMessageDialog
(this,"Alter :-"+e);
}
}
void jdbc_drop()
{
try
{
JOptionPane.showMessageDialog
(this,"Drop Button Clicked");
Statement stmt3 = con.createStatement();
String query3 = tfquery.getText();
stmt3.executeUpdate(query3);
JOptionPane.showMessageDialog
(this,"Table Droped");
}
catch(Exception e)
{
JOptionPane.showMessageDialog
(this,"Alter :-"+e);
}
}
Slip – 30b
/*
Write a Java Program for the implementation of scrollable ResultSet. Assume Teacher table
with attributes (TID, TName, Salary) is already created.
*/
import java.sql.*;
class Slip30B
{
public static void main(String[] args) throws Exception
{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
System.out.println("Got Connection:-"+con);
import java.sql.*;
import java.util.*;
class Slip16B
{
public static void main(String[] args) throws Exception
{
Scanner sr = new Scanner(System.in);
Class.forName("org.postgresql.Driver");
System.out.println("Driver Loaded And Registered");
Connection con = DriverManager.getConnection
("jdbc:postgresql://localhost/slips","postgres","");
System.out.println("Got Connection :-"+con);
con.close();
}
}