Introduction

Author

Ludovic Deneuville

Introduction to Java

  • 6h CM
  • 12h TP
  • ludovic.deneuville@ensai.fr
  • office 181
  • class based on those by Ikko Yamane, Benjamin Girault, Romaric Gaudel, Samuel Toubon and Olivier Levitt

Objectives

  • Learn the basic syntax of Java
  • Understand key OOP concepts
  • Learn how to use collections
  • Best practices

TP

  • 4 x 3h
  • Datalab SSPCloud
  • Follow instructions precisely
  • Don’t use LLM

Evaluation

  • Graded TP
    • 2 students max per group
    • to be completed at home
  • Table-top exam
    • duration: 1h30
    • a handwritten A4 sheet allowed

Why Java

History / Version

  • Created in 1991
    • by James Gosling and Mike Sheridan (Sun Microsystems)
  • Java 8 (2014) : Lambda, Stream, Optional
  • Java 17 (2021)
  • Java 21 (2023)

https://www.java.com/

  • Facebook story
  • LTS
  • 2009 Oracle
  • 2017 Java 9 -> Modules
  • 2018 Java 11
  • Java 17 : Sealed Classes, Refactor JDK

Portability

  • Compiled to bytecode
  • Runs on any machine with a JVM
  • “Write Once, Run Anywhere”

WORA: desktop, servers, smartphones

Robust / Secure

  • Automatic memory management
  • Strong Static Typing
  • Compile-Time Checks

Compiler

  • Transform java code into bytecode
  • Detects syntax and type errors
  • Optimization
  • javac MyClass.java ➡️ create file MyClass.class

JVM

Definition

The Java Virtual Machine (JVM) is the runtime environment for Java programs. It acts as an interpreter between Java code and the operating system.

The JVM :

  • Executes bytecode
  • Interacts with OS
  • Manages Memory (Garbage Collection)
  • java MyClass ➡️ run main method

JVM, JDK, JRE

  • JRE: Java Runtime Environment
  • JDK: Java Development Kit
Component Purpose
JVM Runs Java bytecode
JRE Contains JVM + libraries to run Java apps
JDK Includes JRE + compiler + dev tools

https://openjdk.org/projects/jdk/

  • JRE: java.util, java.io…, $java
    • to execute java app
  • JDK: $javac, new libraries
    • to dev java app

Java Vs Python

Java Python
Typing Strongly typed, static Strongly typed, dynamic
Compilation Compiled into bytecode Interpreted
Performance Very fast Slower
Syntax Verbose, requires {} Concise, uses indentation
Paradigm Object-oriented Multi-paradigm
Ecosystem Huge (Spring, Hibernate…) Large (Django, Flask, Pandas…)
  • Typing: int x = 10; vs x = 10
  • Interpreted: exécution à la volée
  • Multi-paradigm (objet, fonctionnel, impératif)

Resources

Practice java language