Maven and third-party libraries
The programming exercises of this course have been done in the NetBeans development environment with a Test My Code plugin for downloading and submitting exercises. However the exercise templates we have used are not dependent on NetBeans or Test My Code in any way, and you can use them in other development environments as well.
The exercise templates use a tool called Maven, which is used for executing and managing programs.
Maven dictates the structure of our projects — every project has a file called
pom.xml located at its root, and their source code is located in a directory called
src directory typically has two sub-directories:
main containing the project source code and
test containing the source code of the tests for the project.
One advantage of using Maven is, that it is useful for downloading libraries. Libraries are source code which has been packaged to be used by anyone. For example we have used the JUnit library for unit tests. There is a library for almost anything. The search engine at https://mvnrepository.com/ finds over 10 million libraries, although many of them are different versions of the same library.
You can find for example libraries for using databases or creating telegram bots. Next you will get to know some of those libraries a bit better.
Using a database
Databases, or rather database management systems, are tools for managing data. You have a chance to familiarize yourself better with them on the course Introduction to Databases (TKT10004). Let's have a brief look at an application that uses a database.
There are several libraries for using databases at the address https://mvnrepository.com/. We will show an example of how to begin using the database management system called H2. This can be done by adding the H2 library to the file
pom.xml, between the tags
</dependencies>, which is the area for the library dependencies. You can take a look at the example below.
<!-- other content -->
<!-- other libraries -->
<!-- other libraries -->
<!-- other content -->
This has already been done in the exercise base. When the library dependency has been configured as part of the project, the classes included in that library are usable in the project. In the following exercise you are going to use the previously described dependency, and implement a program that uses a database to manage data.
As we mentioned above, you can use Maven to find a great number of libraries you can use as a part of your own applications. By searching telegram from https://mvnrepository.com/ you find e.g the TelegramBots library for making Telegram bots.
Telegram bots are programs which react to messages sent on Telegram, and for example tell jokes. Creating these bots is out of the scope of this course, but the skills you have learned will help you to study different tutorials. . If you want to learn to make a Telegram bot, read the guide at https://github.com/rubenlagus/TelegramBots/wiki/Getting-Started. Remember to start implementing your bot bit by bit — start by for example making a bit which joins a channel.
So far it has seemed like our applications have required a development environment to work. This is not strictly true however, because executing a program on a development environment is quite the same as executing a program outside of it.
We can define a class which contains the
public static void main method for starting the program.
Oracle has a javapackager tool for packaging an application. You can find information about using it from https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/packager.html.
Using the instructions on the website linked above you can create packaged versions of your applications you can share with others. The library used in the instructions can be found packaged as a Maven plugin from https://github.com/javafx-maven-plugin/javafx-maven-plugin.
There are other tools for packaging, for example the JavaPackager Maven plugin.
Other development environment
Java is one of the most used programming languages in the world, and it is used i.e in Android phones. The techniques for creating graphical user interfaces practiced in this course can be used for mobile applications as well, altough JavaFX is primarily targeted for desktop applications. If you want to use JavaFX for a mobile application, JavaFXPorts project is created for that. The JavaFXPorts project can be used to create mobile applications using the JavaFX library. You can find more information about it from https://docs.gluonhq.com/javafxports/.
If you are interested in developing mobile applications, it is worth it to study the Android's developer guide for app developers which can be found from https://developer.android.com/guide/. This programming course has given you excellent basis for learning app development. Correspondingly if you are interested in developing simple (mobile) games, we recommend learning to use the FXGL library.
Remember to check your points from the ball on the bottom-right corner of the material!