Posts

Showing posts from September 22, 2013

We need to write the function to check the password entered is correct or based on the following conditions..

a) It must have atleast one lower case character and one digit. b)It must not have any Upper case characters c) length should be b/w 5-12. d) It should not have any same immediate patterns like abcanan1 : not acceptable coz of an an pattern abc11se: not acceptable, coz of pattern 11 123sd123 : acceptable, as not immediate pattern adfasdsdf : not acceptable, as no digits Aasdfasd12: not acceptable, as have uppercase character Solution : package assignment1; import java.util.Scanner; /**  * @author Snlkjha  */ public class ValidPassword {   /*It must have atleast one lower case character*/   public static boolean islower(String password){     char pass[]=password.toCharArray();     for(int i=0;i<pass.length;i++)         if((int)pass[i]>=97 &&(int)pass[i]<=122) return true;       return false; } /*It must not have any Upper case characters*/ public static boolean isup...

A string of characters is given.Find the highest occurrence of a character and display that character.

eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE OUTPUT: E or I,J(if equal occurance) package assignment1; /*  * @author snlkjha  */ public class Charfreq {         public static void charFreq(String x){                 String toUpperCase = x.toUpperCase();   /*If the given string is in lower case or mixed case , convert it into upper case.*/         char y[]=toUpperCase.toCharArray();         int freq[]=new int[26],max=0;         for(int i=0;i<y.length;i++) ++freq[(int)y[i]-65];         System.out.println("________________________________________");         for(int i=0;i<y.length;i++)             if(freq[i]!=0)  System.out.println((char)(i+65)+" "+freq[i]);         for(int i=1;i<freq.length;i++)  max=freq[max]<freq[i]?i:max;   ...

Code to upload multiple files simultaneously using JSP, Servlet .

Image
Step 1 : Create a jsp page. index.jsp <%--      Document   : index     Created on : 21 Sep, 2013, 5:58:32 PM     Author     : snlkjha --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html>     <head>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">         <title>JSP Page</title>     </head>     <body>         <form action="UploadServlet" method="post" enctype="multipart/form-data">             <input type="file" id="file" name="file1" accept="image/*"  multiple="muliple" required/><br>             <input type="submit"/>            <br><br> ${requestScope.message} ...

Code to create Zip file using Java .

/*  * To change this template, choose Tools | Templates  * and open the template in the editor.  */ package Java_Classes; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /**  *  * @author snlkjha  */ public class Zip {     public static void zipFolder(String srcFolder) throws Exception {         FileOutputStream fileWriter = new FileOutputStream(srcFolder + ".zip");         ZipOutputStream zip = new ZipOutputStream(fileWriter);         addFolderToZip("", srcFolder, zip);         zip.flush();         zip.close();     }     private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws Exception {         File folder = new File(srcFolder);   ...