Posts

Java Program to Check Palindrome Number in Java

 import java.util.Scanner; public class PalindromeNumber {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         System.out.print("Enter an integer number: ");         int original = sc.nextInt();         int reversed = 0;         int temp = original;         while (temp != 0) {             int digit = temp % 10;     // get last digit             reversed = reversed * 10 + digit;  // build reversed number             temp = temp / 10;          // remove last digit         }         if (original == reversed) {             System.out.println(original + " is a Palindrome number");         } el...

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");           ...