Seminar 01 - Project Setup
The first seminar focuses on learning how to set up new project completely from scratch. As a precondition, you will be required to setup your developer environment.
Note: Except for task 0, you ought to work in pairs in every task.
Task 0 : appendSetup your environment
As part of this seminar you will need the following tools
- Git VCS
- JDK 17
- Maven 3.8.5 or newer
- IntelliJ IDEA
To install these tools, follow our guide for either Linux/MacOS or Windows. To set up the environment on the faculty computer, you only need to follow Faculty guide.
Note: Even if you work on faculty computers during the seminars, you might want to set up the environment on your personal machine to work on the seminar project.
Task 1: Create Maven Project
In this task, you will create a simple “Hello World” project from scratch.
Maven Projects
In Maven, projects (artifacts) are identified by so-called GAV (Group - Artifact - Version) triplet.
- group: identifies your organisation and usually identifies the base package of the application
- artifact: identifies a specific project under the given group
- version: version of the artifact
An example of such project/artifact could be
groupId: cz.muni.fi.pv168
artifactId: hello-world
version: 1.0-SNAPSHOT
Note: The -SNAPSHOT
suffix, in this case, is a Maven version qualifier which means that this is a development (unreleased) version of our application.
Task 1.1: Creating the project
We will use Intellij IDEA to kickstart the base for the new Maven project. The following screenshots will walk you through the process.
Notice the group id
and artifact id
fileds, version is missing as 1.0-SNAPSHOT
will be used by default.
IntelliJ IDEA will create all required files and directories. The standard directory structure of the Maven project looks as follows, but everything is customisable. Thus, you can come across Maven projects with different directory layouts.
project
|- src
|- main
|- java
|- resources
|- test
|- java
|- resources
|- pom.xml
Task 1.2: Hello World
Create a class named cz.muni.fi.pv168.Application
, which will print the string Hello World
to the standard output (stdout).
Build and run the Application. How did you start the app? Does it have any disadvantages? Can it be distributed to other users?
Task 1.3: Distribution
In order to create a distributable version of a Java application, a jar archive containing all the required classes is usually created. By default, Maven produces a JAR archive with the following command.
mvn clean package
The JAR application can then be run as follows
java -cp target/hello-world-1.0-SNAPSHOT.jar cz.muni.fi.pv168.Application
Note: this is a very basic way of creating a JAR archive. Firstly, you can see that it is mandatory to specify the class containing a main method. This fact is just one of the limitations of this default approach. Can you think of other issues?
Task 1.4: Version Control
Create an empty project named pv168-hello-world
in your GitLab namespace and push your code there! Make sure the repository is empty and is not intialized with any files.
If you are not sure how to push an existing code from a local folder to a remote repository, you can follow these steps:
- Initialize the project directory as an empty git repository
- Add a remote repository named
origin
pointed at your GitLab repository - Think about which files you want in your remote repository and set up a .gitignore file.
- Add all those files to be tracked by git. Then create a commit and push it into the remote repository.
Task 2: Calculator
Your next task is to explore a sample GUI application implemented in Java, which all students should be familiar with. The application demonstrates a simple calculator supporting just basic arithmetic operations.
Task 2.1: Fork the repository and make it private
- In each pair, choose the one who will do all the git work. The other one should assist.
- Fork the Calculator repository into your personal namespace.
-
Make it private, so that it is visible only to explicitly assigned individuals.
Go to Settings > General and expand Visibility, project features, permissions. Then change the Project visibility and scroll down (to be able) to click on Save changes.
Task 2.2: Make the repository accessible for your partner
-
Add your partner under the Developer role.
Go to Project information > Members and click on Invite Members. Fill in the FI login name of your partner and choose Developer in Select a role. Finally, click on Invite.
-
Add both of your seminar tutors under the Reporter role.
You can find the FI login names of your seminar group tutors in Seminars.
Task 2.3: Clone the repository for your work
Each pair clones the repository into a single computer as they are working together as one person during the seminar.
Task 2.4: Implement the Exponentiation operation
Implement the exponentiation operation, represented as ^
(b
raised to the power of n
is written as b^n
). Examples:
2^3=8.0
2^0.5=1.4142135623730951
Task 2.5: Implement the Exponentiation operation again in refactored code
Change the branch you are working on to reworked
and perform the same task.
git switch reworked
Task 3: Discuss your experience
Discuss with pairs around you what you experienced during the work on Task 2.
Concentrate on a comparison of your opinions on:
- how easy was the code to understand,
- what amount of code you had to write, and where exactly,
- how you positioned the new operation in the GUI and why,
- how friendly the GUI of the calculator was for its users,
- etc.