Java, IntelliJ IDEA and Maven

https://github.com/heig-vd-dai-course

Web · PDF

L. Delafontaine and H. Louis, with the help of GitHub Copilot.

This work is licensed under the CC BY-SA 4.0 license.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Objectives

  • Learn why Java is a popular programming language
  • Manage multiple Java versions with SDKMAN!
  • Develop Java apps with IntelliJ IDEA and Maven
  • Manage dependencies with Maven
  • Develop essential skills for professional Java development
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Java

More details for this section in the course material. You can find other resources and alternatives as well.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Java

  • General-purpose, object-oriented language
  • Write once, run anywhere (WORA)
  • Created by James Gosling, 1995 at Sun Microsystems
  • The documentation seems scary but you will get used to it and it is very useful
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Java virtual machine

  • Compiles source code to bytecode
  • Executes in Java virtual machine (JVM)
  • Where a JVM exists, Java can run (most of the time)
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

JVM versions

  • Multiple implementations exist
  • Can target different platforms and/or specific features
  • JDK for development, JRE for running
  • Eclipse Temurin is recommended
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Java versions and version managers

  • Java 21 is the latest LTS
  • You can use SDKMAN! to manage multipe versions of Java
  • Match versions for project consistency
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Compiling and running Java programs

  • Compile manually with javac command

    javac HelloWorld.java
    
  • Execute with java command

    java HelloWorld
    
  • Modern way: package into JAR files with the help of Maven

    java -Xmx1024M -Xms1024M -jar minecraft_server.1.20.1.jar nogui
    
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Summary

  • Java is a general-purpose, class-based, object-oriented programming language.
  • Java is compiled to bytecode, which is then executed by a Java virtual machine (JVM).
  • Java is intended to be portable, thanks to the JVM.
  • Java has various versions, each with its own set of features and improvements.
  • Versions managers allow you to install and switch between different versions of Java.
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

IntelliJ IDEA

More details for this section in the course material. You can find other resources and alternatives as well.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

IntelliJ IDEA

  • IDE for (Java) software development
  • Developed by JetBrains
  • Works on Windows, macOS, Linux
  • Quite a standard in the industry
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Community Edition and Ultimate Edition

  • Community (free) and Ultimate (paid)
  • Free student license available - you can get it!
  • The Community Edition is sufficient for this course
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

JetBrains Toolbox App

  • Manage multiple JetBrains IDEs
  • Install and update in one place
  • Optional but very useful
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Configuration files and Git

  • .idea directory for project config
  • Allow to share project settings between developers
  • Some files must be ignored to avoid issue (local config) in Git
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Summary

  • IntelliJ IDEA is an integrated development environment (IDE) written in Java for developing computer software.
  • IntelliJ IDEA is available in two editions: the Community Edition (free and open-source) and the Ultimate Edition (proprietary).
  • You are eligible for a free student license for the Ultimate Edition.
  • When creating a new project, IntelliJ IDEA will create a .idea directory containing the project configuration files.
  • Some of these files must be ignored by Git, as they contain local configuration that is specific to your computer.
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven

More details for this section in the course material. You can find other resources and alternatives as well.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven

  • Maintained by Apache Software Foundation
  • Software project management tool
  • Manages dependencies
  • Build automation tool
  • Allows to define a standard project structure
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven project structure

  • Standardized directory structure
    • src/main/java
    • src/main/resources
    • src/test/java
  • Simplifies build process with conventions
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

pom.xml file

  • Configuration and build settings
  • Shared among developers
  • Defines dependencies and plugins:
    • Plugins extend Maven functionality
    • Dependencies are external libraries
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven lifecycle

  • Maven defines build process
  • Composed of phases and goals
  • Phases load plugin goals
  • Goals execute tasks on your project (e.g., compile, test, package)
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven Repository

  • Public repository of Java libraries
  • Maven can download dependencies automatically
  • You can publish your own libraries
  • Many libraries available such as picocli, a library for building CLI applications
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Maven wrapper

  • Allows to use Maven without installing it
  • Wrapper script downloads Maven
  • Ensures consistent Maven version
  • Use mvnw or mvnw.cmd instead of mvn
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Summary

  • Maven is a software project management and comprehension tool.
  • Maven is a dependency manager for Java projects.
  • Maven is a build automation tool for Java projects.
  • Maven defines a standard directory structure for Java projects.
  • Maven defines a standard build process for Java projects.
  • The pom.xml file contains the configuration of your Maven project.
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Questions

Do you have any questions?

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Practical content

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

What will you do?

  • Install and configure SDKMAN!, Java, Maven and IntelliJ IDEA
  • Create and run a small CLI application with picocli, an external Maven dependency
  • Publish your project on GitHub
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Find the practical content

You can find the practical content for this chapter on GitHub.

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Finished? Was it easy? Was it hard?

Can you let us know what was easy and what was difficult for you during this chapter?

This will help us to improve the course and adapt the content to your needs. If we notice some difficulties, we will come back to you to help you.

➡️ GitHub Discussions

You can use reactions to express your opinion on a comment!

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

What will you do next?

In the next chapter, you will learn the following topics:

  • Java IOs: input/output processing
    • How to read and write files?
    • Why is encoding important?
    • How to deal with exceptions?
HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0

Sources

HEIG-VD - DAI Course 2024-2025 - CC BY-SA 4.0