Module 1: Introduction to Java
Lesson 1.1: What is Java?
Objective: Understand the basics of Java, its features, and its uses.
What is Java?
Java is an object-oriented, class-based programming language that is designed to have as few implementation dependencies as possible.
It is widely used for building web applications, Android apps, server-side applications, and more.
Java’s Key Features:
Platform independence (Write Once, Run Anywhere)
Object-Oriented
Simple and easy to learn
Secure (offers features like bytecode verification)
Rich standard library
Why Java?
Java is everywhere! It’s used in backend development, Android apps, cloud systems, big data tools, and more.
Lesson 1.2: Setting Up Your Java Development Environment
Objective: Install Java and set up an IDE to write Java code.
Step 1: Install Java Development Kit (JDK)
Go to the Oracle JDK website
Download the JDK that matches your operating system (Windows, macOS, or Linux).
Follow the installation instructions provided on the website.
Step 2: Install an IDE
Recommended IDEs: IntelliJ IDEA, Eclipse, or Visual Studio Code.
Example for IntelliJ IDEA:
Download and install IntelliJ IDEA.
After installation, open IntelliJ IDEA and create a new project. Select Java as the project type.
Make sure to link the JDK during setup.
Step 3: Write Your First Program
Open your IDE and create a new Java file, name it HelloWorld.java.
Write this simple code to print "Hello, World!" to the console:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Exercise: Run the program. You should see "Hello, World!" printed in the console.
Module 2: Basic Java Syntax
Lesson 2.1: Variables and Data Types
Objective: Learn how to use variables and understand different data types in Java.
Variables and Data Types:
Variables store data, and each variable has a type that defines what kind of data it can hold.
Primitive Data Types:
int (integer values)
double (floating-point values)
char (single character)
boolean (true or false)
Example:
int age = 25;
double price = 19.99;
char grade = 'A';
boolean isJavaFun = true;
Exercise: Declare variables for your name (String), age (int), height (double), and whether you like programming (boolean). Print them out using System.out.println().
Lesson 2.2: Operators in Java
Objective: Understand how to use operators for calculations and comparisons.
Arithmetic Operators:
+, -, *, /, % (modulus)
Example:
java
Copy
int sum = 5 + 3; // sum = 8
int product = 4 * 2; // product = 8
Relational Operators:
==, !=, >, <, >=, <=
Example:
boolean isEqual = (5 == 5); // true
boolean isGreater = (10 > 5); // true
Logical Operators:
&& (AND), || (OR), ! (NOT)
Example:
boolean result = (5 > 3) && (8 > 6); // true
Exercise: Write a program to calculate the area of a rectangle and check if the result is greater than 100.
Lesson 2.3: Control Flow Statements
Objective: Learn how to control the flow of execution in a program.
if, else if, else Statements:
Use conditions to control code flow.
Example:
int number = 10;
if (number > 5) {
System.out.println("Number is greater than 5");
} else {
System.out.println("Number is 5 or less");
}
switch Statement:
Use when you have multiple options to check,
Example:
int day = 3;
switch (day) {
case 1: System.out.println("Monday"); break;
case 2: System.out.println("Tuesday"); break;
default: System.out.println("Other day");
}
Exercise: Create a program that asks the user for a number and checks if it's even or odd using if statements.
Module 3: Object-Oriented Programming (OOP) Basics
Lesson 3.1: Introduction to OOP Concepts
Objective: Understand the core principles of object-oriented programming.
What is OOP?
OOP is a programming paradigm that uses objects and classes.
Key concepts:
Classes: Blueprints for objects.
Objects: Instances of classes.
Encapsulation: Hiding data inside a class and exposing methods to access it.
Inheritance: A class can inherit properties and methods from another class.
Polymorphism: Different classes can have methods with the same name but different implementations.
Abstraction: Hiding complex implementation details.
Lesson 3.2: Methods in Java
Objective: Learn how to create and use methods.
Defining Methods:
Methods allow you to organize code into reusable blocks.
Example:
public class Calculator {
public int add(int a, int b) {
return a + b;
}
}
Calling Methods:
Example:
Calculator calc = new Calculator();
int sum = calc.add(5, 3); // sum = 8
Exercise: Create a method that takes two integers and returns their product.
Lesson 3.3: Constructors
Objective: Learn how constructors work in Java.
What is a Constructor?
A constructor initializes an object when it is created.
Example:
public class Car {
String model;
int year;
public Car(String model, int year) {
this.model = model;
this.year = year;
}
}
Exercise: Create a Person class with a constructor to initialize the name and age of a person.
Module 4: Working with Collections
Lesson 4.1: Arrays
Objective: Learn how to work with arrays in Java.
Creating and Using Arrays:
Arrays store multiple values of the same type.
Example:
int[] numbers = {1, 2, 3, 4, 5};
System.out.println(numbers[0]); // Output: 1
Exercise: Create an array to store the names of your friends and print each one using a loop.
Lesson 4.2: ArrayLists
Objective: Learn how to use the ArrayList class.
ArrayLists:
Dynamic arrays that can grow or shrink in size.
Example:
ArrayList<String> names = new ArrayList<>();
names.add("Alice");
names.add("Bob");
System.out.println(names.get(0)); // Output: Alice
Exercise: Create an ArrayList of integers, add some values, and print them.
Module 5: Handling Errors
Lesson 5.1: Exception Handling
Objective: Understand how to handle errors in Java.
What are Exceptions?
Exceptions are runtime errors that can be handled with try-catch blocks.
Example:
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e.getMessage());
}
Exercise: Write a program that prompts the user for a number and divides 100 by the number, handling division by zero.
Module 6: Java Project
Lesson 6.1: Building a Simple Java Project
Objective: Apply everything you’ve learned in a small project.
Project Example: Basic Calculator
Create a simple calculator program that performs basic arithmetic operations based on user input.
Module 7: Final Thoughts and Next Steps
Lesson 7.1: Recap of What You Learned
Objective: Review key concepts and wrap up the course.
Key Takeaways:
Java syntax, control flow, OOP concepts, methods, arrays, collections, error handling.
Lesson 7.2: What’s Next?
Objective: Provide resources for continued learning.
Further Reading:
Websites like Oracle Java Documentation
Next Learning Steps:
Dive into more advanced topics like GUI programming (JavaFX), multi-threading, and frameworks like Spring.