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.
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.
| Type | Example | Size | Description |
|---|---|---|---|
int | 25 | 4 bytes | Whole numbers |
double | 12.5 | 8 bytes | Floating point numbers |
char | 'A' | 2 bytes | Single character |
boolean | true | 1 bit | Logical true/false |
String | "Hello" | variable | Sequence 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
Ask for the user’s name and greet them: Hello, [name]! Welcome to Java.
Read two integers and print their sum, difference, product, and quotient (handle division by zero if you want to be safe).
Convert Celsius to Fahrenheit. Use formula: F = (C * 9/5) + 32. Input a decimal value and print the result.
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
Scannerfor console input andSystem.out.println()for output.
Next: Module 2 — Control Flow and Logic (conditionals, loops, practical mini-projects).