Day of Week

 Description:          The following program takes three numbers as input date: month, date, year and returns the week-day corresponding to it.                             Primary Inputs:    Three numbers (month m, day d, year yyyy) Primary Output:    Determine the week-day (sunday, monday etc.) for the input date. Platform Used:      JDK 1.6 with Notepad.   import java.io.*; class DayOfWeek { public static void main(String[] args) { // ...

Custom JComboBox with Autocompletion

Custom JComboBox with Autocompletion
———————————–SearchBoxModel.java——————————————— package com.example; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.ArrayList; import javax.swing.AbstractListModel; import javax.swing.ComboBoxEditor; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; import javax.swing.JTextField; public class SearchBoxModel extends AbstractListModel implements ComboBoxModel, KeyListener, ItemListener { private static final long serialVersionUID = 1L; ArrayList db = new ArrayList(); ArrayList data = new ArrayList(); String selection; JComboBox cb; ComboBoxEditor ...

Creating xls file from properties file

Description : The following program read a properties files(yes, they cann be multiple), create a xls file and add properties file name, key and value pair in that xls file   Primary Input : 1. Path of the directory where properties files are present.(Currently ,hard-coded) 2. Location and name of xls file (to be created)(also, hard-coded)   Primary Output: xls file with ...

Convert dateTime from one Time-zone to another

import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; public class ConvertTimeZone { public static void main(String args[]) { // here we are assuming that we have // date/Time in Africa/Harare(UTC+02) // Time zone // Africa/Harare -> 02/29/2012 23:59:36 String fromTimeZone = "Africa/Harare"; // we want to convert it into // Asia/Riyadh(UTC+03) Time Zone // Asia/Riyadh -> 03/01/2012 ...

Connecting to MySQL in Java Code

Follow the steps below to have a basic program that would connect to your MySQL DB: 1.       First of all make sure that your MySQL installation is proper and the DB services are up and running fine. (We are assuming that you’ve setup your DB on localhost. This example, however, is not limited to this and ...

Binary Tree

Binary tree implementation in java <<<<<<<<<<<<<<<<<BinaryTreeNode.java>>>>>>>>>>>>>>>>>>>>>>> public class BinaryTreeNode { private int key; private BinaryTreeNode leftLink; private BinaryTreeNode rightLink; public void setKey(int key) { this.key = key; } public int getKey() { return this.key; } public void setLeftLink(BinaryTreeNode bNode) { this.leftLink = bNode; } public void setRightLink(BinaryTreeNode bNode) { this.rightLink = bNode; } public BinaryTreeNode ...

Binary Search

Binary Search algorithm implementation in Java import java.io.Console; public class BinarySearch { static int[] numArr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; public static void main(String args[]) { for (int i = 0; i < numArr.length; i++) { System.out.print(numArr[i] + "\t"); } System.out.println("\n"); System.out.print("Search? :"); Console con = System.console(); ...

Truncate, Delete and Drop

DELETE The DELETE command is used to remove rows from a table. A WHERE clause can be used to only remove some rows. If no WHERE condition is specified, all rows will be removed. After performing a DELETE operation you need to COMMIT or ROLLBACK the transaction to make the change permanent or to undo ...

Triggers and Indexes

Triggers SQL Triggers are SQL Statements or a set SQL of statements which is stored to be activated or fired when an event associating with a database table , view or schema occurs. The event can be INSERT, UPDATE and DELETE. SQL Triggers provides an alternative way to check integrity and to run scheduled tasks. However, ...

Stored Procedures and Functions

Difference between Stored Procedures and Functions   Stored procedures are a set of actions  already written  and stored inside database  for achieving a particular task. Functions are general databse objects which are  used for general purpose programming.        S.No.                                  Stored Procedures                                             Functions  1.  Procedures may return none or more values  Functions must always return one value either a ...