difference between an interface and an abstract class

What's the difference between an interface and an abstract class? Also discuss the similarities. (Very Important)
Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. Interface is a Java Object containing method declaration and doesn't contain implementation. The classes which have implementing the Interfaces must provide the method definition for all the methods
Abstract class is a Class prefix with a abstract keyword followed by Class definition. Interface is a Interface which starts with interface keyword.
Abstract class contains one or more abstract methods. where as Interface contains all abstract methods and final declarations
Abstract classes are useful in a situation that Some general methods should be implemented and specialization behavior should be implemented by child classes. Interfaces are useful in a situation that all properties should be implemented.

Differences are as follows:
* Interfaces provide a form of multiple inheritance. A class can extend only one other class.
* Interfaces are limited to public methods and constants with no implementation. Abstract classes can have a partial implementation, protected parts, static methods, etc.
* A Class may implement several interfaces. But in case of abstract class, a class may extend only one abstract class.
* Interfaces are slow as it requires extra indirection to to find corresponding method in in the actual class. Abstract classes are fast. 

Similarities:

* Neither Abstract classes or Interface can be instantiated.


How to define an Abstract class?
A class containing abstract method is called Abstract class. An Abstract class can't be instantiated.
Example of Abstract class:

abstract class testAbstractClass { 
    protected String myString; 
    public String getMyString() { 
    return myString; 

public abstract string anyAbstractFunction();
}

How to define an Interface?Answer: In Java Interface defines the methods but does not implement them. Interface can include constants. A class that implements the interfaces is bound to implement all the methods defined in Interface.
Example of Interface:

public interface sampleInterface {
    public void functionOne();
    public long CONSTANT_ONE = 1000;
}

Adding image to JPanel Java

Adding Image to JPanel

BufferedImage myPicture = ImageIO.read(new File("path-to-file"));
JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
add( picLabel );

:D

Read time from internet time server - working java code

Read time from internet time server - working java code
import java.io.*;
import java.net.*;
import java.util.*;

/**
 * This program makes a socket connection to the atomic clock in Boulder,
 * Colorado, and prints the time that the server sends.
 */
public class Time_Server_Socket_Test_Java {
    public static void main(String[] args) {
        try {
            Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
            try {
                InputStream inStream = s.getInputStream();
                Scanner in = new Scanner(inStream);

                while (in.hasNextLine()) {
                    String line = in.nextLine();
                    System.out.println(line);
                }
            } finally {
                s.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



iterate through map hashmap linkedhashmap in java

How to iterate through Map.. MashMap, LinkedHashMap ...  in Java
Method 1 : If you're only interested in the keys, you can iterate through the keySet() of the map:
Map map = ...;
for (String key : map.keySet()) {
    // ...
}

Method 2 :

java escape text in regular expression

Java's a built-in way to escape arbitrary text so that it can be included in a regular expression-
For example, users enter "$5", we can match that exactly rather than a "5" after the end of input.


Just do this : to escape text in regex
Pattern.quote("$5");

use of @override annotation in java - why ?

The @override annotation  is most useful as a compile-time reminder that the intention of the method is to override a parent method. See this example:

import java.util.HashSet;
import java.util.Set;
/**
 * Override_Annotation_Usage_Example, from  Effective Java
 */

java reflection - what is - 101 tutorial


The name reflection is used to describe code which is able to inspect other code in the same system (or itself).
A simple code example of this in Java (imagine the object in question is foo) :
Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
One very common use case in Java is the usage with annotations. JUnit 4, for example, will use reflection to look through your classes for methods tagged with the @Test annotation, and will then call them when running the unit test.
There are some good reflection examples to get started : at http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html

Bubble sort working source code - C/C++

Bubble sort working source code - C/C++
#include <stdio.h>
#include <iostream.h>

void bubbleSort(int *array,int length)//Bubble sort function 
{
    int i,j;
    for(i=0;i<length;i++)
    {
        for(j=0;j<i;j++)
        {
            if(array[i]>array[j])
            {
                int temp=array[i]; //swap 
                array[i]=array[j];
                array[j]=temp;
            }
        }
    }
}

void printElements(int *array,int length) //print array elements
{
    int i=0;
    for(i=0;i<length;i++)
        cout<<array[i]<<endl;
}


void main()
{

    int a[]={9,6,5,23,2,6,2,7,1,8};   // array to sort 
    bubbleSort(a,10);                 //call to bubble sort  
    printElements(a,10);               // print elements 
}


C C++ CODE : Shooting method for solving boundary value problem

Working C C++  Source code program for Shooting method for solving boundary value problem
#include<iostream.h>
#include<conio.h>
float f1(float ,float,float);
float f2(float, float ,float);
int main()
{
    int i;

C C++ CODE : Simpsons 1/3 rule for integration

Working C C++  Source code program for Simpsons 1/3 rule for integration
/************** SIPMPSONS 1/3 RULE ***********************/

#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
    char choice='y';
    float f,x,h,a,b,sum;
    clrscr();
    cout<<"a & b ? ";cin>>a>>b;
    do
    {
        sum=0;
        x=a;
        cout<<"Enter value of h ? ";cin>>h;
        while(x<b)
        {
            sum+=(funct(x)+4*funct(x+h)+funct(x+2*h));
            x=x+2*h;
        }
        cout<<endl<<"The integration is: "<<sum*h/3<<endl;
        cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
    }while(choice=='y');
    getch();
    return 0;
}

float funct(float x)
{
    return x*exp(x)-2;   // sin takes arguments in radian........
}