Learn Java & Python Basics

Master the fundamentals of two powerful programming languages through interactive lessons

Java Java
Python Python

Learning Path

Java Java Fundamentals

  1. 1

    Variables & Data Types

    Learn primitive types, declarations, and type casting

  2. 2

    Control Structures

    Master if-else, switch, loops (for, while, do-while)

  3. 3

    Methods & Classes

    Understand OOP concepts, constructors, and methods

  4. 4

    Arrays & Collections

    Work with arrays, ArrayLists, and basic data structures

Python Python Fundamentals

  1. 1

    Variables & Data Types

    Learn dynamic typing, numbers, strings, and lists

  2. 2

    Control Flow

    Master if-elif-else, loops (for, while), and range()

  3. 3

    Functions

    Define functions, parameters, return values, and scope

  4. 4

    Lists & Dictionaries

    Work with sequences, list comprehensions, and dictionaries

Lesson 1: Variables & Data Types

Java Variables

Java is statically typed, meaning you must declare the variable type before using it. Primitive types include int, double, boolean, and char.

// Variable declaration and initialization
int age = 25;
double price = 19.99;
boolean isJavaFun = true;
char grade = 'A';

// Constants (cannot be changed)
final double PI = 3.14159;

Python Variables

Python is dynamically typed - you don't need to declare variable types. Common types include int, float, bool, str, and list.

# Variable assignment
age = 25
price = 19.99
is_python_fun = True
grade = 'A'

# Constants (by convention, not enforced)
PI = 3.14159

Key Differences

  • Type Declaration: Java requires explicit type declaration, Python infers types
  • Constants: Java has final keyword, Python uses naming conventions (UPPER_CASE)
  • Strings: Java uses double quotes, Python can use single or double quotes
  • Boolean Values: Java uses true/false, Python uses True/False

Interactive Exercise

Fix the variable declarations in this Java code. There are 3 errors to correct.

public class Main {
    public static void main(String[] args) {
        // Fix these variable declarations
        int count = "10";
        double average = 3.5
        boolean isCorrect = "true";
        char initial = A;
        
        System.out.println("Count: " + count);
    }
}

Lesson 2: Control Structures

Java Control Structures

Java uses traditional C-style control structures with curly braces {}.

// If-else statement
int score = 85;
if (score >= 90) {
    System.out.println("A");
} else if (score >= 80) {
    System.out.println("B");
} else {
    System.out.println("C");
}

// For loop
for (int i = 0; i < 5; i++) {
    System.out.println(i);
}

// While loop
int count = 0;
while (count < 3) {
    System.out.println(count);
    count++;
}

Python Control Structures

Python uses indentation (whitespace) to define code blocks instead of curly braces.

# If-elif-else statement
score = 85
if score >= 90:
    print("A")
elif score >= 80:
    print("B")
else:
    print("C")

# For loop (often used with range())
for i in range(5):
    print(i)

# While loop
count = 0
while count < 3:
    print(count)
    count += 1

Control Structures Challenge

Write a Java program that prints numbers from 1 to 100. For multiples of 3 print "Fizz", for multiples of 5 print "Buzz", and for multiples of both print "FizzBuzz".

public class FizzBuzz {
    public static void main(String[] args) {
        // Your code here
        
        
    }
}

Additional Practice Exercises

Calculator Program

Create a simple calculator that can add, subtract, multiply, and divide two numbers.

Java Python

Number Guessing Game

Program generates a random number and user tries to guess it with hints.

Java Python

Student Gradebook

Store student names and grades, then calculate averages and find highest/lowest.

Java Python

Learning Resources

Made with DeepSite LogoDeepSite - 🧬 Remix