Results for tag "java"

Fourth Coimbra JUG Meeting – Google Web Toolkit

posted by Roberto Cortez on

Last Thursday, 22 May 2014, the fourth meeting of Coimbra JUG was held on the Department of Informatics Engineering of the University of Coimbra, in Portugal. The attendance was very good, we had around 30 people to listen Paulo Martins talk about the Web Framework – Google Web Toolkit. A very special thanks to Paulo for taking the challenge and steer the session.

Coimbra JUG Meeting 4 Audience

I did a quick introduction to the group to welcome the newcomers and Paulo dived right in the session about Google Web Toolkit. GWT is not exactly a new technology, but I think that the topic draws some interest since I know a lot of people using it in their projects, and looking into RebellabsJava Tools and Technologies Landscape for 2014, GWT appears at 4th place for the Web Frameworks in use with a 10% share. Only a few people in the audience used GWT before, but there was a lot of interest to learn a little about it. Paulo presented some of the most relevant topics about GWT and show cased a few examples with live code demos.

Praxis Beer

For this meeting, Paulo had a surprise for the attendees: beer and chocolates. Thanks for Praxis Brewery for proving the beer! IntelliJ also sponsored our event, by offering a free license to raffle among the attendees. Congratulations to Bruno Martins for winning the license. Develop with pleasure!

Here are the materials for the session:

Enjoy!

Second Coimbra JUG Meeting – New Java EE 7 Features

posted by Roberto Cortez on

Last Thursday, 13 February 2014, the second meeting of Coimbra JUG was held on the Department of Informatics Engineering of the University of Coimbra, in Portugal. The event was almost cancelled due to our main speaker not being able to attend, but thanks to the support of @arungupta, @reza_rahman, @brunoborges and many others from the JUG Leaders mailing list, I was able to pull out a presentation about the new features of Java EE 7. Thank you everyone!

About the event, since this was only our second meeting, we took a bit of time to get to know each other and talk about our expectations of the group itself. I had a surprise to “motivate” our fellow JUG members to participate: beer and chocolates. We had good feedback and for reference, the following topics where among the preferred to the next sessions:

  • Garbage Collection
  • Web Frameworks
  • Testing Strategies / Frameworks
  • Mixing JVM languages in the same project
  • Databases

For the people that attended, please let me know if I forgot about something.

Coimbra JUG Meeting 2

Next came the talk about Java EE 7. Not that many people have used Java EE before, so a lot of the terminology was new to them, but I tried my best to present the topic in a way that could be understood for the ones that were only starting with the technology and also keep it interesting for the most experienced people. Generally, I think people enjoyed it and I actually took more time with the presentation than I antecipated due to the interest and questions from the audience. Unfortunately, our camera couldn’t keep up and got it’s memory full, so we don’t have the complete presentation recorded. Need a higher memory card for the next event 🙂

Here are the materials:
Presentation (in Portuguese)
Code: Websockets Chat
Code: Java EE 7 Samples
Java EE 7 Samples Documentation
Youtube Channel (in Portuguese)

Enjoy!

Getting started with IntelliJ IDEA Live Templates

posted by Roberto Cortez on
tags: , ,

Do you find yourself writing the same code over and over again? Maybe you’re already familiar with IntelliJ Live Templates feature. If that’s the case don’t go away. I’m going to demonstrate how to use them, but also the most interesting part is how to create your own Live Templates that can help you on your everyday coding.

For those not familiar with Live Templates, this feature allows you to quickly insert code fragments in your source code files and have the ability to replace or auto-complete sections of the template based on the current code context. IntelliJ already has a lot of templates that you can use right away after installing the IDE. You can have a look into the templates by using the shortcut CTRL+J/CMD+J:

Live Templates Popup

You get a list of the Live Templates that can be applied in the current context. The context is related with the file type you are editing (Java, SQL, XML, HTML, etc.), and also with the section itself (inside a method, field declaration, in the comments, etc). Let’s try one of the Live Templates I use the most, iterate an array. Did you notice the abbreviation on the left side of the Live Template popup? You can use it instead of using the popup shortcut. Just type iter followed by TAB key (do it inside the main method):

Iteration Expansion

The Live Template gets expanded to the Java 5 for each loop and IntelliJ suggests you the args array from the main method in the iteration plus the element type being iterated. You can pick other arrays available in the context and the code will automatically adjust to your choice (look at the red square around the args, it can auto complete to other arrays using CTRL+SPACE). Pretty cool!

Other notable Live Templates that I find pretty useful:

AbbreviationGenerated Code
psvmpublic static void main(String[] args) {}
psfspublic static final String
psfpublic static final
soutSystem.out.println();
soutvSystem.out.println("var = " + $var);
StString
ifnif ($var == null) {}
innif ($var != null) {}

Try to explore others that suit your programming style. Remember, Live Templates change with the file type you are editing. If you type udp in a SQL file and press TAB the abbreviation gets expanded to update set = where ;.

The real power is IntelliJ ability to create and customise your own code fragments. Lacking ideas? How about List<String> strings = new ArrayList<String>();? You type that a lot right? Well, maybe not with the String type, but that’s just an example. We’re going to create a Live Template for it where you can pick the type of the elements in the List. Go to IntelliJ Settings CTRL+ALT+S/CMD+, and search for Live Templates. You should get the following screen:

Live Templates Settings

We can now add a new Live Template by pressing the + on the right upper corner of the screen. We now need to add an abbreviation, a description, the template text itself and pick the applicable contexts.

PropertyValue
Abbreviationls
DescriptionList
Template TextList<$TYPE$> $VAR$ = new ArrayList<$TYPE$>();
ApplicableJava: statement, declaration

Add Live Template

The $TYPE$ and $VAR$ are variables that you can replace on the Live Template generation using IntelliJ pre-defined functions. Go to Edit Variables screen and you should get a screen like this:

Edit variables Live Template

So expectedType() replaces the $TYPE$ variable with a class type with the default value of String and suggestVariableName() replace the $VAR$ variable with an auto suggestion for the variable name where the default value is list. Take a look into IntelliJ help and see which other predefined functions are available for you to use. You can even use Groovy code!

Now you can type ls in the editor and expand it with TAB. You will get:

List Live Template

You can auto-complete and replace String by another type. Notice how the rest of the template adjusts to your pick:

List Live Template Edit

Note: If you’re using Java 7 or higher you can get rid of the generic type declaration on the right hand side of the template. I’m still working in a couple of projects that use Java 6, so I need it this way.

Now you just have to think on the code you type all the time and convert it to a Live Template and save precious time typing it! How about a template to create the Log instance to perform logging? You’re also going to need template log methods like sout to output log.info(""), log.error("") and so on. Try them out!

Feel free to share your Live Templates 🙂

First Coimbra JUG meeting – The new Java 8 Features

posted by Roberto Cortez on

Last Thursday, 19 December 2013, the first ever meeting of Coimbra JUG was held on the Department of Informatics Engineering of the University of Coimbra, in Portugal. I couldn’t be more proud, more than 50 people attended the event.

After a quick intro to the JUG by myself, explaining the JUG objective and purposes, we had Samuel Santos from PT.JUG to share some of his experience running and managing the biggest JUG in Portugal.

The highlight of the meeting was the my talk about the new features in Java 8, especially lambdas. I think that most of the people enjoyed it, but maybe it was not that interesting for the folks that already use lambdas or equivalents on other languages. Also a lesson learned for me.

If you’re curious, here are the materials (in portuguese):
Presentation
Code
YouTube Channel

You can find more photos of the event on our Meetup page. We also have a few videos that I’m uploading right now. I’ll update the post when I’m done.

A special thanks to Jetbrains for giving away 2 free licenses of IntelliJ 13 to raffle among the participants. Congratulations to the lucky winners of Math.random(), Hugo Lopes and Luis Rosa.

Feel free to comment 🙂