Thursday, October 28, 2010

Difference between HTTP and HTTPS

HTTP and HTTPS

The main difference between http:// and https:// is It's all about keeping you secure HTTP stands for HyperText Transport Protocol, which is just a fancy way of saying it's a protocol (a language, in a manner of speaking) for information to be passed back and forth between web servers and clients.
The important thing is the letter S which makes the difference between HTTP and HTTPS.
The S (big surprise) stands for "Secure". If you visit a website or webpage, and look at the address in the web browser, it will likely begin with the following: http://. This means that the website is talking to your browser using the regular 'unsecure' language. In other words, it is possible for someone to "eavesdrop" on your computer's conversation with the website. If you fill out a form on the website, someone might see the information you send to that site. This is why you never ever enter your credit card number in an http website!
But if the web address begins with https://, that basically means your computer is talking to the website in a secure code that no one can eavesdrop on.
You understand why this is so important, right? If a website ever asks you to enter your credit card information, you should automatically look to see if the web address begins with https://. If it doesn't, there's no way you're going to enter sensitive information like a credit card number!

Thursday, September 2, 2010

Java Threads : Using Callable

                      Threads , the first thing which comes to mind is the Runnable Interface. Callable is an interface introduced in Java 5 to take care of this specific requirement. Callable is similar to Runnable, but it returns a value.  A Future interface holds the result of asynchronous computation and it is used in conjunction with Callable. FutureTask is a wrapper class which implements both Future and Runnable interfaces and it provides a convenient way to convert a Callable into both a Future and a Runnable.

Lets see an example which implements the same:


Make a StringGenerator Class:

import java.util.concurrent.Callable;
import static java.lang.Math.random;

public class StringGenerator implements Callable {

    public String call() throws Exception {
        String [] allStrings =
                {"Wine", "Movies", "Party", "Books", "Shopping",
                "Flowers", "Food", "Music", "Cars","Jewelery"};
        int index = (int)(random()*100)/10;

        //Let's wait for sometime
        Thread.sleep(2000);
        return allStrings[index];
    }
}


Next make a StringGeneratorTest class:

import java.util.ArrayList;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;


public class StringGeneratorTest {

    public static void main(String[] args) {

        //Create an array to store the future objects.
        ArrayList> results = new ArrayList>();
        for (int i=0; i<10; i++){
            //Create the instance of the Callable task
                        Callable stringGenerator = new StringGenerator();

            //create the object of FutureTask
            FutureTask task =
                                new FutureTask(stringGenerator);

            //Add to the list
            results.add(task);

            //Create a thread object using the task object created
            Thread t = new Thread(task);

            //Start the thread as usual
            t.start();

        }

        //Compute the results now.
        StringBuilder resultStr = new StringBuilder();

        long start = System.currentTimeMillis();

        for(Future result: results){
            try {
                //The blocking get call
                resultStr.append(result.get());
                resultStr.append(" ");

            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }

        long end = System.currentTimeMillis();

        System.out.println("The returned string is:\n"+resultStr);
        System.out.println("Execution time:"+(end - start));
    }
}

Output:
The returned string is:
Shopping Party Party Flowers Books Wine Wine Flowers Music Cars
Execution time:1002

Explanation:
Create a StringGenerator thread which is supposed to return a random string to the caller. Create a StringGeneratorTest class which spawns ten StringGenerator thread and displays the concatenation of the string returned from all the threads.


Hope this helped !!! Cheers !! :-)

References:

Thursday, August 19, 2010

Removing Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory!!

Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
at org.apache.catalina.startup.Bootstrap.(Bootstrap.java:54)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
… 1 more
Could not find the main class: org.apache.catalina.startup.Bootstrap. Program will exit.

Solutions

1. In Eclipse, Open the “Server” tab.
2. Double click on the “Tomcat6″ entry to see the configuration.
3. Then click on the “Open launch configuration” link in the “General information” block.
4. In the dialog, select the “Classpath” tab.
5. Click the “Add external jar” button.
6. Select the file “/usr/share/tomcat6/bin/tomcat-juli.jar”
7. Close the dialog.
8. Start tomcat 6 from Eclipse.

Tuesday, July 20, 2010

Excerpts from The Kite Runner

This is a book which I have read over and over... and still I fall in love with it every time I read it. Here are some excerpts from the same .... 

They danced high above the trees on the west end of the park, over the windmills, floating side by side like a pair of eyes looking down on San Francisco, the city I now call home. And suddenly Hassan's voice whispered in my head: For you, a thousand times over. Hassan the harelipped kite runner.I sat on a park bench near a willow tree. I thought about something Rahim Khan said just before he hung up, almost as an afterthought. There is a way to be good again. I looked up at those twin kites. I thought about Hassan. Thought about Baba. Ali. Kabul. I thought of the life I had lived until the winter of 1975 came along and changed everything. And made me what I am today.


That same night, I wrote my first short story. It took me thirty minutes. It was a dark little tale about a man who found a magic cup and learned that if he wept into the cup, his tears turned into pearls. But even though he had always been poor, he was a happy man and rarely shed a tear. So he found ways to make himself sad so that his tears could make him rich. As the pearls piled up, so did his greed grow. The story ended with the man sitting on a mountain of pearls, knife in hand, weeping helplessly into the cup with his beloved wife's slain body in his arms.


She said, 'I'm so afraid.' And I said, 'why?,' and she said, 'Because I'm so profoundly happy, Dr. Rasul. Happiness like this is frightening.' I asked her why and she said, 'They only let you be this happy if they're preparing to take something from you


I want to tear myself from this place, from this reality, rise up like a cloud and float away, melt into this humid summer night and dissolve somewhere far, over the hills. But I am here, my legs blocks of concrete, my lungs empty of air, my throat burning. There will be no floating away.

It was only a smile, nothing more. It didn't make everything all right. It didn't make ANYTHING all right. Only a smile. A tiny thing. A leaf in the woods, shaking in the wake of a startled bird's flight. But I'll take it. With open arms. Because when spring comes, it melts the snow one flake at a time, and maybe I just witnessed the first flake melting. - Amir

Quiet is peace. Tranquility. Quiet is turning down the volume knob on life. Silence is pushing the off button. Shutting it down. All of it

There is only one sin. and that is theft... when you tell a lie, you steal someones right to the truth...Theft was the one unforgivable sin, the common denominator of all sins. When you kill a man, you steal a life. You steal his wife's right to a husband, rob his children of a father. When you tell a lie, you steal someone's right to the truth. When you cheat, you steal the right to fairness. There is no act more wretched than stealing.

Children aren't coloring books. You don't get to fill them with your favorite colors.

some stories don't need telling


Hope you liked it :-)

Monday, July 12, 2010

Humor with computers!!!!

Sometimes while I work , I really get irritated especially if there is an issue which refuses to resolve fast.The other day I came across some good humor related with computers .I have mentioned them below so that you guys can aslo have a hearty laugh

1>Q: What is the difference between Windows 95 and Windows 98? A: 3 years

2>“As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.”
Maurice Wilkes discovers debugging, 1949.

3>
“Before software can be reusable it first has to be usable.”
Ralph Johnson

4>
“The evolution of languages: FORTRAN is a non-typed language. C is a weakly typed language. Ada is a strongly typed language. C++ is a strongly hyped language.”
Ron Sercely

5>
“If debugging is the process of removing bugs, then programming must be the process of putting them in.”
Edsger Dijkstra

6>
“I’ve finally learned what ‘upward compatible’ means. It means we get to keep all our old mistakes.”
(Dennie van Tassel)


7>
“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”
(C.A.R. Hoare)

8>
“Keyboard not found. Press <> to RESUME. “
Source unknown (appears in many common BIOSes as a real error message)

9>
“The trouble with programmers is that you can never tell what a programmer is doing until it’s too late.”
(Seymour Cray)

10>“A great lathe operator commands several times the wage of an average lathe operator, but a great writer of software code is worth 10,000 times the price of an average software writer.”
(Bill Gates)

Hope this brought across a smile :)!

Thursday, June 17, 2010

Rmoving Restrictions on package like sun.*, java.*

The java.*, javax.* and org.* packages documented in the Java Platform Standard Edition API Specification make up the official, supported, public interface. If a Java program directly calls only API in these packages, it will operate on all Java-compatible platforms, regardless of the underlying OS platform.
The sun.* packages are not part of the supported, public interface.
A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.


Due to the same a project give access restriction errors at the compile time ...
Access restriction: Class is not accessible due to restriction on required library";
may be shown while developing Java projects in Eclipse IDE.

Solution: follow the following steps to solve the same

1.(Your Project) Properties -> Java Compiler -> Errors/Warnings


This was all about eclipse when you deploy the same using Felix
you can either pass the VM argument as:

-Dorg.osgi.framework.bootdelegation=sun.*,com.sun.*

or you can add

Dorg.osgi.framework.bootdelegation=sun.*,com.sun.*

in the config.properties file in the conf folder of the Felix Framework





References:

1 http://java.sun.com/products/jdk/faq/faq-sun-packages.html
2 http://lkamal.blogspot.com/2008/09/eclipse-access-restriction-on-library.html
3 http://blog.springsource.com/2009/01/19/exposing-the-boot-classpath-in-osgi/





Friday, June 4, 2010

eqinox to felix - an experience

The other day I had created a few OSGi bundles in Eclipse and deployed the same in the Equinox framework of Eclipse..

These same bundles when I deployed in Felix.. it gave an error stating it was not able to find the classes .. esp those which were exposing the services.Next I added the following bundles in the manifest of each of the bundles:

- javax.naming
- javax.naming.event
- javax.naming.spi


And VOILA !!! it worked .... :-)