Loading...

Monday, May 25, 2015

Sieve of Eratosthenes Algorithm to generate Prime numbers upto 100 in Java

There are many occasions when you need to generate all prime numbers upto a specified integer and one algorithm which is most often used to generate prime numbers is Sieve of Eratosthenes. Its an ancient greek algorithm to find all prime numbers upto a given number and named after the famous greek mathematician Eratosthenes. He was the first man to calculate the circumference of the earth and also known for working on calendars with leap years. A prime number is a whole number which is either divisible by 1 or itself e.g. 2, 3 and 5. You can see they are not divisible to any positive whole integer. In other words, prime number doesn't have a factor other than 1 or itself. You can use this algorithm to generate prime numbers from 1 to 100 or up-to any maximum value. In this tutorial, we will not only learn how Sieve of Eratosthenes algorithm works but also we will generate prime numbers using this algorithm and verify whether all number generated are actually prime or not.

Friday, May 22, 2015

Fixing Unsupported major.minor version 52.0 Error in Java

Unsupported major.minor version 52.0 comes when you are trying to run a class compiled using Java 1.8 compiler into a lower JRE version e.g. JRE 1.7 or JRE 1.6. Simplest way to fix this error is install the latest Java release i.e. Java 8 and run your program. If upgrading to Java 8 is not an option then make sure you use Java compiler's cross compilation feature and compile source code for lower Java version by using -target option of javac command. If you have multiple JRE installed make sure that the latest one comes first in PATH environment variable. You can get "java.lang.unsupportedclassversionerror unsupported major.minor version 52.0" while running a Java program explicitly using java command or running a Java Applet in browser or running a Java program from command line but compiled in Eclipse or any other build tool like Maven or ANT. Main reason of this error is that during compilation, you have used a higher version of JDK but during deployment, you have deployed into a lower version of JDK or JRE. Let's understand the cause and solution of Unsupported major.minor version 52.0 Error in little more detail.

TL:DR; upgrade to Java 8 or compile for lower JRE version using java -target 1.6 option.

Tuesday, May 19, 2015

How to differentiate between an Average and a Good Programmer?

When it comes to interview, goal is to find the most suitable developer for job to get done but its very difficult to judge someone's caliber, experience and expertise in short duration of Interview. There is always a process starting from phone interview, written tests to face-to-face interview, but its still difficult to hire the right programmer. Process can help you to filter candidates but eventually it will come down to your experience and gut feeling. As you take more and more interviews, you will know what to ask and what not and like many other interviewers in the world, you will develop some of your own tips. Similarly, I have developed couple of tips from my experience which has helped me to differentiate an average programmer with a good programmer in past. Today I would like to share one of such tips with you guys, to see if you agree with my observation and hopefully I will get couple of more tips to find right programmers. One of my most used tip is finding gaps in requirement. I have found and learnt it over time that good developers has knack of breaking requirements and finding gaps, which is very important to produce quality software and products. Though this skill comes with experience, a good developer even with less experience has this ability. In this article, I will share my hypothetical interview with two programmers and see what they produced.