Print Friendly, PDF & Email

Hello, finally got time to test and create some projects with Java 9, specifically with Jigsaw that it’s gonna be the next Java’s innovation avalible for all public starting about september 2016.

Creating Java 9 Hello World‘s code

Actually there isn’t option to create a new Java 9 project as such not even on development versions of Netbeans, so we whould create a normal Java project, and disable conmpile on save feature until we have the basic structure.

The structure I’m using is as follows:

the class helloJavaWorld(Holamundodejava in spanish) could go at the root projet’s directory, but having in a specific package is a recommended practice.

The module info file

The module.info.java file is the most important at this kind of project, it allows us to administrate better our project interaction with other projects. For the case of our hello world project, we will not need no other modules but the base module, that luckily is imorted by default.

Below you can see the list of modules from wich you can choose that comes bundled in the JDK 9.

Our module file will have the following structure:

module MODULE_NAME{
    requires MODULE_USED;
    requires MODULE_USED;
}

In our case, using the structure the module file could remain something like this:

module holamundodejava {
    requires java.base; //imported by default
}

 

but as we mentioned previously, java.base module is imported by default so we are ommiting it.

module holamundodejava {
}

 

 

Our Holamundodejava file

the other file will be a very familiar and will be as follows:

package holamundodejava;

/**
* Class that greets the world
*
* @author Javatlacati
*/
public class Holamundodejava {

/**
* Application entry point.
*
* @param args the command line arguments
*/
    public static void main(final String... args) {
        System.out.println("Hola mundo");
    }

}

 

FAQ

¿If I import a proyect as is do I could compile it with Java 9?

Unfortunately no, Jigsaw use requires specifically use the new module feature. Most of the code can be reused but sometimes a deep analisis may be requires to know what is or not exported for use in outer modules.

¿Why it doesn’t work on my Netbeans?

I use a development versionfor both Java 9 and Netbeans 9, since both releases dates are estimated about september 2016 they should be downloaded from special repositories and you may not find them that easily.

¿Why it doen’t work with my Java 9 compiler?

The version I’m using is for early access to Jigsaw Feature. You may download it directly from Oracle site once acceting the license.

Radio

Do NOT follow this link or you will be banned from the site!