thejavajar

Archive for May, 2009

Are You Learning Java? Why?

by RJ Salicco on May.28, 2009, under Commentary

The other day, I began thinking about how to learn to become a programmer/software developer. Then I began thinking about learning C, C++, Java, Groovy, Ruby, Scala, PHP, Coldfusion, Perl, Python JavaScript and so on. I started thinking about beginning programmers because my youngest brother has started learning C in school. He has started with the standard:

#include<stdio.h>
main()
{
    printf("Hello World");
}

I started programming in a similar fashion and then I would eventually begin to learn PHP then Coldfusion, Java, Groovy, Ruby, Python…I was wondering what sparked my interest to learn other languages. My biggest effort or concentration has been learning Java, that is what I do 9-5 and I even became a SCJP, why you ask? Good question. What if I was a COBOL programmer or RPG programmer, why would I start to learn Java? Here are some reasons I came up with:

* I am in school/fresh out of school and I want to learn Java because:

  • I took an intro to programming class and the professor/other students were talking about Java.
  • I have a few friends that are working for big companies that are learning Java.
  • I see a lot of Java jobs advertised on the job sites.
  • I have been working with Web scripting languages but I would like to see the Java approach.

* I am a COBOL, RPG or legacy programmer and I want to learn Java because:

  • My company is re-platforming legacy applications and moving to Java.
  • I see a lot of Java jobs advertised on the job sites.
  • Java developers at my company make more money.
  • I want to be able to put Java on my resume and become more marketable.

Maybe you have some other reasons to learn Java?

6 Comments : more...

Groovy Prime Numbers

by RJ Salicco on May.11, 2009, under Development

The other day I wanted to prove the power of Groovy to a few more core Java developers. I sat down and played with a little script that I think proves the power, or ease of use, of Groovy while having fun with number theory. My goal was to have a Collection that contains Prime Numbers calculated from a given range of numbers x to y, or in Groovy syntax x..y. I am taking a few things for granted with this script. For example, I know that 2 is the lowest Prime Number (it helps simplify the algorithm) and that 1 is not a Prime Number. So here’s the script:

def t = 1..100
def v = []

t.each { n ->
    (2..n).each { d ->
        if(n % d == 0 && n != d)
            v.add(n)
    }
}

println t - v - 1

We have our range of numbers t and we are capturing the non-Prime numbers and adding them to our Collection v. The final line of the script is doing a lot of groovy work for us that would take a few more lines of code with plain Java syntax. What is it doing for us? It is taking our range of numbers t and subtracting (removing) our non-Prime numbers collected in v. This line is also removing the number 1 because we know that 1 is not a Prime Number. Finally, it is printing the result like so:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Very cool stuff. Now, I know that many of us are rarely building a Collection of Prime Numbers and I know this script does not do things in a timely manner with a range like 1..10000 (it took a couple of minutes), but I am sure this feature of Collections in Groovy can be utilized in many ways in my development.

14 Comments :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!