Choose Your Language

Thursday 12 September 2013

Generate QRCode using java

import java.io.*;
import java.util.Date;
import net.glxn.qrgen.image.ImageType;

public class QRCode {
    public static void main(String[] args) {
        ByteArrayOutputStream out = net.glxn.qrgen.QRCode.from("Aravind Sankaran").to(ImageType.PNG).stream();
 Date d=new Date();
 String filename="c:\\"+d.getTime()+".png";
        try {           
            FileOutputStream fout = new FileOutputStream(new File(filename));
            fout.write(out.toByteArray());
            fout.flush();
            fout.close();
        } catch (FileNotFoundException e) {
                       e.printStackTrace();
        } catch (IOException e) {
                       e.printStackTrace();
        }
    }
}

jar file:
qrgen-1.0.jar
zxing-core-1.7.jar
zxing-j2se-1.7.jar


How to add two numbers without using "+" symbol

public class AdditionWithoutPlusSymbol{
    public static void  main(String args[]){
        int a,b,c;
        a=10;b=20;
        c=(a-(-b));
        System.out.print("Addition Result is "+c);
    }
}

output:
Addition Result is 30

Wednesday 4 September 2013

How to install Android


System Requirements

1. Supported Operating Systems

*          Windows XP (32-bit) or Vista (32- or 64-bit)

*          Mac OS X 10.4.8 or later (x86 only)

*          Linux (tested on Linux Ubuntu Hardy Heron)

           
2. Supported Development Environments

*          Eclipse 3.4 (Ganymede) or 3.5 (Galileo)
           
*          JDK 5 or JDK 6 (JRE alone is not sufficient)

*          Android Development Tools plugin (optional)

*          Not compatible with Gnu Compiler for Java (gcj)
 

3.Other Development Environments or IDEs

*          JDK 5 or JDK 6 (JRE alone is not sufficient)

*          Apache Ant 1.6.5 or later for Linux and Mac, 1.7 or later for Windows

*          Not compatible with Gnu Compiler for Java (gcj)


Install android_sdk_windows_1.6

After downloading the Android SDK, unpack the Android SDK.zip archive to a suitable location on your machine. By default, the SDK files are unpacked into a directory named android_sdk_ <platform>_<release>. Here we are going to install android-sdk-windows-1.6_r1.

Make a note of the name and location of the unpacked SDK directory on your system — you will need to refer to the SDK directory later, when setting up the Android plugin or when using the SDK tools.

Optionally, you may want to add the location of the SDK's primary tools directory to your system PATH. The primary tools/ directory is located at the root of the SDK folder. Adding tools to your path lets you run Android Debug Bridge (adb) and the other command line tools without needing to supply the full path to the tools directory.

On Windows,

1. Right-click on My Computer, and select Properties.

2. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up,

3. Double-click on Path (under System Variables).

4. Add the full path to the tools/ directory to the path.

Example:
Set variable name as path &
variable value as,like D:\android-sdk-1.6_r1\tools

On Linux,

1. Edit your ~/.bash_profile or ~/.bashrc file.

2. Look for a line that sets the PATH environment variable and

3. Add the full path to the tools/ directory to it. If you don't see a line setting the path, you can add one:
export PATH=${PATH}:<your_sdk_dir>/tools

On a Mac,

Look in your home directory for .bash_profile and proceed as for Linux. You can create the .bash_profile if you haven't already set one up on your machine.

Note that, if you update your SDK in the future, you should remember to update your PATH settings to point to the new location, if different.

If you will be using the Eclipse IDE as your development environment, the next section describes how to install the Android Development Tools (ADT) plugin and set up Eclipse. If you choose not to use Eclipse, you can develop Android applications in an IDE of your choice and then compile, debug and deploy using the tools included in the SDK (skip to Next Steps).


Install the ADT Plugin for Eclipse

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, add components based on the Android Framework API, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application.
In general, using Eclipse with ADT is a highly recommended approach to Android development and is the fastest way to get started. (If you prefer to work in an IDE other than Eclipse, you do not need to install Eclipse or ADT, instead, you can directly use the SDK tools to build and debug your application—skip to Next Steps.)

Once you have the Eclipse IDE installed, as described in Preparing for Installation, follow the steps below to download the ADT plugin and install it in your respective Eclipse environment.


Eclipse 3.4 (Ganymede)

1. Start Eclipse, then select Help > Software Updates.... In the dialog that appears, click the Available Software tab.

2. Click Add Site...

3. In the Add Site dialog that appears, enter this URL in the "Location" field:
https://dl-ssl.google.com/android/eclipse/

Note: If you have trouble aqcuiring the plugin, try using "http" in the Location URL, instead of "https" (https is preferred for security reasons).

4. Click OK.

5. Back in the Available Software view, you should see the plugin listed by the URL, with "Developer Tools" nested within it. Select the checkbox next to Developer Tools and click Install...

6. On the subsequent Install window, "Android DDMS" and "Android Development Tools" should both be checked. Click Next.

7. Read and accept the license agreement, then click Finish

8. Restart Eclipse


Eclipse 3.5 (Galileo)

1. Start Eclipse, then select Help > Install New Softare.

2. In the Available Software dialog, click Add....

3. In the Add Site dialog that appears, enter a name for the remote site (e.g., "Android Plugin") in the "Name" field.
In the "Location" field, enter this URL:

https://dl-ssl.google.com/android/eclipse/

Note: If you have trouble aqcuiring the plugin, you can try using "http" in the URL, instead of "https" (https is preferred for security reasons).
Click Ok

4. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android

5 In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish.

6. Restart Eclipse.


Now modify your Eclipse preferences to point to the Android SDK directory:

1. Select Window > Preferences... to open the Preferences panel (Mac: Eclipse > Preferences).

2. Select Android from the left panel.

3. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.

4. Click Apply, then OK.

Done!If you haven't encountered any problems, then you're ready to begin developing Android applications.


What is android

Android is a Linux-based open source platform for mobile cellular handsets. Android was developed by Google and the Open Handset Alliance (OHA), a coalition of hardware, software and telecommunications companies oriented towards advancing mobile telephony standards.

Android platform includes an operating system based upon Linux, a GUI, a Web browser and many other applications considered key to a modern cellular handset. Android allows synchronization to a user's address book, calendar and other personal information management (PIM) programs, though individual software makers will have to customize their offerings.

Android will allow users to browse the Internet more easily, integrate mapping services with local business listings and use many other software features traditionally associated with personal computers rather than cellphones.

Android will run on both of the most widely deployed cellular standards, GSM/HSDPA and CDMA/EV-DO.

 Android will also support:
  • Bluetooth
  • EDGE
  • 3G Communication Protocols, like EV-DO and HSDPA
  • WiFi
  • SMS messaging
  • MMS
  • Video/Still Digital Cameras
  • Touchscreens
  • GPS
  • Compasses
  • Accelerometers
  • Accelerated 3D Graphics
         Android includes software built by many different entities. For instance, the default Android web browser will be based on Webkit, like Apple's Safari. Webkit was originally based on the Konquerer Web browser for Linux. Its music and video playback software was developed by PacketVideo. Applications are written using Java and are run on Dalvik, a virtual machine that runs on top of a Linux kernel.

Monday 15 July 2013

java program to read input from console

import java.io.Console;

public class ConsoleDemo {
   public static void main(String[] args) {    
     Console console = null;
     try{
         console = System.console();
          if (console != null) {
            String name  = console.readLine("Name: ");          
            char[] pwd = console.readPassword("Password: ");
            System.out.println("Name is: " + name);        
            System.out.println("Password is: "+pwd);
            System.out.println("Password is: "+new String(pwd));
          }    
      }catch(Exception ex){
         ex.printStackTrace();    
      }
   }
}

output:
Name: aravind
Password:
Name is: aravind
Password is: [C@1a758cb
Password is: sankaran

java program to delete duplicate entry in an array

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class DeleteDuplicate {

    static int[] a = {5,1,2,3,4,5,7,8,9,10};
    static int[] b = new int[10];
    static int f, i, k, j = 0;
    static int l = a.length;

    static void DeleteElementInt(int elementToDelete) {
        j = 0;
        for (int i = 0; i < l; i++)
            if (a[i] != elementToDelete){
                b[i - j] = a[i];}
            else{
                ++j;
        }
    }
static  int findDuplicate(){
    int num = 0;
    int best = 0;
    for (int i = 0; i < a.length; i++) {
    if (a[i] > best) {
        num = i;
        best = a[i];
    }   return best;
    }
    return best;
}

    public static void main(String[] args) {
       
    System.out.println("Array elements are:");
        for (i = 0; i < a.length; i++)
            System.out.print(a[i]+" ");
        InputStreamReader is = new InputStreamReader(System.in);
       System.out.println("");
       int duplicate=findDuplicate();
       System.out.println("Duplicate entry is "+duplicate);
            DeleteElementInt(duplicate);
            System.out.println("New array:");
            for (i = 0; i < l - j; i++)
                System.out.print(b[i]+" ");
           }
}
   
output:
Array elements are:
5 1 2 3 4 5 7 8 9 10
Duplicate entry is 5
New array:
1 2 3 4 7 8 9 10

Sunday 14 July 2013

java program to find default value of java primitive data types

public class DataTypeDefaultSize {   
     byte  b;
     boolean boo;
     char c;
     short s;
     int i ;
     long l;
     float f;     
     double d;        
     public static void main(String a[]) {
        DataTypeDefaultSize dataTypeDefaultSize=new DataTypeDefaultSize();
        dataTypeDefaultSize.displayDataTypeDefaultSize();
     }
     void displayDataTypeDefaultSize(){
         System.out.println("default value of byte is "+b);
         System.out.println("default value of boolean is "+boo); 
         System.out.println("default value of char is "+c);
         System.out.println("default value of short is "+s);
         System.out.println("default value of int is "+i);
         System.out.println("default value of long is "+l);
         System.out.println("default value of float is "+f);        
         System.out.println("default value of double is "+d);
       
     }
}


output:
default value of byte is 0
default value of boolean is false
default value of char is
default value of short is 0
default value of int is 0
default value of long is 0
default value of float is 0.0
default value of double is 0.0




java program to list all processes that are active in task manager

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Aravind Sankaran
 */
public class ListProcessesTaskManager {
    public static void main(String a[]) throws IOException{
       String processes;
       BufferedReader input = new BufferedReader(new  InputStreamReader(Runtime.getRuntime().exec("tasklist.exe").getInputStream()));
       while ((processes = input.readLine()) != null) {
               System.out.println(processes);
                }
        input.close();
    }
}




Thursday 11 July 2013

Java program to find run rate per over

import java.util.Scanner;
public class RunRateCalculator {

    int runs,over;   
    float runRate;
    public void findRunRate(){
         Scanner scanner=new Scanner(System.in);
         try{
            over=1;
            System.out.println("Enter Runs Scored: ");
            runs=scanner.nextInt();
            runRate=runs/over;
            System.out.println(runs+" runs in "+over+" over with a Run Rate of "+runRate+" per over.");   
        }
        catch(NumberFormatException nfe){
            System.out.println(nfe);
            }
        }

    public static void main(String[] abc){
        RunRateCalculator runRateCalculator=new RunRateCalculator ();       
        runRateCalculator.findRunRate();
    }
}

output:
Enter Runs Scored:
10
10 runs in 1 over with a Run Rate of 10.0 per over

How to run java program without main method

public class WithOutMainMethod{
static {
   WithOutMainMethod withOutMainMethod=new WithOutMainMethod();
   System.out.println("inside static block!");
   staticMethod();
   withOutMainMethod.nonStaticMethod();
   System.exit(0);
}
   static  void staticMethod(){
       System.out.println("inside static method!");

   }
   void nonStaticMethod(){
       System.out.println("inside non static method!");

   }
}

output:
inside static block!
inside static method!
inside non static method!

Calculate strike rate of a batsman using java program

public class StrikeRateCalculator {
   
    int ballsFaced, runScored;
    double strikeRate;
    public void findStrikeRate(){
        Scanner scanner=new Scanner(System.in);
         try{
            System.out.println("Enter Runs Scored: ");
            runScored=scanner.nextInt();
            System.out.println("Enter Balls Faced: ");
            ballsFaced=scanner.nextInt();
            strikeRate=(100*runScored)/ballsFaced;
            System.out.println(runScored+" runs scored in "+ballsFaced+" balls, Strike Rate is: "+strikeRate);
        }
        catch(NumberFormatException nfe){
            System.out.println(nfe);           
        }
       
    }

    public static void main(String[] args){
        StrikeRateCalculator strikeRateCalculator=new StrikeRateCalculator();      
        strikeRateCalculator.findStrikeRate();
      
    }
}

Java program to open control panel

import java.io.IOException;

/**
 *
 * @author Aravind Sankaran
 */
public class ControlPanel {
     public static void main(String[] abc){
        try{
             Runtime.getRuntime().exec("control.exe");
            }
        catch(IOException ioe){
            System.err.println(ioe);           
        }
    }
}

Open command prompt using java program

import java.io.IOException;

/**
 *
 * @author Aravind Sankaran
 */
public class OpenCommandPrompt{
     public static void main(String[] abc) {
    try {
          Runtime.getRuntime().exec("cmd /c start ");
         }
    catch (IOException e) {
      System.out.println(e);
        }  
  }
}

Java program to open a notepad

import java.io.IOException;

/**
 *
 * @author Aravind Sankaran
 */
public class OpenNotepad {
     public static void main(String[] abc) {
      try {
            Runtime.getRuntime().exec("notepad");
           }
    catch (IOException e) {
      System.out.println(e);
    }  
  }
}

Java Program to find IP Address of a given site

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.InetAddress;

/**
 *
 * @author Aravind Sankaran
 */
public class IPAddressFinder {
     public static void main(String args[]) throws Exception
   {
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       System.out.println("enter the site address");
       String siteName=br.readLine();
       System.out.println(InetAddress.getByName(siteName));     
   }
}

output:
enter the site address
www.facebook.com
www.facebook.com/31.13.72.33

Java program to print alphabets in capital and small letters

public class DisplayAlphabets {
    public static void main(String abc[])
   {
      char alphabets;

       for( alphabets = 'a' ; alphabets <= 'z' ; alphabets++ )
       {
         System.out.print(alphabets+" ");
       }
       System.out.println("");
       for( alphabets = 'A' ; alphabets <= 'Z' ; alphabets++ )
       {
         System.out.print(alphabets+" ");
       }
   }  
  
}

output:
a b c d e f g h i j k l m n o p q r s t u v w x y z 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Saturday 29 June 2013

Dictionary application using JAVA, JSP, AJAX and MySql with source code

Project Structure:

index.jsp

<%--
    Document   : index
    Created on : 29 Jun, 2013, 11:03:21 PM
    Author     : Aravind Sankaran
--%>

<%@page import="com.dictionary.common.LoadMyProperties"%>
<%@page import="com.dictionary.bean.DictionaryBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
DictionaryBean bean=new DictionaryBean();
            LoadMyProperties loadMyProperties=new  LoadMyProperties();          
            bean=loadMyProperties.getMyPropertiesFile(bean);
            String typeaword=bean.getTypeaword();
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Dictionary</title>
        <script type="text/javascript">

function loadXMLDoc1()
{
var xmlhttp;

var word=document.getElementById("word").value;

var urls="getmeaning.jsp?word="+word;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4)
    {
       
        document.getElementById("err1").innerHTML=xmlhttp.responseText;

    }
  }
xmlhttp.open("GET",urls,true);
xmlhttp.send();
}
</script>
    </head>
    <body>
        <table>
            <tr>
            <td>
          <form method="post" action="/Dictionary/Login">
          <table>
                  <tr>
                      <td></td><td></td><td><b><a href="" style="text-decoration: blink;">Login here&nbsp;</a></b></td>
                  </tr>
                  <tr>
                      <td>User Name</td><td>&nbsp;</td><td><input type="text" name="username"></td>
                  </tr>
                  <tr>
                      <td>Password</td><td>&nbsp;</td><td><input type="password" name="password"></td>
                  </tr>
                  <tr><td>&nbsp;</td>
                      <td></td><td><input type="submit" value="login" ></td>
                  </tr>
              </table>
          </form>
              </td>
              </tr>
        </table>
        <p>
            <center>
                <table width="30%" border="0">
                <tr>
                    <td>&nbsp;</td>
                    <td><b>Dictionary: </b></td>  
                    <td><b>The universe in alphabetical order</b></td>
                    <td>&nbsp;</td>   
                </tr><br><br>
                <tr>
                    <td>&nbsp;</td>
                    <td></td>  
                    <td></td>
                    <td>&nbsp;</td>   
                </tr><br><br>
                <tr>
                    <td>&nbsp;</td>
                    <td><b><%=typeaword%></b></td>  
                    <td><input type="text" name="word" id="word"  onkeyup="loadXMLDoc1()"></td>
                    <td>&nbsp;</td>
                </tr> 
                </table>
            </center><br><br>
            <span id="err1"> </span>
        </p>
       
</body>
</html>

getmeaning.jsp

<%--
    Document   : getmeaning
    Created on : 29 Jun, 2013, 11:26:25 PM
    Author     : Aravind Sankaran
--%>

<%@page import="com.dictionary.common.LoadMyProperties"%>
<%@page import="com.dictionary.bean.DictionaryBean"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%String word=request.getParameter("word");%>

<%! static Connection con;%>

<%
DictionaryBean bean=new DictionaryBean();
            LoadMyProperties loadMyProperties=new  LoadMyProperties();          
            bean=loadMyProperties.getMyPropertiesFile(bean);
            String dbUrl=bean.getDbUrl();
            String dbName=bean.getDbName();
            String dbUserName=bean.getDbUserName();
            String dbPassword=bean.getDbPassword();
            String driverName=bean.getDriverName();
 String typeaword=bean.getTypeaword();
 String errorMessage=bean.getErrorMessage();
 String newline=bean.getNewline();
 String outputmeaning=bean.getOutputmeaning();
Class.forName(driverName);
con=DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("select * from wordmeaning where word like '"+word+"%'");

%>

<!DOCTYPE html>
<%

 if(rs.next())
                    { 
    String words=rs.getString("word");    
    String meanings=rs.getString("meaning");
                        out.println("<center>");
                        out.println("<table width='30%'>");
                        out.println("<tr>");
                        out.println("<td><b><font size='5' color=black>"+words+":-</font></b></td>");
                        out.println("<td>&nbsp;&nbsp;&nbsp;</td>");
                        out.println("<td><b><font color=red></font></b></td>");                       
                        out.println("</tr>");
                       
                        out.println("<tr>");
                        out.println("<td></td>");
                        out.println("<td>&nbsp;&nbsp;&nbsp;</td>");
                        out.println("<td></td>");                       
                        out.println("</tr>");
                       
                        out.println("<tr>");
                        out.println("<td><b><font color=black>"+outputmeaning+"</font></b></td>");
                        out.println("<td>&nbsp;&nbsp;&nbsp;</td>");
                        out.println("<td><b><font color=red>"+meanings+"</font></b></td>");                       
                        out.println("</tr>");
                        out.println("</table>");
                        out.println("<center>");
                       
                        out.println("<tr>");
                        out.println("<td></td>");
                        out.println("<td><font color=black>"+newline+"</font></b></td>");
                        out.println("<td></td>");                       
                        out.println("</tr>");
                 
}else {
                        out.println("<center>");
                        out.println("<table>");
                        out.println("<tr>");
                        out.println("<td><b><font color=black>"+errorMessage+"</font></b></td>");                                              
                        out.println("</tr>");
                        out.println("</table>");
                        out.println("</center>");
                    }
rs.close();
s.close();
con.close();

%>

admin.jsp

<%--
    Document   : admin
    Created on : 29 Jun, 2013, 11:28:15 PM
    Author     : Aravind Sankaran
--%>

<%@page import="com.dictionary.common.LoadMyProperties"%>
<%@page import="com.dictionary.bean.DictionaryBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% String un=request.getParameter("un");%>
<%
DictionaryBean bean=new DictionaryBean();
            LoadMyProperties loadMyProperties=new  LoadMyProperties();          
            bean=loadMyProperties.getMyPropertiesFile(bean);
            String typeaword=bean.getTypeaword();
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <p>
          <form method="post" action="/Dictionary/AddNewWords">       
     
      <center>
              <table width="50%" border="0">
              <tr>
                  <td>&nbsp;</td>
                  <td><b>Word</b></td>  
                  <td><input type="text" name="word"  ></td>
                  <td>&nbsp;</td>
              </tr>
              <tr>
                  <td>&nbsp;</td>
                  <td><b></b></td>  
                  <td></td>
                  <td>&nbsp;</td>
              </tr>
              <tr>
              <td>&nbsp;</td>
              <td><b>Meaning</b></td>  
              <td><textarea name="meaning" rows="5" cols="18"></textarea></td>
              <td>&nbsp;</td>
              </tr>
              <tr>
              <td>&nbsp;</td>
              <td><b></b></td>  
              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="SUBMIT"></td>
              <td>&nbsp;</td>
              </tr> 
              </table>
              </form>
        </p>
    </body>
</html>

com.dictionary.bean package

1.DictionaryBean.java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dictionary.bean;

/**
 *
 * @author Aravind Sankaran
 */
public class DictionaryBean {
   
private String  userName;
private String userPassword;
private String  dbName;
private String dbUserName;
private String dbPassword;;
private String dbUrl;
private String word;
private String meaning;
private String driverName;
private String typeaword;
private String errorMessage;
private String newline;
private String outputmeaning;
private boolean valid;
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserPassword() {
        return userPassword;
    }

    public void setUserPassword(String userPassword) {
        this.userPassword = userPassword;
    }

    public String getDbName() {
        return dbName;
    }

    public String getDriverName() {
        return driverName;
    }

    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public String getNewline() {
        return newline;
    }

    public void setNewline(String newline) {
        this.newline = newline;
    }

    public String getOutputmeaning() {
        return outputmeaning;
    }

    public void setOutputmeaning(String outputmeaning) {
        this.outputmeaning = outputmeaning;
    }

    public String getTypeaword() {
        return typeaword;
    }

    public void setTypeaword(String typeaword) {
        this.typeaword = typeaword;
    }

    public void setDbName(String dbName) {
        this.dbName = dbName;
    }


    public String getDbPassword() {
        return dbPassword;
    }

    public void setDbPassword(String dbPassword) {
        this.dbPassword = dbPassword;
    }

    public String getDbUrl() {
        return dbUrl;
    }

    public void setDbUrl(String dbUrl) {
        this.dbUrl = dbUrl;
    }

    public String getDbUserName() {
        return dbUserName;
    }

    public void setDbUserName(String dbUserName) {
        this.dbUserName = dbUserName;
    }

    public String getMeaning() {
        return meaning;
    }

    public void setMeaning(String meaning) {
        this.meaning = meaning;
    }

    public boolean isValid() {
        return valid;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    public String getWord() {
        return word;
    }

    public void setWord(String word) {
        this.word = word;
    }
}

com.dictionary.common package 
1. AddNewWords.java

package com.dictionary.common;
import com.dictionary.bean.DictionaryBean;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AddNewWords extends HttpServlet {
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       // processRequest(request, response);
        String word=request.getParameter("word");
        String meaning=request.getParameter("meaning");
        DictionaryBean db=new DictionaryBean();
        db.setWord(word);
        db.setMeaning(meaning);
      
        db=Operations.addNewWord(db);
        if(db.isValid()){
            HttpSession session=request.getSession(true);
            session.setAttribute("admin", db);
            response.sendRedirect("admin.jsp");
        }else{
            response.sendRedirect("index.jsp");
        }
    }

}

2.DbConnect.java

package com.dictionary.common;
import com.dictionary.bean.DictionaryBean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Aravind Sankaran
 */
public class DbConnect {
static Connection con=null;      
    public static Connection getConnection(){
        try{
            DictionaryBean bean=new DictionaryBean();
            LoadMyProperties loadMyProperties=new  LoadMyProperties();          
            bean=loadMyProperties.getMyPropertiesFile(bean);
            String dbUrl=bean.getDbUrl();
            String dbName=bean.getDbName();
            String dbUserName=bean.getDbUserName();
            String dbPassword=bean.getDbPassword();
            String driverName=bean.getDriverName();
            Class.forName(driverName);
            try{
            con=DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
            System.out.println("connection occured");          
            }
            catch(SQLException se){
               
            }
        }catch(ClassNotFoundException e){
           
        }
      return con;
    }
}

3.LoadMyProperties.java

package com.dictionary.common;
import com.dictionary.bean.DictionaryBean;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author Aravind Sankaran
 */
public class LoadMyProperties {
 Properties configProp=new Properties();
     public DictionaryBean getMyPropertiesFile(DictionaryBean myBean){   
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/dictionary/resources/db.properties");
        try {
          configProp.load(in);
          String dbUrl=configProp.getProperty("dbUrl");
          String dbName=configProp.getProperty("dbName");
          String dbUserName=configProp.getProperty("dbUserName");
          String dbPassword=configProp.getProperty("dbPassword");
        
          String driverName=configProp.getProperty("driverName");
          String typeaword=configProp.getProperty("typeaword");
          String errorMessage=configProp.getProperty("errorMessage");
          String newline=configProp.getProperty("newline");
          String outputmeaning=configProp.getProperty("outputmeaning");
         
          myBean.setDbUrl(dbUrl);
          myBean.setDbName(dbName);
          myBean.setDbUserName(dbUserName);
          myBean.setDbPassword(dbPassword);
         
          myBean.setDriverName(driverName);
          myBean.setTypeaword(typeaword);
          myBean.setErrorMessage(errorMessage);
          myBean.setNewline(newline);
          myBean.setOutputmeaning(outputmeaning);
          myBean.setValid(true);
        } catch (IOException e) {
            e.printStackTrace();
        }      
      
        return myBean;
    }
}

 4.Login.java

package com.dictionary.common;
import com.dictionary.bean.DictionaryBean;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 public class Login extends HttpServlet {
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
      //  processRequest(request, response);
        String userName=request.getParameter("username");
        String userPassword=request.getParameter("password");
        DictionaryBean db=new DictionaryBean();
        db.setUserName(userName);
        db.setUserPassword(userPassword);      
        db=Operations.login(db);
        if(db.isValid()){
            HttpSession session=request.getSession(true);
            session.setAttribute("admin", db);
            String un=db.getUserName();
            response.sendRedirect("admin.jsp?un="+un);
        }else{
            response.sendRedirect("index.jsp");
        }
    }
}

5. Operations.java

package com.dictionary.common;
import com.dictionary.bean.DictionaryBean;
import java.sql.*;

/**
 *
 * @author Aravind Sankaran
 */
public class Operations {
 public static DictionaryBean login(DictionaryBean bean){
        String userName=bean.getUserName();
        String userPassword=bean.getUserPassword();
        String query="select * from login where username='"+userName+"' AND password='"+userPassword+"'";
        Connection con=DbConnect.getConnection();
        try {
            Statement st=con.createStatement();
            ResultSet rs=st.executeQuery(query);
            boolean more=rs.next();{
            if(!more){
                System.out.print("no more records");
                bean.setValid(false);
            }else if(more){
             
               String username=rs.getString("username");
               String password=rs.getString("password");
               bean.setUserName(username);               
               bean.setUserPassword(password);
               bean.setValid(true);
            }
        }
        } catch (SQLException ex) {
           System.out.println("error occured in Login Operations");
        }
        return bean;
    }
  
    public static DictionaryBean addNewWord(DictionaryBean bean){
        String word=bean.getWord();
        String meaning=bean.getMeaning();
        PreparedStatement ps= null;

        String query="insert into wordmeaning(word,meaning) values(?,?)";
        Connection con=DbConnect.getConnection();
        try {
            ps=(PreparedStatement) con.prepareStatement(query);
            ps.setString(1, word);
            ps.setString(2, meaning);           
            ps.executeUpdate();
         
            bean.setWord(word);         
            bean.setMeaning(meaning);
            bean.setValid(true);
        } catch (SQLException ex) {
           System.out.println("error occured in adding new word ");
        }
        return bean;
    }
}
}
com.dictionary.resources  package

db.properties

dbUrl=jdbc:mysql://localhost:3306/dictionary?
dbName=dictionary
dbUserName=root
dbPassword=root
driverName=com.mysql.jdbc.Driver
typeaword=Type a word:
errorMessage=If a word in the dictionary were misspelled, how would we know?
newline=-----------------------
outputmeaning=Meaning:

jar file:

mysql-connector-java-3.1.14-bin.jar

Output: