Showing posts with label groovy. Show all posts
Showing posts with label groovy. Show all posts

Saturday, April 4, 2015

Javaland 2015 - Day 2

Better late then never here it is, my summary of our second day at Javaland 2015 :-)!

After a first day with a lot of interesting talks and fantastic rides with the Black Mamba we started day 2 at Javaland. This day came up with a lot of JavaFX talks. Perfect, because the last Project at work made heavy use of JavaFX. So i decided to take a look how other programmers work with JavaFX.

Hendrik Ebbers from Canoo and Alexander Casall (Saxonia AG) started after the Keynote with "Enterprise Applications with JavaFX". They gave an overview how to build JavaFX Applications that communicate with JEE Backend Systems and gave some best practice tips how to bind data models to their corresponding view (Model-View-View-Model Pattern), and how to synchronize views between two instances of one JavaFX Application. Theyalso mentioned some interessting JavaFX Libraries that addresses the named Topics:


Well, as you can see, Java Developers are not very creativ when inventing a Name for a library ;-)

IoT

Another big Topic at day two was IoT - Internet of things. Maybe you did not know this term you probably get in touch with it. Since not even Computers and Smartphones but also TVs, Refrigerators, Watches and lot more devices can connect to the Internet we talk about the IoT. To get an easy introduction into that Topic i decided to watch "IoT Magic Show" with Stephen Chin (yeah, the men with the Motorcycle :-) ). Stephen and a colleague explained IoT with the help of three Magic tricks. The most impressing one was the first one. Three People from the audience had to choose one gamingcard and Stephens colleague had to guess what gaming they had choosen. As you might guess he guessed right every Card!
The trick mainly based on an really tiny RFID-Chip inside every Card. With a Little RFID detector hidden in his Hand, he hovered over the Card with the face down. The RFID-Chip transmitted the type of the Card to the detector. Over a Network the result was transmitted to a RasberryPI and finally send to Google Glasses.
That showed how Network capable devices can communicate with each other.

2048

Need a break after a lot of reading? How about playing 2048 to relax? If you don't know 2048 the game you may want to checkout http://gabrielecirulli.github.io/2048/. It is fun and easy to learn!

Bruno Borges and a colleague showed their implementation of 2048 with JavaFX in the next talk. They covered how they did the databinding, the design and the animations with JavaFX to achieve the typical 2048 Feeling. Finally they introduced the port to Android Devices, done with JavaFXPort (http://www.javafxports.org/page/home). You can find the app in the Play-Store https://play.google.com/store/apps/details?id=org.jpereda.game2048

Groovy Traits

A less visited talk but not less interessting was "Traits and their usage inside groovy" by Jochen Theodorou. Jochen talked about the reason why they invented and implemented traits and why it is better to use traits then mixins.
With a lot of examples he showed use cases and best practices.

Projector Pattern

Finally we visited "Efficency and Flexibility of the projector pattern" by Dierk König. Maybe you don't know the pattern it is very likely that you already used this pattern when you programmed some GUI Application. In short words the projector pattern is when you work with an API that describes what the GUI should Display, but not how things are displayed. For this reason you use a Projector and only the projector knows how to Display GUI Elements.

Saturday, January 3, 2015

Quick Dependency resolving with Grape

Most of the time i use Groovy with the GroovyShell or as a Groovy-Shell Script (remember my Blog-Post in October). Doing it that way you can achieve a lot with some lines of Groovy Script and the Groovy Standard Library Classes. But what if you need some classes from some third party libraries?
If you run your Groovy Script inside the GroovyShell you can simply modify the file groovy-starter.conf (resides in the conf folder of your GroovyShell installation). Add the classpath to the required library and you are done.
But this can get quite difficult if the library has further dependencies and you did not have these ones. Or you have these dependencies but only as maven dependencies, living in a gigantic maven repo on your local harddrive.
To get around this issue Groovy provides a Maven like mechanism called Grape. Grape does all the dependency resolving for you by doing lookups in well known Maven Repositories. So for example, if you like to have the FTPClient class from org.apache.commons.net in your Groovy Script, add the following Grape Statement:

@Grapes(
    @Grab(group='commons-net', module='commons-net', version='3.2')
)


Then add the import statement for the FTPClient class and you are done! The full script with its overwhelming functionality ;-):

@Grapes(
    @Grab(group='commons-net', module='commons-net', version='3.2')
)
import org.apache.commons.net.ftp.*;

FTPClient ftpClient = new FTPClient();


 If the required dependency does not exist in the repositories known by Grape you can tell Grape where to go to find it. Simply add this statement:

@GrabResolver(name='myrepo', root='http://mymavenrepo.org/')

Grape is "supported" by mvnrepository.com. If you look for a dependency mvnrepository.com tells you the grape-code for instant usage!

Friday, October 31, 2014

Execute Groovy as a Shell-Script

A colleague of me told me today that it is possible to run Scala Scripts directly in a shell. Because i am more familiar with Groovy i started some research if it is possible to do this with Groovy as well. To do it short: Yes we can :-) Take a look: http://groovy.codehaus.org/Running