Sunday 9 October 2011

Divide by Zero in case of Java

One of the good interview questions I found was related to divide by zero.
Lets take the case:

What will be the output of this code snippet?

public class NaN {

public static void main(String[] args) {
double d = 2.0 / 0.0;
System.out.println(d);
}
}

What's the answer: The code will not compile or will it throw a DivideByZero error? Both are wrong. The code compiles fine and the output is,
Infinity

Let's check another code snippet,

public class NaN {

public static void main(String[] args) {
double d = 0.0 / 0.0;
System.out.println(d);
}
}

The output in this case is,
NaN

Saturday 8 October 2011

Hello World in Ruby using Netbeans

After getting a decent knowledge of what Ruby is and the useful resources that are available, lets get into action by creating our first hello world program.

Ruby and Ruby on Rails development becomes amazingly easy using Netbeans IDE where you can perform almost all the tasks in one single IDE. Download and install the Netbeans-Ruby version. You should be having JDK installed in your box, thats pretty much the pre-requisite for Netbeans to install.

OR you can simply download the complete version of netbeans and install ruby plugins.

Download the ruby from here. Extract it to some location, Say C:\\ruby
Now create new project.
Launch Netbeans go to File --> New Project. A new project wizard should come up. Select Ruby Application i.e. C:ruby\bin., click Next and click Finish. Thats it!!!!
You dont even have to type a Hello World. The new project template does it for you! So sweet isnt it? Now, click on the big green Run button and the console should print out Hello World without a hitch.

Now just run the program :)

installing RadRails on Eclipse

I could not find a proper answer when i wanted to install RadRails on eclipse . This is how it is done , .... in the Eclipse menu go to
Help-->Software Updates --> Find and Install....
then in the pop - up window which appears ,..
Search for new features to install
and then click next and then u will have to add 2 new remote sites, .. the details for the sites are the ones which were very difficult to obtain , they are
site 1 :
Name :RadRails
URL : http://radrails.sourceforge.net/update
site 2 :
Name :RDT
URL : http://updatesite.rubypeople.org/release
then click on finish , u are almost done with the installation , u have to just follow the instructions from here on to finish the installation .
This entry was posted on Friday, May 16, 2008 at 8:37 PM and is filed under , , . You can follow any responses to this entry through the comments feed .