Skip to main content

Posts

Showing posts from July, 2020

Write a Java program using servlet for email registration with userid, password, name, address fields and display the details on next page.

Write a Java program using servlet for email registration with userid, password, name, address fields and display the details on next page. Program: import java.io.*; import java.net.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class User extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{ resp.setContentType("Text/http:charset=UTF-8"); PrintWriter out = resp.getWriter(); out.print("<html>"); out.print("<head>"); out.print("<title>Today</title>"); out.print("</head>"); out.print("<body>"); out.print("<br>UserId="+resp.getParameter("userid")); out.print("<br>Password="+resp.getParameter("password")); out.print("<br>Name=&quo

Write a Java program to read n integers into LinkedList collection. Do the following operations. Display only negative integers and delete last element.

Write a Java program to read n integers into LinkedList collection. Do the following operations. Display only negative integers and delete last element. Program: import java.io.*; import java.util.*; class LinkedListInt { public static void main(String args[]) throws IOException { LinkedList list = new LinkedList(); int i,n,x; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("How many integers:"); n = Integer.parseInt(br.readLine()); for(i=0;i<n;i++){ System.out.println("Enter Number:"); x = Integer.parseInt(br.readLine()); list.add(x); } Iterator itr = list.iterator(); while(itr.hasNext()){ Integer y = (Integer)itr.next(); int a = (int)y; if(a<0){ System.out.println("Negative number:"+a); } } System.out.pri

Write a Java program to accept names of n students and insert into LinkedList. Display the contents of list using Iterator and also Display the content in reverse order using ListIterator.

Write a Java program to accept names of n students and insert into LinkedList. Display the contents of list using Iterator and also Display the content in reverse order using ListIterator. Program: import java.io.*; import java.util.*; class ReverseLinkedList { public static void main(String args[]) throws IOException { LinkedList students = new LinkedList(); String str; int i, n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter how many names:"); n = Integer.parseInt(br.readLine()); for(i=0;i<n;i++){ System.out.println("Enter the names of students:"); str = br.readLine(); students.add(str); } Iterator itr = students.iterator(); System.out.println("Content of LinkedList using Iterator"); while(itr.hasNext()){ System.out.println(itr.next()); }

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

Write a Java program to read n strings and insert into ArrayList collection. Display the elements of collection in reverse order. Program: import java.io.*; import java.util.*; class ReverseArrayList { public static void main(String args[]) throws IOException { ArrayList<String> strList = new ArrayList<String>(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int i,n; String str; System.out.println("Enter how many strings:"); n=Integer.parseInt(br.readLine()); for(i=0;i<n;i++){ System.out.println("Enter string:"); str = br.readLine(); strList.add(str); } Collections.reverse(strList); System.out.println("Reverse Order List:"+strList); } }

Write a Java program to design a screen with two textbox and start button. Clicking on start button should start two threads printing 1 to 100 in two textbox.

Write a Java program to design a screen with two textbox and start button. Clicking on start button should start two threads printing 1 to 100 in two textbox. Program: import java.io.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import javax.swing.*; public class ThreadBox extends JApplet implements Runnable, ActionListener { TextArea ta1, ta2; Button btnStart; Thread t1, t2; public void init(){ ta1 = new TextArea(1,20); ta2 = new TextArea(1,20); btnStart = new Button("Start"); setLayout(new FlowLayout()); btnStart.addActionListener(this); add(ta1); add(ta2); add(btnStart); } public void run(){ int i; String str = Thread.currentThread().getName(); if(str.equals("First")){ for(i=1;i<=100;i++){ try{ ta1.append(" "+i) t1.sleep(500);

Write a program to implement following UNIX commands.

Write a program to implement following UNIX commands. wc -c <filename> displays number of characters for the given file. wc -w <filename> display number of words for given file. wc -l <filename> display number of line for given file. Program: #include <stdio.h> #include <stdlib.h> #include <string.h> void main(){ setbuf(stdout,NULL); FILE *fp; char s[80],a[5],c[5],temp[100],f[50],p[50],ch; int n; while(1){ printf("\nAP:>"); gets(s); if(strcmp(s,"exit")==0){ exit(0); } sscanf(s,"%s%s%s",&c,&a,&f); fp=fopen(f,"r"); if(strcmp(c,"wc")!=0){ printf("Invalid Command."); }else if(fp==NULL){ printf("File cannot be found."); }else if(strcmp(a,"-c")==0){ n=0; while(!feof(fp)){ ch = fgetc(fp); n++; } printf("\nNumber of character present in file:%d",n); }else if(strcmp(a,"-l")==0){

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.

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. Program: import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ThreadRun extends JFrame implements Runnable, ActionListener { int i,j; String str, msg = "Thread running"; Thread t; JButton btnStart, btnStop; JPanel panel; public ThreadRun() { Container c = getContentPane(); setDefaultCloseOperation(EXIT_ON_CLOSE); t = new Thread(this); panel = new JPanel(); btnStart = new JButton("Start Thread"); btnStop = new JButton("Stop Thread"); panel.add(btnStart); panel.add(btnStop); btnStart.addActionListener(this); btnStop.addActionListener(this); c.add(panel); setSize(500,600); setVisible(true); j=8

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames.

Write simulation program for demand paging and show the page scheduling and total number of page faults according to LFU page replacement algorithm. Assume the memory of n frames. Program: #include <stdio.h> #include <stdlib.h> void main(){ setbuf(stdout,NULL); int f, tp ,al[50][50]={-1, -1}, i,j,pg[50],pf,x,queue[50]; printf("\nEnter total number of frames:"); scanf("%d",&f); printf("\nEnter total number of pages:"); scanf("%d",&tp); printf("\nEnter page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; for(i=0;i<tp;i++){ for(j=0;j<f;j++){ if(al[j][i]==pg[i]){ break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==-1){ al[j][i]=pg[i]; queue[++x]=pg[i]; pf++; break; } } if(f==j){ for(j=0;j<f;j++){ if(al[j][i]==queue[x]){ al[j][i]=pg[i]; pf++; x--; } } } } else{ queue[++

Write a Java program to display "Hello Java" 50 times using multithreading.

Write a Java program to display "Hello Java" 50 times using multithreading. Program: import java.lang.*; class HelloThread extends Thread { public HelloThread(String name) { super(name); } public void run() { try { for(int i=0;i<25;i++){ System.out.println(Thread.currentThread().getName()+"Hello"); sleep(500); } } catch(InterruptedException ie){ System.out.println(ie); } } } public class ThreadMain { public static void main(String args[]){ HelloThread t = new HelloThread("My Thread"); t.start(); try{ for(int i=0;i<25;i++){ System.out.println(Thread.currentThread().getName()+"Hello"); Thread.sleep(500); } } catch(InterruptedException e) { System.out.println(e); } } }

Write the simulation program for demand paging and show the page scheduling and total number of page faults according to MFU page replacement algorithm. Assume the memory of n frames.

Write the simulation program for demand paging and show the page scheduling and total number of page faults according to MFU page replacement algorithm. Assume the memory of n frames. Program: #include <stdio.h> #include <stdlib.h> int stack[5], x,f,al[10],flag; void selectPage(int s){ int i,j; for(i=0;i<x;i++){ if(stack[i]==s){ for(j=i;j<x;j++){ stack[j]=stack[j+1]; } } } stack[x]=s; } int searchPage(int s){ int i; for(i=0;i<f;i++){ if(al[i]==s){ return i; } } return -1; } void main(){ setbuf(stdout,NULL); int i,j,pg[50],tp,pf; printf("\nEnter the number of frames:"); scanf("%d",&f); printf("\nEnter the total pages:"); scanf("%d",&tp); printf("\nEnter the page string:"); for(i=0;i<tp;i++){ scanf("%d",&pg[i]); } pf=0; x=-1; flag=-1; for(i=0;flag!=f;i++){ if(searchPage(pg[i])==-1){ pf++; stack[++x]=pg[i]; al[++flag]=pg[i]; }else

Write a Java program which will generate threads to display 10 terms of Fibonacci Series and to display 1 to 20 in Reverse order.

Write a Java program which will generate threads to display 10 terms of Fibonacci Series and to display 1 to 20 in Reverse order. Program: import java.lang.*; class FibonacciReverse extends Thread{ String str; FibonacciReverse(String s){ str = s; setName(str); start(); } public void run() { int a=1,b=1,i,j; int c=a+b; try { for(i=0;i<=10;i++) { a=b; b=c; c=a+b; System.out.println(c); sleep(500); } } catch(InterruptedException e) { System.out.println(e); } try { for(j=20;j>=1;j--) { System.out.println(j); sleep(500); } } catch (InterruptedException e){ System.out.println(e); } } } class ThreadMain { public static void main(String args[]){ FibonacciReverse t1 = new Fibonacc