Your First Program
Congratulations! You're about to write your first program. We'll start with the traditional "Hello, World!" program and explore basic programming concepts.
🌍 Why "Hello, World!"?
The "Hello, World!" program is a time-honored tradition in programming. It's usually the first program that new programmers write because it:
- Tests that your development environment is working correctly
- Introduces basic syntax of the programming language
- Gives you the satisfaction of running your first program
- Connects you to a long tradition of programmers
Hello World in Different Languages
Python
# Your first Python program
print("Hello, World!")
# Variables and basic operations
name = "Alice"
age = 25
print(f"My name is {name} and I'm {age} years old")
# Simple calculation
x = 10
y = 5
result = x + y
print(f"{x} + {y} = {result}")
Python uses simple, readable syntax. The print() function displays text, and f-strings make it easy to include variables in your output.
How to Run:
- 1Save the code in a file called hello.py
- 2Open terminal/command prompt
- 3Navigate to the file location
- 4Run: python hello.py
JavaScript
// Your first JavaScript program
console.log("Hello, World!");
// Variables and basic operations
let name = "Alice";
let age = 25;
console.log(`My name is ${name} and I'm ${age} years old`);
// Simple calculation
let x = 10;
let y = 5;
let result = x + y;
console.log(`${x} + ${y} = ${result}`);
JavaScript uses console.log() to display output. Template literals (backticks) make it easy to include variables in strings.
How to Run:
- 1Save the code in a file called hello.js
- 2Open terminal/command prompt
- 3Navigate to the file location
- 4Run: node hello.js
Java
// Your first Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
// Variables and basic operations
String name = "Alice";
int age = 25;
System.out.println("My name is " + name + " and I'm " + age + " years old");
// Simple calculation
int x = 10;
int y = 5;
int result = x + y;
System.out.println(x + " + " + y + " = " + result);
}
}
Java requires a class structure and a main method. System.out.println() displays output, and you need to declare variable types.
How to Run:
- 1Save the code in a file called HelloWorld.java
- 2Open terminal/command prompt
- 3Compile: javac HelloWorld.java
- 4Run: java HelloWorld
Basic Programming Concepts
Variables
Store data values that can be used and changed
Functions
Reusable blocks of code that perform specific tasks
Data Types
Different kinds of data like text, numbers, true/false
Comments
Notes in your code that explain what it does
🎯 Try It Yourself
Now it's your turn! Try modifying the Hello World program:
Easy Challenges:
- Change "Hello, World!" to your name
- Add another print statement
- Create variables for your age and city
- Try different text and numbers
Next Steps:
- Ask the user for their name (input)
- Use an if statement for conditions
- Create a simple loop
- Write a basic function
Common Beginner Errors
Syntax Error
Typos or incorrect code structure
Example: Missing quotes, parentheses, or semicolons
Solution: Check for typos and make sure all brackets/quotes are closed
Name Error
Using a variable that doesn't exist
Example: print(nam) when you meant print(name)
Solution: Check variable names for typos and make sure they're defined
Indentation Error
Incorrect spacing (mainly in Python)
Example: Mixing tabs and spaces, or wrong indentation level
Solution: Use consistent indentation (4 spaces is standard)
🐛 Debugging Tips for Beginners
When Your Code Doesn't Work:
- Read the error message carefully
- Check for typos in variable names
- Make sure all brackets and quotes match
- Try running the code line by line
Good Debugging Habits:
- Add print statements to see what's happening
- Test small pieces of code separately
- Use your editor's syntax highlighting
- Don't be afraid to start over with a simpler version
- Ask for help when you're stuck
Congratulations!
You've just written your first program! This is the beginning of an exciting journey. Every expert programmer started exactly where you are now.
🚀 What's Next?
Now that you've written your first program, here are some great next steps:
- Explore more about your chosen programming language
- Learn about variables, loops, and functions in depth
- Try building a simple calculator or guessing game
- Join programming communities and forums
- Start working on small projects that interest you