Monthly Archives: August 2012

Test your SQL

SQL Fiddle is the place to test your queries and database design. You can simply share the links with other team members to let them know what you are thinking. It provided a number of database platforms like Oracle, Mysql, MS Sql, Postgres etc.

What is Type Erasure?

Since Java 5, Java has come up with the concept of Generics. Idea of generics came from the fact that developers at times faced issue with assignment of data types to Lists and other structure. In case a wrong type was assigned or was tried to fetched, error could be caught at run time only

Example

ArrayList arr=new ArrayList();
arr.add("kamal");
Integer i=arr.getIndex(0); //run time error

So Java gave us an option

ArrayList arr=new ArrayList();
arr.add("1");
Integer i=arr.getIndex(0); //compile time error

But we should note that Generics is a compile time concept. When Java convert the code to bytecode for JVM, it removes all generics related info. So finally

ArrayList arr=new ArrayList();

will be converted to

ArrayList arr=new ArrayList();

This concept is known as Type Erasure. This was necessary for Java in order to give backward compatibility, otherwise the code written earlier would not have been supported by newer JVMs.

Accessing localhost from virtual machine or Android Emulator

Two problems- one solution i.e. 10.0.2.2

Sometime back, I faced an issue that I had installed a virtual machine on mu linux machine. I had a server/ website running which I wanted to access from virtual machine. http://localhost/site simply refused to work. A little googling helped with an answer to use http://10.0.2.2/site

Again faced similar issue. Was trying to access local website from within android emulator. Again localhost refused to work. And guess who was the rescuer? yep 10.0.2.2 again 🙂