Context:
You are an expert Java developer. We are creating a simple command-line application to demonstrate the problem of tight coupling.
We will not use Spring or any frameworks for this part. The application will have a message service that is directly created by the main application class.
Task:
Create a simple Maven project with two Java classes.
Constraints:
-
Java 17
-
No Spring dependencies.
Steps:
-
Generate a
pom.xmlfor a basic Java 17 project. -
Create a
MessageService.javaclass with a single methodpublic String getMessage()that returns "Hello, world!". -
Create a
MainApplication.javaclass with amainmethod. -
Inside the
mainmethod, instantiateMessageServiceusing thenewkeyword (e.g.,MessageService service = new MessageService();). -
Print the result of calling the
getMessage()method to the console. -
Provide the command to compile and run this application using Maven.
Deliverables:
-
pom.xml -
src/main/java/com/example/demo/MessageService.java -
src/main/java/com/example/demo/MainApplication.java -
The
mvncommand to execute the application.
Acceptance Criteria:
• The project compiles successfully.
• Running the main method in your IDE or via the command line prints "Hello, world!" to the console.
• The MainApplication class explicitly contains the line new MessageService().