Module 1 — Introduction to Java & Programming Basics

A friendly, compact first module covering what Java is, setting up the environment, basic syntax, data types, simple I/O and practice exercises.

Estimated pages: 4–6 Level: Beginner
Contents: What is Java Setup Syntax

1.1 — What is Java?

Java is a high-level, object-oriented, platform-independent programming language originally created by Sun Microsystems (now Oracle) in 1995. It was designed for portability, reliability, and ease of use. The principle “Write Once, Run Anywhere (WORA)” means Java bytecode runs on any machine with a Java Virtual Machine (JVM).

Common uses

  • Android mobile applications
  • Web & enterprise backends (Spring Boot)
  • Desktop GUIs and tools
  • Big data platforms and distributed systems

1.2 — Setting up your Java environment

Install the JDK

Download and install the Java Development Kit (JDK). Modern recommended LTS versions: 17 or later.

// verify installation in terminal / command prompt
java -version
javac -version

Choose an IDE

  • IntelliJ IDEA — excellent for beginners & pros
  • Eclipse — classic, widely used in enterprise
  • VS Code — lightweight with Java extensions

First Java file

Save the file as HelloWorld.java, then compile and run.

// HelloWorld.java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, Java World!");
    }
}

Compile: javac HelloWorld.java — Run: java HelloWorld

1.3 — Understanding a Java program structure

Key elements:

  • Class definition — Java code is organized inside classes.
  • Main method — the entry point for standard Java applications: public static void main(String[] args).
  • Statements — executed line-by-line inside methods.
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

1.4 — Java basic syntax

Case sensitivity & naming

Java is case-sensitive. Use PascalCase for class names and camelCase for variables & methods.

Comments

// single-line comment
/* multi-line comment */

1.5 — Data types and variables

Java is statically typed: every variable has a type declared at compile time.

TypeExampleSizeDescription
int254 bytesWhole numbers
double12.58 bytesFloating point numbers
char'A'2 bytesSingle character
booleantrue1 bitLogical true/false
String"Hello"variableSequence of characters (class)

Example

int age = 25;
double height = 1.75;
boolean isStudent = true;
String name = "Liam";
System.out.println(name + " is " + age + " years old.");

1.6 — Operators

Arithmetic

+  -  *  /  %
int a = 10, b = 3;
System.out.println(a + b);  // 13
System.out.println(a % b);  // 1

Comparison & Logical

Comparison: ==, !=, >, <, >=, <= — Logical: && (and), || (or), ! (not)

1.7 — Input and Output

Use Scanner to read from standard input (keyboard).

import java.util.Scanner;

public class InputExample {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter your name: ");
        String name = sc.nextLine();
        System.out.print("Enter your age: ");
        int age = sc.nextInt();
        System.out.println("Hello, " + name + "! You are " + age + " years old.");
        sc.close();
    }
}

Tip: Always call sc.close() when done with the scanner (for simple console apps).

1.8 — Java program flow

Execution starts at main() and runs statements sequentially. Conditional branching and loops change the flow — these are covered in Module 2.

1.9 — Practice Exercises

Exercise 1 — Hello, User!

Ask for the user’s name and greet them: Hello, [name]! Welcome to Java.

Exercise 2 — Simple Math

Read two integers and print their sum, difference, product, and quotient (handle division by zero if you want to be safe).

Exercise 3 — Temperature Converter

Convert Celsius to Fahrenheit. Use formula: F = (C * 9/5) + 32. Input a decimal value and print the result.

Exercise 4 — Age in Months (Challenge)

Input: age in years (integer). Output: age in months (years × 12). Add a friendly message.

Try implementing each exercise in your IDE and test with different inputs. Keep your code modular and add comments.

1.10 — Summary

  • Java is platform-independent and object-oriented.
  • Programs begin at the main() method.
  • Java is statically typed — declare variable types.
  • Use Scanner for console input and System.out.println() for output.

Next: Module 2 — Control Flow and Logic (conditionals, loops, practical mini-projects).

Prepared by your Java tutor — ready for Module 2 when you are.
Notes: save as module1-java.html to keep this page offline.