Java Basics, Gradle Build file

All Java code mentioned in the following exercise should be developed within the package pt.ist.ap.labs;

  1. Create a project named 'lab01' with the following contents:
    • build.gradle: file that defines the project and supports the following tasks:
      • clean: cleans the entire project's generated files
      • compileJava: compile the source code into the classes directory
      • run: runs the application Hello World
    • src/main/java: directory where the java source files reside
    • build/classes: directory where the java bytecode files reside
  2. Create a class named HelloWorld under the src directory. This class should print "Hello World!" when its main method runs.
  3. Run the program from the console:
    • using the task run from the Gradle build file
    • directly using the java command
  4. Reusing the previous project, do the following changes:
    • Create a new interface Message with the method void say();
    • Create a class named GoodbyeWorld that implements Message. The method say() should print "Goodbye World!"
    • Change HelloWorld so that it also implements Message. The method say() should now print "Hello World!"
  5. Develop a program that asks the user for a String, which should be the name of a class that implements the Message interface. Then, using reflection, the program should instantiate the given class. Finally, without using reflection, it should invoke the say() method on the instance of Message.
  6. Compile and run the previous program.