Grails Cookbook - A collection of tutorials and examples

Iterate Through String Array in Java

A String Array is a data structure that holds several String values. The number of String elements is fixed and can't be changed throughout the lifetime of the array object. One common thing that we wish to do with String Array is to go through all the data it contains and process individually. Below contains examples on how to iterate through String Array in Java.

String Array Length in Java

String Array is a commonly used data structure when programming in Java. Although we can generally use List for greater flexibility, but sometimes using String Array is more suitable for a given scenario. Arrays in general have the property of having fixed number of elements and the size can't be changed throughout the lifetime of the data structure. When given a String Array as parameter to our method, it is common that we wish to know the length of it. Below are some examples on how to get the length of a String Array in Java.

Byte Array to String in Java

There are programming scenarios where we have a data in byte array that represents a String. This could be a case when we use a third party library to load data somewhere and the result is a byte array. In such cases, we may want to convert back the byte array to a String. Below are some examples on how to convert a byte array to String in Java.

Java String Array Declaration

An array is a basic and essential data structure in Java. It holds a fix number of values that can be easily manipulated. It is common to use an array of immutable objects in Java, such as a String. But before we can use a String Array, we must first be able to declare it. Below are some examples on how to declare a String Array in Java.

Grails 3 Vue.js AJAX Table Examples

With all the popular JavaScript framework, I believe that Vue.js stands out as a powerful yet easy to learn framework. Other popular JavaScript framework have high learning curve. It takes weeks to understand and write simple stuff. Vue.js is a breath of fresh air because it provides excellent features yet it can be learned within minutes. In fact, I have written the example in this tutorial in less than 1 hour and having no prior Vue.js background. Here is an example on how to write in Grails 3 and Vue.js an AJAX table that displays records of a database table in paginated form.

Grails 3 Vue.js Hello World Examples

The release of Grails 3 coincide with the growing popularity of more modern Javascript frameworks. Gone are the days where we mostly write code in gsp and jQuery. Frameworks like AngularJS, React, Ember and others are gaining popularity. For beginners, I highly recommend Vue.js because it is very easy to learn like Grails. A developer with some experience will be able to grasps how to use it in minutes. But as always, the hard part is in getting started. How can our single page application interact with our Grails 3 back end? Below are some basic examples for beginners. Here are some Grails 3 Vue.js Hello World Examples.

Grails Select Enum Values

It is more convenient that we use Enums in our domain classes rather than String, when we are really sure that Enum is the best representation of a property. Maintaining Strings and constants is just a pain. But it is common problem on how to create a form that accepts Enum values. Below is an example on how to use Select Tag inGrails to choose from Enum values.

Convert String to Enum in Groovy

When programming in Grails, sometimes we get a String value that we wish to transform to an Enum. For example, when usually get String value from data passed from form or url parameters. Since Groovy 1.7.6, it is now easy to transform a String into a Enum value. Below are some examples:

Groovy SQL Delete Operation Examples

When a record in a database table is not needed anymore then we may want to delete it. There are two ways of deleting a record. One is called logical delete where the record is still in the table but a marker was set in one of the column to tell the application that uses the table to ignore it. The second one is called physical delete where we really delete the record in the databases. SQL provides the delete statement for physical delete. Below are examples on how to perform delete operation using Groovy SQL.

Groovy SQL Update Operation Examples

There are instances when data on a record should be modified. SQL provides update statements for this purpose. Below are examples on how to perform update operation using Groovy SQL.