Write a java program to read n integers into LinkedList collection Do the following operations i) Display only negative integers ii) Delete the last element

import java.io.*;
import java.util.*;
class Slip29
{
    public static void main(String ar[]) throws IOException
    {
        int n;
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        System.out.print("\t\t Enter the size of Linked List ");
        n= Integer.parseInt(br.readLine());
        LinkedList<Integer> ll = new LinkedList<Integer>();
        for(int i=0;i<n;i++)
        {
           System.out.println("Enter the element ");
           ll.add(Integer.parseInt(br.readLine()));
        }
        Iterator<Integer> it = ll.iterator();
        System.out.println(" Contents of Linked List using iterator ");
        while(it.hasNext())
           System.out.println(" \t " + it.next());
        it = ll.iterator();
        System.out.println(" List of negative numbers ");
        while(it.hasNext())
        {
            int no=it.next();
            if(no<0)
               System.out.println("\t" + no);
        }
        ll.removeLast();
        it=ll.iterator();
           System.out.println(" Contents of linked list after removing last element... ");
        while(it.hasNext())
          System.out.println("\t" +it.next());
    }
}

Write a java program which reads a series of first names & stores them in Linked List The program should not allow duplicate names and it should also allow the user to search first name.

import java.io.*;
import java.util.*;
class Slip30
{
    public static void main(String ar[]) throws IOException
    {
        int n;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter size of linkedList...");
        n = Integer.parseInt(br.readLine());
        LinkedList <String> ll = new LinkedList <String>();
        for(int i=0;i<n;i++)
        {
            System.out.println("Enter the element...");
            String str = br.readLine();
            if(ll.contains(str)==true)
            {
                System.out.println("The element is already existing...");
                i--;
            }
            else
            ll.add(str);
        }
        Iterator <String> it = ll.iterator();
        System.out.println("Contents of Linked List using iterator...");
        while(it.hasNext())
          System.out.println("\t" + it.next());
        System.out.println("Enter the element to search : ");
        String search = br.readLine();
        int pos = ll.indexOf(search);
        if(pos== -1)
           System.out.println(" The element not found" );
        else
           System.out.println(" The element found at location :  " +pos);
    }
}

Write a JAVA program to accept names of n students and insert into LinkedLlist i) Display the contents of list using Iterator. ii) Display the content in reverse order. (using ListIterator)

//roll no:-5211
//slp no:-28
import java.util.*;
import java.io.*;
class slip28
{
public static void main(String args[])
{
String str;
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
LinkedList a=new LinkedList();
System.out.println("Enter a no of String you want:");
int n=Integer.parseInt(br.readLine());
for(int i=0;i<n;i++)
{
 System.out.println("Enter string:");
str=br.readLine();
a.add(str);
}
 System.out.println("Display LinkedList:");
Iterator iter=a.iterator();
while(iter.hasNext())
{
System.out.println(iter.next());
}
Collections.reverse(a);
System.out.println("Reversing LinkedList containtns:"+a);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Error");
}
}
}

/* *****output******
F:\5211>javac slip28.java
Note: slip28.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

F:\5211>java slip28
Enter a no of String you want:
2
Enter string:

Rupesh
Enter string:
Rohan
Display LinkedList:
Rupesh

Rohan
Reversing LinkedList containtns:[Rohan,Rupesh]
*/

Write a JAVA program to read n strings & insert into ArrayList collection. Display the elements of collection in reverse order.

import java.util.*;
import java.io.*;
class Slip27
{
    public static void main(String ar[])throws IOException
    {
        int n;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("\t Enter size of arraylist ");
        n=Integer.parseInt(br.readLine());
        ArrayList <String> a = new ArrayList<String>(n);
        for(int i=0;i<n;i++)
        {
            System.out.println("Enter element");
            a.add(br.readLine());
        }
        System.out.println(" The contents of arraylist using iterator..");
        Iterator <String> it = a.iterator();
        while(it.hasNext())
           System.out.println(" \t  " + it.next());
        ListIterator <String> lit = a.listIterator();
           while(lit.hasNext())
         lit.next();
           System.out.println("The contents of arraylist in reverse order... ");
          while(lit.hasPrevious())
           System.out.println("  \t  " + lit.previous());
    }
    }

Write a JAVA program using servlet to count the no of times a servlet has been invoked.


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


    public class slip24 extends implements
    {

    static int numreq=0;
    proctected void doGet(ServletRequest reg,ServletResponse res)

    throws ServletException,IOException
    {
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println("Servlet invoke :");
    numreq++;
    out.println("numreq");
    out.close();

    }
}

Write a JAVA program to accept mobile handset details through html page and servlet will insert the details in handset table(Assume handset table is already present)

import java.io.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Slip22 extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        String modelno=request.getParameter("modelno");
        String modelname=request.getParameter("modelname");
        Connection con;
        Statement state;
        ResultSet rs;
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection("jdbc:odbc:mobile");
            String sql="insert into mobile values(?,?)";
            PreparedStatement p=con.prepareStatement(sql);
            p.setString(1,modelno);
            p.setString(2,modelname);
            p.executeUpdate();
            out.println("Record Inserted");
            p.close();
            con.close();
        }catch(Exception e)
        {
            System.out.println(e);
        }
    }
}

Write a JAVA program Design a screen with two buttons start thread and stop thread. Clicking on start ,it should start printing “Thread running” until stop button is pressed.

import java.awt.*;
import java.awt.event.*;

public class s19 extends Frame implements

ActionListener,Runnable
 {
   Button start,stop;
                 TextField tf;
      int x=0,y=0;
     String msg="";
   Thread t1=new Thread(this);
      public s19()
       {
             setLayout(new FlowLayout());
             start=new Button("start");
             stop=new Button("stop");
            add(start);
            add(stop);

         start.addActionListener(this);
         stop.addActionListener(this);
                  addWindowListener(new

WindowAdapter()
                     {
                        public void

windowClosing(WindowEvent e)
                         {
                           System.exit(0);
                            }
                      });
                     
                     setSize(200,200);
                     setVisible(true);
              }
 
  public void actionPerformed(ActionEvent ae)
     {
             Button btn=(Button)ae.getSource();
              if(btn==start)
              {
                  t1.start();
                 }
       

      if(btn==stop)
              {
                  t1.stop();
                 }
}


public void run()
 {
   try
   {
      while(true)
       {
          repaint();
          Thread.sleep(350);
         }
  }


catch(Exception e)
{
  }
 }

public void paint(Graphics g)
  {
   msg=msg+"thread running";
  g.drawString(msg,10,y+=10);
    }

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

Write a JAVA program using servlet for e-mail registration with user-id, password, name, address, fields & display the details on next page.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Slip21 extends HttpServlet
  {
     public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
    
      {

       String uid = req.getParameter("uid");
       String Password = req.getParameter("Password");
       String name = req.getParameter("Name");
       String addr = req.getParameter("Address");
       res.setContentType("text/html");
       PrintWriter pw = res.getWriter();
       pw.println("\nUser id : "+uid);
       pw.println("\nPassword : "+Password);
       pw.println("\nName : "+name);
       pw.println("\nAddress : " +addr);
       pw.close();
     }
}

Write a Java program to display “Hello Java” 50 times using multithreading

class mythread implements Runnable
{
    Thread t;
    public mythread(String title)
    {
    t=new Thread(this,title);
    t.start();
    }
    public void run()
    {
    for(int i=0;i<50;i++)
{
System.out.println((i+1)+"ThreadName:"+Thread.currentThread().getName());
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}}}
public class slip18
{
public static void main(String a [])
{
System.out.println("ThreadName:"+Thread.currentThread().getName());
mythread mt=new mythread("Hello Java");
}
}   

/*
OUTPUT
---------------------------------------------------------------
D:\ROHAN\Semester\sem 6>javac slip18.java

D:\ROHAN\Semester\sem 6>java  slip18
ThreadName:main
1ThreadName:Hello Java
2ThreadName:Hello Java
3ThreadName:Hello Java
4ThreadName:Hello Java
5ThreadName:Hello Java
6ThreadName:Hello Java
7ThreadName:Hello Java
8ThreadName:Hello Java
9ThreadName:Hello Java
10ThreadName:Hello Java
11ThreadName:Hello Java
12ThreadName:Hello Java
13ThreadName:Hello Java
14ThreadName:Hello Java
15ThreadName:Hello Java
16ThreadName:Hello Java
17ThreadName:Hello Java
18ThreadName:Hello Java
19ThreadName:Hello Java
20ThreadName:Hello Java
21ThreadName:Hello Java
22ThreadName:Hello Java
23ThreadName:Hello Java
24ThreadName:Hello Java
25ThreadName:Hello Java
26ThreadName:Hello Java
27ThreadName:Hello Java
28ThreadName:Hello Java
29ThreadName:Hello Java
30ThreadName:Hello Java
31ThreadName:Hello Java
32ThreadName:Hello Java
33ThreadName:Hello Java
34ThreadName:Hello Java
35ThreadName:Hello Java
36ThreadName:Hello Java
37ThreadName:Hello Java
38ThreadName:Hello Java
39ThreadName:Hello Java
40ThreadName:Hello Java
41ThreadName:Hello Java
42ThreadName:Hello Java
43ThreadName:Hello Java
44ThreadName:Hello Java
45ThreadName:Hello Java
46ThreadName:Hello Java
47ThreadName:Hello Java
48ThreadName:Hello Java
49ThreadName:Hello Java
50ThreadName:Hello Java
---------------------------------------------------------------
*/

Write a JAVA program which will create two child threads by implementing Runnable interface; one thread will print even nos from 1 to 50 and other display vowels

import java.io.*;
class x1 extends Thread

{
 public void run()
 {
   for(int i=1;i<=50;i++)
{
 if(i%2==0)
System.out.println("even no" +i);
}
}
}

class x2 implements Runnable
{
 public void run()
{
   try

{
BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));
System.out.println("Enter the string");
String data=br.readLine();
int n1=data.length();
char p[]=data.toCharArray();
System.out.println("vowel is");
for(int i=0;i<n1;i++)
{
if(p[i]=='a'|| p[i]=='e'|| p[i]=='i'|| p[i]=='o'|| 

p[i]=='u')
 System.out.println(p[i]);
}
}
catch(Exception e)
{
}

}
}

class s17
{
public static void main(String args[])
{
try
{
 x1 runnable=new x1();
Thread tx1=new Thread(runnable);
tx1.start();
tx1.sleep(50);

 x2 runnable1=new x2();
Thread  tx2=new Thread(runnable);
//x2.data=argv[i];
tx2.start();
}
catch(Exception e)
{
}

}
}

output:-


D:\5242>java s17
even no2
even no4
even no6
even no8
even no10
even no12
even no14
even no16
even no18
even no20
even no22
even no24
even no26
even no28
even no30
even no32
even no34
even no36
even no38
even no40
even no42
even no44
even no46
even no48
even no50
even no2
even no4
even no6
even no8
even no10
even no12
even no14
even no16
even no18
even no20
even no22
even no24
even no26
even no28
even no30
even no32
even no34
even no36
even no38
even no40
even no42
even no44
even no46
even no48
even no50