Lab: the StreamingPlatform class¶
☕ Java 17 · Your First Java Class · 3/3
Goal: write a complete class with documentation, data, behavior and an entry point, then run it.
Setup: in your project folder, create StreamingPlatform.java. Compile and run it from the terminal.
Step 1 — Document the class¶
Start with a Javadoc comment, then the class declaration:
The double asterisk /** makes it Javadoc. @author is a standard Javadoc tag. Editors show this text when you hover over the class name.
Step 2 — Add a field¶
Every StreamingPlatform object will have a name. It gets its value later, once an object exists.
Step 3 — Add a method¶
void: the method does something and returns nothing.
Step 4 — Add the main method¶
public static void main(String[] args) {
StreamingPlatform p = new StreamingPlatform();
p.name = "ADC Flix";
p.launch();
}
new StreamingPlatform()creates an object in memory, andprefers to it.p.name = "ADC Flix"sets the object's field: the dot reaches what belongs to an object.p.launch()calls the method on that object.
Step 5 — Compile and run¶
Final code¶
/**
* Entry point of the ADC Flix platform.
* @author Mounir
*/
public class StreamingPlatform {
// Platform name
String name;
// Display a welcome message
public void launch() {
System.out.println("ADC Flix is live!");
}
public static void main(String[] args) {
StreamingPlatform p = new StreamingPlatform();
p.name = "ADC Flix";
p.launch();
}
}
← Comments, files and main · Back to the series
🎓 Preparing the OCP Java 17 exam? Exam traps and practice questions for this section → (optional)