Although most books on Java(except a few good ones) will beg to differ and say that "In Java, primitives are passed by value and objects by references"
But, this is not true. Or you can say that it is 50% true.
Because, even Objects when passed as parameters to a method are passed by value !!
Hard to Digest !!
But it is TRUE. This is not to say that changes are not reflected back when objects are passed to a method.
Actually what happens when you try and pass an object as a parameter is that the bit representation of the actual parameter(lets say the address of the actual object on the heap) is COPIED to the formal parameter. So at this time both references are pointing to the same object on the heap and thus any changes made to it are reflected back in the calling code.
A proficient C programmer is not akin to this concept as it works in C exactly the same way.
Try out the following program to understand how parameter passing works in Java.
class myClass
{
int val;
myClass(int x)
{
val = x;
}
void display()
{
System.out.println(" Value is "+val);
}
}
class test
{
static void modifyValue(myClass o)
{
o = new myClass(20);
o.display();
}
public static void main(String[] args)
{
myClass ob = new myClass(10);
ob.display();
modifyValue(ob);
ob.display();
}
}
The output is
Value is 10
Value is 20
Value is 10
Third line says that the value of object ob has not changed after passing it to a method and making changes there.
This happened because objects ob and o are different entities and changing o (the reference) bit pattern (the address) by creating a new object won't affect ob in any way.
The bottom line on pass-by-value : Java is actually pass-by-value for all variables running within a single VM(virtual machine).
Notes:
Exception to this rule is perhaps :
1. Parmeter passing in RMI (Remote Method Invocation)
Comments & Corrections are Welcome. :-)
The creative side of me unleashed here....love to write about technology that excites and inspires me...
Friday, August 15, 2008
Sunday, July 20, 2008
Drupal & Joomla to your Rescue !!
Have you ever felt that the process of making a web site tedious, time-consuming and lengthy process and spent more time than is actually needed ??
Or have you ever felt the need to build an interactive website really fast, may be for a semester project ??
If yes, then Content Management Systems (CMS) like Drupal & Joomla! are exactly what you need. This is not to say that only in these CMS would work only in these situations. They can be used by experts as well as novices to build rich-featured, reliable, easily administered websites by providing them an extremely flexible and highly configurable environment to operate in.
Let's see what is a CMS ?
CMS stands for Content Management System. It can be seen as a software package that can be used by individual or community of users to easily publish, manage and organize a wide variety of content on your website.
CMS eases the process of building websites by being flexible in nature and providing the developer with high degree of configuration and customization.
Also using CMS, one need not be proficient in scripting languages like PHP, however basic knowledge would help.

So before you start using any one of them, make sure that your web server is properly installed.
For windows, you need to perform the following steps:
For remote web server, an extra step is that you need to FTP these files to the server using any FTP client like FileZilla and then follow the installation instructions.
Drupal eases your installation task by providing you with a videocast on how to install and configure your CMS, that is really really useful for novices like me. :-)
Joomla! also provides you with detailed installation instructions that helps you with any issue that you might get into.
Having being used both of them, i can say that Drupal is much more extensive in terms of features and functionality that it provides to the developer. May be because it is in existence for a longer time than Joomla!. But, it also makes Drupal user-interface more overwhelming (not complicated though) and sometimes frustating for the newbie. But one should devote some more time in understanding the basics, its architecture and workflow.
This is not to say that Joomla! is not good. On the other hand, i would recommend students to begin with Joomla! and then slowly graduate to Drupal But still i found it pretty easy to set permissions in Drupal than in Joomla!. There are several tutorials on both of them and I'm not really an expert to compare the two. The bottom-line is that both are useful and extensible in their own right.
Using a CMS, you can easily make website for your school/college clubs or alumni portal providing features like discussion forums, creating polls and voting on them, giving each user a facility to create and manage their own blog using a blogging API, creating, editing and managing articles, stories, pages as well as commenting on other's posts, uploading files onto the server and much more. It provides a plethora of options to the administrator as well and helps him/her to have total control on the flow, thus making your website secure, reliable and safe.
With Drupal and Joomla! being open-source, they are backed by a huge community of users and developers who continuously keep on developing new innovative modules and themes which can be downloaded as such (free of cost, obviously) and used within your website. Thus, they make your website easily extensible and flexible in nature.
Thus anyone, who is interested in creating websites on-the-go can definitely give these frameworks a try and end up learning quite a lot.
There is so much more to share about these exciting systems, but I think I have already written a pretty long blog, so will continue sometime later...
Or have you ever felt the need to build an interactive website really fast, may be for a semester project ??
If yes, then Content Management Systems (CMS) like Drupal & Joomla! are exactly what you need. This is not to say that only in these CMS would work only in these situations. They can be used by experts as well as novices to build rich-featured, reliable, easily administered websites by providing them an extremely flexible and highly configurable environment to operate in.
Let's see what is a CMS ?
CMS stands for Content Management System. It can be seen as a software package that can be used by individual or community of users to easily publish, manage and organize a wide variety of content on your website.
CMS eases the process of building websites by being flexible in nature and providing the developer with high degree of configuration and customization.
Also using CMS, one need not be proficient in scripting languages like PHP, however basic knowledge would help.

So before you start using any one of them, make sure that your web server is properly installed.
For windows, you need to perform the following steps:
- Install the WAMP server on your local machine.
- Download Drupal or Joomla! dump from their respective sites and depending on whether you use localhost or remote web server, you need to unzip files from the dump to a correct location.
For remote web server, an extra step is that you need to FTP these files to the server using any FTP client like FileZilla and then follow the installation instructions.
Drupal eases your installation task by providing you with a videocast on how to install and configure your CMS, that is really really useful for novices like me. :-)
Joomla! also provides you with detailed installation instructions that helps you with any issue that you might get into.
Having being used both of them, i can say that Drupal is much more extensive in terms of features and functionality that it provides to the developer. May be because it is in existence for a longer time than Joomla!. But, it also makes Drupal user-interface more overwhelming (not complicated though) and sometimes frustating for the newbie. But one should devote some more time in understanding the basics, its architecture and workflow.
This is not to say that Joomla! is not good. On the other hand, i would recommend students to begin with Joomla! and then slowly graduate to Drupal But still i found it pretty easy to set permissions in Drupal than in Joomla!. There are several tutorials on both of them and I'm not really an expert to compare the two. The bottom-line is that both are useful and extensible in their own right.
Using a CMS, you can easily make website for your school/college clubs or alumni portal providing features like discussion forums, creating polls and voting on them, giving each user a facility to create and manage their own blog using a blogging API, creating, editing and managing articles, stories, pages as well as commenting on other's posts, uploading files onto the server and much more. It provides a plethora of options to the administrator as well and helps him/her to have total control on the flow, thus making your website secure, reliable and safe.
With Drupal and Joomla! being open-source, they are backed by a huge community of users and developers who continuously keep on developing new innovative modules and themes which can be downloaded as such (free of cost, obviously) and used within your website. Thus, they make your website easily extensible and flexible in nature.
Thus anyone, who is interested in creating websites on-the-go can definitely give these frameworks a try and end up learning quite a lot.
There is so much more to share about these exciting systems, but I think I have already written a pretty long blog, so will continue sometime later...
Saturday, July 12, 2008
GWT - Have you tried it ??
What's GWT ?
Google Web Toolkit is an open source Java development framework that can be used to build web applications using AJAX easily and you do not have to worry about issues like cross-browser compatibility.
GWT Major Features:
Also, during development you can run and debug your application in hosted mode by running it as Java Bytecode within JVM using GWT's Hosted Web Browser.
To get an overview of the its architecture, please see this
On a downside, there are few issues still unresolved:
So, what are you waiting for !!
If you haven't tried it yet, download it right now here and have fun making easy to use and interactive good looking web applications.
Google Web Toolkit is an open source Java development framework that can be used to build web applications using AJAX easily and you do not have to worry about issues like cross-browser compatibility.
GWT Major Features:
- Real-time debugging
- Cross-browser compatibility
- Reusable UI Components
- Simplified DOM API
- Completely Open Source
Also, during development you can run and debug your application in hosted mode by running it as Java Bytecode within JVM using GWT's Hosted Web Browser.
To get an overview of the its architecture, please see this
On a downside, there are few issues still unresolved:
- GWT 1.4 does not support JDK 1.5 version but GWT 1.5 Release Candidate do support it
- Also, GWT does not support several concepts in Java such as Reflection, Finalization, Assertions, Multithreading & Synchronization, mainly because JavaScript does not provide support for them.
So, what are you waiting for !!
If you haven't tried it yet, download it right now here and have fun making easy to use and interactive good looking web applications.
Sunday, July 6, 2008
Interesting SQL Query
Write a SQL query to compute the Nth Maximum Salary
Lets get started with an easy one.
Write a SQL query to compute the 2nd Maximum Salary
select Max(Salary)
from Employee
where Salary != (select Max(Salary) from Employee);
To see how it works, you need to understand how a nested query is executed:
First the innermost (nested) query is executed and its result is placed in a temporary table, then the outer query is executed which uses that result.
So if you have to find the 3rd Maximum Salary, you could extend the previous query by increasing one more level of nesting. And so on.
A more interesting and simpler way to find Nth maximum salary would be the following correlated subquery
select * from Employee E1 where
(N-1) = (select Count(Distinct(E2.Salary))
from Employee E2 where E2.Salary > E1.Salary );
Let us now see how this correlated query works:
For each tuple of table Employee, the inner query is executed once and
the result is now stored in some temporary form which is used by the
outer query.
Thus, this correlated query takes O(n*n) time (quadratic time) as compared to linear time {O(n+n) = O(n)} of nested queries but it is still better than nesting the query n number of times as that would result in cumbersome code. However, both would take equal time. :-)
The best way to understand the query is to dry run it on some sample data and some value for N
Labels:
SQL
Subscribe to:
Posts (Atom)