How to program in Grimport?

Ask us for help with programming in Grimport TRANSLATE THIS PAGE WITHOUT TOUCHING THE CODES

Go Further

 

Java & Groovy inheritance


Grimport is a computer language that inherits from Java and Groovy. This means that Grimport inherits all the classes and methods of Java and Groovy and can call their classes in a script.

Java inheritance

For example, to create a thread, it is possible to create a subclass to access the Java Thread class:

class MyThread extends Thread 
{ 
	// code 
}

Here is an example with the Java method getAbsolutePath() which is part of the File class. This function returns the absolute path of the given file object (here the folder of the current application).

file = new File("")  
path=file.getAbsolutePath() 
console(path) // -> C:\Users\My_User\Grimport Crawler

Here is another example that uses the encode method of the Java URLEncoder class:

urlEncodage=URLEncoder.encode("hello my friend, how are you ?",  "UTF-8") 
console(urlEncodage) // -> hello+my+friend%2C+how+are+you+%3F

 

Groovy inheritance

Groovy's sort() function can be used in Java like all other functions. It returns a sorted copy of the original list:

list = [13,  12, 15, 14] 
list.sort() 
console(list) // -> [12, 13, 14, 15]

Here is another example where we import the withPool method from the GParsPool package. We then use Groovy's eachParallel() method. It creates a Parallel Array out of the supplied collection.

import  groovyx.gpars.* //import of a library for parallelization in groovy 

list = [ 1, 2, 3, 4, 5 ] GParsPool.withPool { result = list.eachParallel {param-> console(param) } } // -> 1 // -> 2 // -> 4 // -> 5 // -> 3

 

 

 


Next ❯ ❮ Previous