An array is a very common type of data structure where in all elements must be of the same data type.Once defined , the size of an array is fixed and cannot increase to accommodate more elements.
x[0]=0;
x[1]=1;
x[2]=2;
x[3]=3;
x[4]=4;
x[5]=5;
Using and array in your program is a 3 step process -
1) Declaring your Array
2) Constructing your Array
3) Initializing your Array
Syntax for Declaring Array Variables is
int intArray[];
// Defines that intArray is an ARRAY variable which will store integer values
int []intArray;
Constructing...
Sunday, 31 March 2013
Faces behind popular Programming Languages
1. Java (James Gosling)
2. C (Ken Thompson Left & Dennis Ritchie Right)
3. C++ (Bjarne Stroustrup)
4. Python (Guido van Rossum )
5. Fortran (John W. Backus)
6. Linux Kernel (Linus Benedict Torvalds)
7. Perl (Larry Wall)
8. C# (Development team led by Anders Hejlsberg)
9. Ruby (Yukihiro Matsumoto)
10. Ruby on Rails (RoR) (David Heinemeier Hansson)
11. JavaScript (Brendan Eich)
12. PHP (Rasmus Lerdo...
Friday, 22 March 2013
Compare Images In Java
package defaultt;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.io.File;
import javax.imageio.ImageIO;
public class CompareImage {
public static boolean compareImage(File fileA, File fileB) {
try {
// take buffer data from botm image files //
BufferedImage biA = ImageIO.read(fileA);
DataBuffer dbA = biA.getData().getDataBuffer();
int sizeA = dbA.getSize();
BufferedImage biB = ImageIO.read(fileB);
...
Tuesday, 19 March 2013
Casting in Java - when error, when exception?
Parent p1 = new Child();
Parent p2 = new Parent();
Child c1 = (Child) p2;
Child c2 = (Parent) p1;
The code above says,
1. Create an object Child and assign it to a ref to Parent p1 -- Thats ok, all Child can be ref by Parent like All Dogs can be ref by Animal... Dog IS A Animal
2. Create an object Parent and assign it to a ref of Parent p2 -- No doubt!.. that's prefect.
3. Cast a Parent to Child and store it on Child, please note we are not creating any object here. Now compiler...
Measuring elapsed time using Spring StopWatch
measuring elapsed time using Spring StopWatch
package Core;
import org.springframework.util.StopWatch;
public class ExecutionTimeStopWatch {
void method() throws InterruptedException
{
System.out.println("Execution Start");
Thread.sleep(2000);
int b = 12+7*88/9;
System.out.println("Execution End "+ b);
}
public static void main(String[] args) {
try {
StopWatch watch = new StopWatch();
ExecutionTime obj = new ExecutionTime();
watch.start();
obj.method();
watch.stop();
System.out.println("Time...
Monday, 18 March 2013
How To Calculate Execution Time Of Java Program
Using new Date.getTime();
package Core;
import java.util.Date;
public class ExecutionTime {
void method() throws InterruptedException
{
System.out.println("Execution Start");
Thread.sleep(2000);
int b = 12+7*88/9;
System.out.println("Execution End "+ b);
}
public static void main(String[] args) {
try {
ExecutionTime obj = new ExecutionTime();
long startTime = new Date().getTime();
obj.method();
long endTime = new Date().getTime();
System.out.println("Time Taken: "+ (endTime - startTime));
...
Thursday, 14 March 2013
Java Hashtable & Hashing
Hashtable is an implementation of a key-value pair data structure in java. You can store and retrieve a ‘value’ using a ‘key’ and it is an identifier of the value stored. It is obvious that the ‘key’ should be unique.
java.util.Hashtable extends Dictionary and implements Map. Objects with non-null value can be used as a key or value. Key of the Hashtable must implement hashcode() and equals() methods. By the end of this...