Project design
- Java course
- Expert
- Lesson 42/46
- 6 min
Design the expert final skeleton.
Project: expert final
In this five-lesson project you will build a mini service framework that combines all expert-level layers. Each lesson adds one layer, and by the final lesson you will run them together. You will use annotations, design patterns, reactive, bytecode and native code concepts together.
First you will define the @Service annotation and the HelloService class. In later lessons you will add reactive publishing, performance measurement, service registry, native bridge and bytecode inspection.
The design pattern layer
The project uses the Registry pattern: a registration class that holds a name-to-instance mapping. Classes marked with @Service are added to this registry and looked up by name when needed. This is a simple model of dependency injection.
In the first lesson you only define the @Service annotation and the HelloService class. The registry pattern comes in later lessons.
Practice Define the @Service annotation and HelloService
Define an annotation with @interface Service {}. Define a class HelloService marked with @Service; its String greet() method returns "hello". In main create HelloService s = new HelloService(); and print System.out.println("service ready: " + s.greet());.
Starter code
// Define the service annotation
// Define the HelloService class: greet method returns hello
// Main: create a HelloService and print service readySample solution
@interface Service {}
@Service
class HelloService {
String greet() { return "hello"; }
}
public class Main {
public static void main(String[] args) {
HelloService s = new HelloService();
System.out.println("service ready: " + s.greet());
}
}Expected output
service ready: hello
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which concepts does this project combine?
- Only database
- Only GUI
- Annotation, pattern, reactive, bytecode, native Correct answer
- Only threads
Explanation: The project combines annotation, pattern, reactive, bytecode and native layers.
2 Complete the annotation declaration
@____ Service {}
@interface Service {}
Explanation: @interface Service {} defines an annotation.
3 Match the project layers
| Term | Meaning |
|---|---|
@Service |
Annotation marker |
Registry |
Service registry |
Publisher |
Reactive publish |
ClassVisitor |
Bytecode traversal |