LinkedList in Java

Linked List implementation in Java… ====================Node.java===================== Java public class Node { int key; Node link; public void setKey(int key) { this.key = key; } public int getKey() { return this.key; } public void setLink(Node node) { this.link = node; } public Node getLink() { return this.link; } public static Node createNode(int key, Node link) { ...

JSch example

Description : This program will explode the myapp.tar present in myHome directory and then navigation will be moved to “scripts” directory, generated after exploding the tar and then run “ls” command   Input : hostname,username, password Output: output of each command will be printed to console   Java package com.coddicted.example; import java.io.InputStream; import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.JSch; import ...

First and Last Day of Month

The following code enables you to find the first and last day of a month in your JAVA code. package others; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class DateTest { /** * @param args */ public static void main(String[] args) { Date dt = null; // Get the last day of Feb. 2012 dt ...

Vampire Numbers 1

Table of ContentsWhat are Vampire numbers?Java Description: The following programs finds out all the 4 digit Vampire numbers defined as follows: What are Vampire numbers? A vampire number has an even number of digits and is formed by multiplying a pair of numbers containing half the number of digits of the result. The digits are ...

File Splitter

 Description:          The following two programs split any specified file in size of specified size (in bytes).   Primary Inputs:    Name of the file to be divided and the desired size(in bytes) of the target parts. Primary Output:    File part(s) of the size specified in input. Platform Used:      JDK 1.6 with JCreator   //File Name: SplitFile.java //SplitFile.java //Contains the main function ...

Display numeric value in reverse order

Example: given a number say 7584, the program should display it in reverse order 4857. public class Reverse { public static void main(String args[]) { int i = 7584; Reverse r = new Reverse(); r.reverseNum(i); } public void reverseNum(int num) { if(num!=0) { System.out.print(num%10); num = num/10; reverseNum(num); } } }

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