Thursday 7 January 2021

Java9: Eclipse Hello World Example

Step 1: Add JDK9 path to ‘Eclipse Installed JREs’.

Open Eclipse. Eclipse -> Preferences…

 


 

Search for ‘Installed JREs’ and Add jdk9 JRE path here by clicking on Add button.




Select JRE Type as ‘Standard VM’. Click on Next button.

 

 


Browse to jdk9 jre home.




Click on Finish button.

 

Step 2: Create new Java Project ‘stringutil’ with jdk9.

File -> New -> Java Project.

 

 


Under JRE section, select the option ‘Use a project specific jre:’ and point this to jdk9.

 

Give the project name as ‘stringutil’.




Click on Next button.

 

 


Use default options and click on Finish button.

 

Project structure looks like below.




Create package ‘com.sample.app.util’.

 

Define StringUtil class in ‘com.sample.app.util’ package.

 

StringUtil.java

package com.sample.app.util;

public class StringUtil {
	
	public String welcomeUser() {
		return "Have a Good Day!!!";
	}

}

 

Update module-info.java file like below.

 

module-info.java

module stringutil {
	
	exports com.sample.app.util;
	
}

 

Step 3: Create new Java project ‘stringutilclient’.

 

 



Add stringutil module dependency to this project.

 

Right click on ‘stringutilclient’ -> properties.

 

 


Select Projects tab, select Modulepath and click on Add… button.


Select ‘stringutil’ project and click on OK button. Apply the changes and close the window.

 

Update module-info.java file like below.

 

module.info.java

module stringutilclient {
	
	requires stringutil;
	
}

 

Create package com.sample.app and define App.java like below.

 

App.java

package com.sample.app;

import com.sample.app.util.StringUtil;

public class App {

	public static void main(String args[]) {
		StringUtil stringUtil = new StringUtil();

		String msg = stringUtil.welcomeUser();

		System.out.println("msg : " + msg);
	}

}

 

Run App.java, you will see below message in console.

 

msg : Have a Good Day!!!

 

You can download these applications from below github link.

https://github.com/harikrishna553/java9-eclipse

 


Previous                                                    Next                                                    Home

No comments:

Post a Comment