Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in

Lecture notes · chapter 1

Language overview

What Java is, what a source file is, and the rules that are not up for debate.

1.1 Introduction

Java is an interpreted, portable, object-oriented, strongly typed, safe, frugal and multithreaded language.

There are (roughly) two major Java implementations: OpenJDK and Oracle JDK.

1.2 Program and source

A Java program is made of one (or, more generally, several) source file(s). These files have the extension .java.

This is exactly what the workshop on this site does: the tab Exercices.java contains public class Exercices. Rename one, and you must rename the other.

1.3 Basic rules

  • Java is a case-sensitive language: canard is not the same thing as CAnArd.
  • Blocks of code are enclosed in braces. Each instruction ends with a ; (semicolon).
  • An instruction can span several lines: the compiler ignores indentation.

The compiler only sees the semicolons

int variable
=
0;

Comments are ignored by the compiler.

// Single-line comment
/* Comment
   over
   several
   lines. */

A first complete program, to run

public class Demo {
    public static void main(String[] args) {
        // One instruction, one semicolon.
        System.out.println("Hello, world!");
    }
}