Programming foundations

Stage 1 · Lesson 2 of 9

Types, variables and input

Your first language

Java is : every has a type that is fixed when the code is compiled, such as int age = 20 or String name = "Ada". The types (int, long, double, boolean, char) hold their values directly. Everything else, String included, is a reference that points to an object.

cuts off the decimal part, so 7 / 2 is 3. An int also silently overflows (wraps around) past about 2.1 billion. var lets the compiler work out a local variable's type for you, which is called type inference, but that type is still fixed.

Each primitive has a wrapper class, such as Integer, which is used in collections, and a wrapper can be null. Read with Scanner. Convert text with Integer.parseInt, which throws NumberFormatException on "abc".

A question to check yourself, an AI practice session and 4 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

  • CourseFree
    Java Programming MOOC

    University of Helsinki · Beginner

    Free Helsinki course with hundreds of auto-tested exercises; parts 1 to 8 cover this stage

  • GuideFree
    Dev.java: Learn Java

    Oracle · Beginner

    Official tutorials from the Java team: read the language basics path next to the MOOC

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?