Thursday, January 28, 2010

Groovy-Strings-Heredocs Step 16

There are interesting things you can do with Strings in Groovy.

def s1='My name is "Joe"'
def s2="My name is 'Joe'"

Quotes can be used to hold a String. This can save you time from having to escape the string if the string contains single or double quotes.

String s= """This is a multi-line String "You don't have to escape it" """

A Heredoc allows you to store multiline Strings in a single variable. Groovy uses triple quotes to define heredocs. (Three single or double quotes)

if you type a variable like this:

def htmlexample="""
<book id="111">
<title>Groovy Test</title>
</book>"""

println htmlexample

You will get this as a printout:

<book id="111">
<title>Groovy Test</title>
</book>

Read more...

Friday, January 22, 2010

Groovy Rules - Step 15

Here are some important Groovy Rules that you should know:

if(1) = true because any non-zero value is true
if(-1) = true
if (!null) = true because any non-null value is true
if("John") = true because any non-empty string is true
Map family="[dad:"John"]
if (family) = true since the map is populated
String [] sa = new String[1]
if(sa) = true since the array length is greater than 0

I think you get the picture. This is based on common sense. If the class isn't null, has items in the list, and isn't empty, it will return true.

Read more...

Saturday, January 16, 2010

Groovy Autoboxing Step 14

In Java, primitives were used for speed and objects were used for developers convenience. In Groovy, everything is an Object.

if you type:

def i=2
println i.class
==> java.lang.Integer

def d=2.2
println d.class
==>java.math.BigDecimal

You do not need to worry about declaring your variable in Groovy because Groovy will automatically know what class your variable is. Groovy will autobox everything on the fly. You can call methods on what looks like a primitive, when it is actually a class. Primitives no longer exist in Groovy.

The good news is that in Groovy, if you give a number a decimal, it will autobox to a BigDecimal instead of a floating point number. This will avoid the dreaded "floating-point arithmetic" problem in Java.

Read more...

Sunday, January 10, 2010

Seattle Seahawks Jones Soda

This is a Sponsored Post written by me on behalf of Jones Soda. All opinions are 100% mine.



Are you a football fan? One thing that goes good with football on Sunday is enjoying a nice glass of Seahawks soda. Jones Soda is famous for their limited edition soda's and now you can get a 4-pk Cream Soda, 4-pk Green Apple and 4-pk of Berry Lemonade Jones Soda which will go great watching football. I would choose the Berry Lemonade Jones Soda because I have always loved the taste of Lemonade. I would love to see the Cowboys Soda because that is my favorite team. I figure the Cowboy Soda would be grape flavor since that is also my favorite fruit. If you are looking for something different to bring to your Super Bowl party, you might want to bring some Jones Soda. They have all kinds of beverages, candy, clothing and limited edition items that you might be interested in. You can order the items directly from their website which makes it easier to get all of your Jones items. So what are you waiting for? If you are looking for a great tasting Soda that will go well with your football parties, you should checkout Jones Pure Cane Soda today and try one of the Seahawk sodas.
SocialSpark Disclosure Badge

Read more...

Groovy Dereferencing Null Pointer Exceptions Step 13

The most annoying and most common error in Java is the Null Pointer Exception.

If you type:

def a=null
println a.size()
You will get a Null Pointer Exception

If you type
println a?.size(),

it will print null and not throw you a null pointer exception. This makes it a lot easier to check for null pointer exceptions.

(Step 14 Coming Soon)

Read more...

Check Out the Dungeons and Dragons Soda

This is a Sponsored Post written by me on behalf of Jones Soda. All opinions are 100% mine.


Are you one of the Dungeons and Dragons fan? How would you like to checkout their unique Dungeons and Dragons Jones Soda? This new and unique Dungeons and Dragons soda has many different flavors such as Sneak Attack, Potion of Healing and more. These sodas sound pretty interesting to me. They have some that are sugar free, and some that are pure cane. They also have Dwarven Draught and Eldritch Blast. I would love to try the Dwarven Draught drink which I would imagine would taste like Vodka. I would figure that Dwarves would be heavy drinkers. The Potion of Healing drink I would expect to taste like medicine. The Sneak Attack drink probably would be a very strong tasting drink that would give me a huge boost of energy. If you are looking for a cool gift to give to someone, you might want to get some of these Dungeons and Dragons drinks. This would be the perfect gift for anybody who enjoys playing Dungeons and Dragons or someone who is into fantasy. If you are looking to try a different kind of drink, or are looking for the perfect gift, you should checkout one of these drinks today. So what are you waiting for?
SocialSpark Disclosure Badge

Read more...

Operator Overloading in Groovy Step 12

Another shortcut in Groovy isOperator Overloading.
You can type something like this:
def d = new Date()
println d.next()
(1..3).each{println d++}

This code will print:
Mon Jan 11 12:06:11 PST 2010
Sun Jan 10 12:06:11 PST 2010
Mon Jan 11 12:06:11 PST 2010
Tue Jan 12 12:06:11 PST 2010

assuming that today's date is January 10th at 12:06 PST in 2010.

This code will instatiate a new date and print the next date.
Then it will print three more dates starting from today's date.

The d++ will call the next method.

Here are other operator overloading:


OperatorMethod
a==b or a!=ba.equals(b)
a + ba.plus(b)
a-ba.minus(b)
a*ba.multiply(b)
a/ba.div(b)
a%ba.mod(b)
a++ or ++aa.next()
a-- or --aa.previous()
a & ba.and(b)
a | ba.or(b)
a[b]a.getAt(b)
a[b]=ca.putAt(b,c)
a<<ba.leftShift(b)
a>>baa.rightShift(b)
a<b or a>b or a<=b or a>=ba.compareTo(b)

For example:

def b=new Date()
def v = new Date()
println "b"+b
println "v"+d
if(b.equals(v))
println "true"
else
println "false"

Read more...

Thursday, January 7, 2010

LG Chocolate Touch Phone

This is a Sponsored Post written by me on behalf of LG Chocolate Touch. All opinions are 100% mine.


How would you like to have a phone that allows you to make calls, send texts, use the Internet, use social media, take pictures and videos and also has a music player with Dolby Mobile technology for crystal-clear sound quality? The Dolby Mobile technology for crystal-clear sound quality will greatly improve my ability to communicate with my friends and family members. This phone also has sweet visual effects and features which include rhythmical beat that vibrates the handset to the beat of the music. Don't worry because now you can have a phone that includes all this technology by purchasing the LG Chocolate Touch phone. This phone also has a 3.2MP Camera/Recorder with excellent quality. I think you would find life much easier by having all of these technologies contained in one phone right? I won’t have to wait until I get on my home computer to get on Facebook, and I will still have excellent crystal clear sound. I am sure if I had this phone, I wouldn’t need my home phone and the internet on my desktop computer anymore either. How convenient is that! It also has a one touch social network message key for easy use of Mobile Blogging such as Facebook. It also has mobile media such as pictures, videos and more. If you are looking for a great phone, you should checkout the LG Chocolate Touch. So what are you waiting for?
SocialSpark Disclosure Badge

Read more...

Create an Executable File Using Java

If you are looking to make your Java application an executable file, you might want to use the Fat.jar plugin. You can download it from this website: http://sourceforge.net/projects/fjep

I downloaded the net.sf.fjep.fatjar_0.0.31.zip from their website.

Unzip the zip file using winzip or another tool.

Copy the net.sf.fjep.fatjar_0.0.31.jar from the zip folder and paste it in your eclipse/plugin directory.

Restart eclipse.

Select on the Java project that you want to make executable with the right mouse button and then select Build Fat Jar.

In the popup menu, select the class that contains the main and press finish.

It will tell you which directory it placed the newly created jar file.

Open a command prompt and traverse to the directory where your newly created jar file is located.

Type (myjar is the name of your jar file you created): java -jar myjar.jar.

If you get the UnsupportedClassVersionError, you might have compiled your code with a new version of Java. In eclipse, you can change the compliance level to make sure your code is compliant for older versions of Java. You can do this by selecting the window menu in eclipse, select preferences, Java and then select compiler.

Read more...

Lovely Hilton Bed and Breakfast Package

This is a Sponsored Post written by me on behalf of Hiltons of Branson. All opinions are 100% mine.


Do you have any plans during Valentine's Day? Are you going to bring your spouse or your girlfriend on a romantic dinner? If you are planning on going on a Valentines Day vacation, why not consider going to Branson, Missouri? Have you ever been there? Branson Missouri is a great place to visit because they have so many great attractions. They have great Amusement Parks such as White Water, Celebration City and Silver Dollar City. If you are looking for a place to stay, you don't need to worry because the Hilton Promenade at Branson Landing and the Hilton Branson Convention Center Hotel are offering an exclusive Romance Package. This package includes:
* Early check-in & pre-registration upon request
* In-room sparkling wine (where permitted by law) or cider upon arrival
* Access to hotel health club, pool and whirlpool spa (where available)
* Full American breakfast for two in their room (where available) or in the hotel's designated restaurant. At airport locations, guests can exchange their breakfast for a lunch or dinner discount
* On stays beyond one night, buy one entrée and get a second one of equal or lesser value at no additional cost. (Choose from either lunch or dinner in designated restaurant)
*Late check-out available upon request
You can also take pleasure in the lovely Hilton Bed and Breakfast Package and enjoy the comfort of the Hiltons of Branson plus a personalized Hilton Breakfast for two. They also offer guests access to shops, boutiques, restaurants, a river walk and other attractions. So what are you waiting for? You should take advantage of the Hilton Promenade at Branson Landing and the Hilton Branson Convention Center Hotel exclusive packages today.
SocialSpark Disclosure Badge

Read more...

Monday, January 4, 2010

Personalized Apple & BlackBerry Cases

This is a Sponsored Post written by me on behalf of Pexagon Technology. All opinions are 100% mine.


Iphone-plastic-az
Are you looking for some cool Apple and BlackBerry personal cases? You can now get some personalized Apple & BlackBerry cases which will greatly improve your phone’s look. It will also give you some added protection in case you drop it. You can get these $5.00 personalized cases in many different models and styles. The personalization is free as well. You will also get free shipping. You can get all of this for only five bucks which is a great deal. The Apple cases come in resilient soft silicone rubber and plastic. The BlackBerry cases will come in the silicone design for most of the popular models. There is no setup charges and nor order minimums. You can get the case, engrave a logo, engrave your name and have it shipped for only $5. You might want to engrave your school logo in case you lose it, or maybe give these out to your employees with your companies color. There are so many things you can do with this great deal. If you purchased this in the store, you might end up paying $20 without the personalization. So what are you waiting for? If you are looking for an Apple or BlackBerry personal case, you should checkout Pexagon today.
SocialSpark Disclosure Badge

Read more...