Lab 8 : Advanced Topics
Introduction
In this last session we will overview some of the more advanced topics: debugging and dynamic class loading. The session will be mostly interactive.
Exercise 1: Debugging
Overview the debugging capability of Eclipse.
Exercise 2: Dynamic loading: basics
Classes in Java are loaded on demand. To verify that execute java with the command line argument
-verbose:class
. What do you see?
Exercise 3: Dynamic loading: reloading
In this exercise we will create a simple plugin infrastructure.
- Create a sample interface called
IPlugin
that will contain one method void printMessgage()
.
- Create two different plugin implementations
PluginA
and PluginB
that both prints out a different message.
- Create a new class with
main
method that loads these plugins statically (not using reflection)
- Change the previous and load the classes dynamically using reflection. Compare the approaches? What is the difference? What does the other one allows us to do?
- What is the difference between
Class.newInstance()
and Constructor.newInstance
?
- Dynamically reloads plugin at runtime.
Exercise 4: Apply the plugin mechanism in the Simulator
Could you extend the simulator in the way that you periodically (every second) scan a certain (hardcoded) directory
plugins
and every time there is a new class you load it and show it on the canvas. The only class that can appear there is an instance of
AbstractCreatute
.