Posts

Showing posts from April, 2017

Write a program for connecting server with client like google.com with ip address of it.

// java socket client example import java.io.*; import java.net.*; public class socket_client { Public static void main(String[] args) throws IOException { Socket s = new Socket(); String host = “www.google.com”; Try { s.connect(new InetSocketAddress(host,80)); } //Host not found catch(UnknownHostException e) { System.out.println(“Dont know about this host: ” +host); System.exit(1); } System.out.println(“Connected”); } }

Write a socket program in java for simple stand alone chatting application.

Client side Import java.io.*; Import java.net.*; public class Chatclient { Public static void main(String args[]) { Boolean b = true; try { Socket s1 = new Socket(“localhost”,40); DataInputStream in1 = new DataInputStream(s1.getInputStream()); DataInputStream out1 = new DataInputStream(s1.getOutputStream()); printStream pw = new printStream(out1); System.out.println(“Send Message”); While(b) { DataInputStream in = new DataInputStream(System.in); String str1 = in.readLine(); If(str1.equals(“quit”)) b=false; else { pw.println(str1); String str2 = in1.readLine(); System.out.println(str2); } } } catch(Exception e) { System.out.println(e); } } Server side Import java.io.*; Import java.net.*; public class Chatserver { Public static void main(String args[]) { Boolean b = true; try { ServerSocket s = new ServerSocket(40); ServerSocket s1 = s.accept(); DataInputStream in1 = new DataInputStream(s1.getInputStream()); DataOutputStream out1 = new DataOutputStream(s1.getOutputStream()); printSt...

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

NumberWord.html <html> <body> <form method=get action="NumberWord.jsp"> Enter Any Number : <input type=text name=num><br><br> <input type=submit value="Display"> </form> <body> </html> NumberWord.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...

Write a JSP script to accept UserName and his NickName through html page and then displays username when visit count to page is odd and displays nickname when the visit count to the page is even. 

VisitPage.html <html> <body> <form method=get action="VisitPage.jsp"> Enter User Name : <input type=text name=uname><br><br> Enter Nick Name : <input type=text name=nname><br><br> <input type=submit value="visit"> </form> <body> </html> VisitPage.jsp <html> <body> <%!        int cnt=0;        String uname,nname; %> <%       uname=request.getParameter("uname");        nname=request.getParameter("nname");        cnt++;       if(cnt%2==0)        out.println("Hello "+nname+".........    Visit Count   "+cnt);       else        out.println("Hello "+uname+".........    Visit Count   "+cnt); ...

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.

Number.html <html> <body> <form method=get action="Number.jsp"> Enter Any Number : <Input type=text name=num><br><br> <input type=submit value=Calculate> </form> </body> </html> Number.jsp <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 %></font> <%      }     else     {       rem=n%10;       do{                  r=n%10;                  n=n/10;        ...

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

SaveAccount.html <html> <body> <form method=get action="saveAccount.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> saveAccount.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");           ...

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.

UserPass.html <html> <body> <form method=post action="http://localhost:4141/Program/servlet/UserPass"> User Name :<input type=text name=user><br><br> Password :<input type=text name=pass><br><br> <input type=submit value="Login"> </form> </body> </html> UserPass.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class UserPass extends HttpServlet {     public void doGet(HttpServletRequest request, HttpServletResponse response)         throws IOException, ServletException     {             PrintWriter out = response.getWriter();             try{                         String us=reques...

Write a SERVLET program which counts how many times a user has visited a web page. If user is visiting the page for the first time, display a welcome message. If the user is revisiting the page, display the number of times visited. (Use Cookie)

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class VisitServlet extends HttpServlet {     static int i=1;     public void doGet(HttpServletRequest request, HttpServletResponse response)         throws IOException, ServletException     {         response.setContentType("text/html");         PrintWriter out = response.getWriter();         String k=String.valueOf(i);         Cookie c = new Cookie("visit",k);         response.addCookie(c);         int j=Integer.parseInt(c.getValue());         if(j==1)         {             out.println("Welcome");  ...

Write a java program to create a student table with field’s rno, name and per. Insert values in the table. Display all the details of the student on screen. (Use PreparedStatement Interface)

import java.io.*; import java.sql.*; public class CreateStudentTable {           static Connection cn;             static Statement st;             static PreparedStatement ps;             static ResultSet rs;             public static void main(String args[])             {         try{                                     int rno,per;                     ...

Write a JDBC application using swing for the following:

Accept Query in TextField For 1. Create Table 2. Alter Table 3. Drop Table import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; class DDL extends JFrame implements ActionListener {             JLabel l1;             JButton b1,b2,b3;             JTextArea t1;             DDL()             {                         setLayout(null);                         l1=new JLabel("Type DDL Query");         ...

Write a JDBC program to delete the records of employees whose names are starting with ‘A’ character.

import java.sql.*; public class DeleteEmployeeRecord {           static Connection cn;             static Statement st;             public static void main(String args[])             {     try {                                     ResultSet rs,rs1;                                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");              ...

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

import java.io.*; import java.sql.*; public class CreateTeacherTable {            static Connection cn;             static Statement st;             public static void main(String args[])             {                    try                  {                                 int tno,sal;                         String tname,desg;                         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));                         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");    ...

Write a JDBC program to remove “percentage” column from student (rno, sname, percentage) table

import java.io.*; import java.sql.*; public class RemoveColumn {           static Connection cn;             static Statement st;             static ResultSet rs;             public static void main(String args[])             {           try{                                     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));                                     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                                     cn=DriverManager.getConnection("jdbc:odbc:dsn","","");       ...

Write a Multithreading program in java to convert smile face into the crying face after 5 seconds and vice versa(Use Applet).

import java.awt.*; /* <applet code="Smileface.class" height=400 width=350> </applet> */ public class Smileface extends java.applet.Applet implements Runnable {     Thread t;     int f;     public void init()     {          t=new Thread(this);          t.start();           f=0;     }  public void run()     {        try{             if (f==0)             {                         t.sleep(1000);                         f=1;                         repaint();             }             else     ...

Write a Multithreading program in java for bouncing ball. For each bounce, Change the color of ball randomly.

import java.awt.*; /*<applet code="BounsingBall.class" height=400 width=350></applet>*/ public class BounsingBall extends java.applet.Applet implements Runnable {     Thread t;     int f,y,f1,f2,f3;     public void init()     {                      t=new Thread(this);              t.start();             f=0;  y=0;  f1=0;               }     public void run()     {   try{                     if (f==0){      t.sleep(10);                                  y=y+5;                                  repaint(); ...

Write a Multithreading program in java using Runnable interface to move text on the frame

import java.awt.*; import java.awt.event.*; class MoveText extends Frame implements Runnable {           Label l1;             Thread t;             int x,y,side;             public MoveText()             {                         setLayout(null);                         l1=new Label(" Hello Java");                         l1.setFont(new Font("",Font.BOLD,14));                         l1.setForeground(Color.red);                         setSize(400,400);                        ...

Write a Multithreading program using Runnable interface to blink Text on the frame.

import java.awt.*; import java.awt.event.*; public class BlinkText extends Frame implements Runnable {             Thread t;             Label l1;             int f;             public BlinkText()             {                         t=new Thread(this);                         t.start();                         setLayout(null);                         l1=new Label("Hello JAVA");                         l1.setBounds(100,100,100,40);                         add(l1); ...

Write a MultiThreading program in java using Runnable interface to draw temple flag on an applet container.

import java.awt.*; import java.applet.*; /* <APPLET     code= "flag.class"  width= "500" height= "300">      </APPLET> */ public class flag extends Applet implements Runnable {             Thread t;             int x1,x2,x3,y3,x4,y4,x5,ln;             public void init()             {                         t=new Thread(this);                         t.start();                         ln=1;             }             public void run()             {             try{      if(ln==1) {       ...

Write a java program to simulate traffic signal using multithreading. import java.awt.*;

/*<applet code="signal.class" height=450 width=350> </applet>*/ public class signal extends java.applet.Applet implements Runnable {         Thread t;        int r,g1,y,i;     public void init()     {                   t=new Thread(this);              t.start();             r=0; g1=0; i=0; y=0;         }     public void run()     {    try{             for(i=24;i>=1;i--)          {                                     if (i>16&&i<=24)  {           t.sleep(200);                           ...