Saturday, January 26, 2013

SQL :: Information Schema Views

You can select the structure of your schema (tables, columns, ...etc.) in most DBs

for example SQL using what is called Information Schema Views

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
and oracle uses:
SELECT owner, table_name
  FROM dba_tables
or
SELECT owner, table_name
  FROM all_tables
or
SELECT table_name
  FROM user_tables
good luck :)

Java Code Convention

My code is returning the right results wohoooo :D, finally i will deliver it to my technical manager and go to sleep, WAAAAAAAAAAAAAAAAAAIT don't go until you do the following!!

1- Make sure that no one will ever realize why you named the variables.
2- Make sure that no one could know how you named your methods, it is your copy rights! daa!
3- Make sure not to add any inline comments in your code, so no one can find out what you mean!! haha!
4- Put all of your code in one class and all method function in one method, it will looks that you put a great effort in it. :D
5- Be different add a caps to package names and don't ever start with a caps letter in class.
6- try to put all of your code in one line.

Off course i was kidding please developers please please please apply the following convention:
http://www.oracle.com/technetwork/java/codeconventions-150003.pdf

Have a nice day :)

Java :: ArrayList VS Vector



ArrayList or Vector?

This is one of the famous questions that a Java beginner has in his mind. This is also a famous question asked in interviews. Following are the differences between ArrayList and Vector.

1. Vectors and Hashtable classes are available from the initial JDK 1.0. But, ArrayList and HashMap are added as a part of new Collections API since JDK 1.2.

2. Vectors and Hashtable are synchronized where as ArrayList and HashMap are unsynchronized.

When to use Vector? When to use ArrayList? 

1. ArrayList is faster when compared to Vector since ArrayList is unsynchronized. So, if the List will be modified by only one thread, use ArrayList. If the list is a local variable, you can always use ArrayList.
2. If the List will be accessed by multiple threads, always use Vector, otherwise you should take care of synchronization manually.

To visualize the problem with synchronization, try the following code.

There is a Producer class that adds 5000 elements to the List (ArrayList/Vector). Another class, Consumer class removes 5000 elements from the same list. There are around 10 producer threads and 10 consumer threads.

Reference:
http://skeletoncoder.blogspot.com/2006/09/java-tutorials-arraylist-or-vector.html