Step by step instructions to install NodeJS on Windows

I just had NodeJS successfully installed on Windows XP using Cygwin and thought this might be of use to someone who wants to do the same.

Pre-requisites: Cygwin with Python & some additional packages (we’ll go over that in a bit)

  1. Double click Cygwin’s setup.exe and continue till you get to select packages window
  2. Select Python
  3. Select Make
  4. Select G++
  5. Select wget(not really required but, good to have for downloading archives & stuffs :) )
  6. Click next and complete the installation
  7. From cygwin type the following commands. Note: At the time of this writing v0.2.0 is the current NodeJS version.

    			wget http://nodejs.org/dist/node-v0.2.0.tar.gz
    			tar xvf node-v0.2.0.tar.gz
    			cd node-v0.2.0/
    			./configure
    			make
    			make install
    		
  8. If all goes well, then you should see NodeJS’s version when you type the following command.

    		node --version
    		v0.2.0
    		

Now its time to crack some code to your heart’s desire :)

StackOverflow, some insights…

A while ago I wrote an article on “how to crash a JVM”, the purpose of that article is to identify the end limits of JVM, instead it stirred quite some controversy in other areas. If you are interested to know more on that article, you can read it here. This is a follow-up article to that one where I would like to touch on StackOverflow and why & when it occurs.

As you might know already, the following code snippet throws StackOverflowError.

	public class StackOverflowTest {
		public static void main(String[] args) {
			main(args);
		}
	}
  

If you read the javadoc of StackOverflowError, it says that error happens when application “recurses too deeply”. There are two key words to underline here… “recurse” and “deep”. The word recursion according to google (Did you mean: recursion :) ) & programmers lingo, some method calling itself. So, it’s very natural to think StackOverflowError happens only when we run into this inifinite recursion scenario. But, thats not entirely true. It could also happen when we have method call chain which is “too deep”.

So, in order to find out how deep is “too deep”, I wrote this code snippet. Obviously, it will vary between different JRE versions, OS etc and you can also increase the stack size limit by setting -XX VM param.

In order to prove the stack overflow in “non-recursion” scenario, here is a Java code that will create, compile & run Java code with nested method call chain of limit set to 7000.

So, if you think this little more deeper, someone like me would wonder.. Is it a limitation that a Java class/application cannot have more than certain number of methods? If yes, how does all the enterprise class software products written in millions of lines of Java code working? The answer to that question is… Yes, it is a limitation, but in only one thread. So, almost any enterprise/mid range Java project/product cannot be written in such a way that it would run in only one main thread and if it written that way, this is the limit you hit.

So, if we come back to our original problem and see if we can make it run. Here is how…

		public class StackOverflowLimitWithThreadTest {
		  private static int recursionLimit = 0;
		  public static void main(final String[] args) {
			new Thread(new Runnable(){
			  public void run() {
				System.out.println("recursionLimit++ = " + recursionLimit++);
				main(args);
			  }
			}).start();
		  }
		}
  

Signing greeting cards in Java

Buddy of mine recently had a baby for the first time. He and his wife are Java developers. So, I thought how about signing his congratulations card in a language we speak?

Here is the code snippet I came up with. In case if you have something that you like to share, feel free…

		public class Life {
		  public static void main(final String args[]) {
			boolean havingKids = args.length > 2;
			if (havingKids) {
			  System.out.println("Life is about to change forever...");
			  throw new LifeChangingException("Congratulations, " +
				"you are going to discover yourself.... Have fun along the way!!!");
			}
			main(args); //Sometimes you'll wish you are here
						// inspite of StackOverflow:)
		  }
		}

What you think?