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

Adding rows and columns in JTable dynamically 5

Adding rows and columns in JTable dynamically
Java Source code to add Row and Column in JTable dynamically package com.example; import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Vector; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.WindowConstants; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; public class JTableSample { private JFrame mainFrame ; private JTable ...

Russian Peasant Multiplication 2

Russian Peasant Multiplication
Description: Russian Peasant Multiplication. This program allows one to do multiplication by just doing muliplication or division by 2 (and addition). This is interesting since computers generally use base 2 arithmetic.The algorithm is as follows. Start two rows, one with the multiplicand (say, A) and the other the multiplier (say B). The goal is to ...