Skip to content

Commit 8bd8dc7

Browse files
committed
feat: Add Day 01 - Java Basics and Setup with Hello World examples
1 parent 3f4536d commit 8bd8dc7

File tree

4 files changed

+232
-0
lines changed

4 files changed

+232
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Day 01 - BasicStructure.java
3+
* Understanding Java Program Structure
4+
*
5+
* This program demonstrates the essential components of a Java program
6+
* and explains each part in detail.
7+
*/
8+
9+
// Import statements (we'll learn more about these later)
10+
import java.util.Date;
11+
12+
/**
13+
* This class demonstrates the basic structure of a Java program
14+
* Class names should start with a capital letter and use CamelCase
15+
*/
16+
public class BasicStructure {
17+
18+
// Class-level variables (we'll learn about these in detail later)
19+
private static final String PROGRAM_NAME = "Basic Structure Demo";
20+
21+
/**
22+
* Main method - the entry point of the program
23+
* This method must be public, static, and void
24+
* @param args command line arguments
25+
*/
26+
public static void main(String[] args) {
27+
// Method calls and program logic go here
28+
printProgramInfo();
29+
demonstrateStructure();
30+
showCurrentTime();
31+
}
32+
33+
/**
34+
* This method prints information about the program
35+
* Methods should have descriptive names and do one thing well
36+
*/
37+
public static void printProgramInfo() {
38+
System.out.println("=== " + PROGRAM_NAME + " ===");
39+
System.out.println("This program demonstrates Java structure.");
40+
System.out.println();
41+
}
42+
43+
/**
44+
* Demonstrates different parts of Java structure
45+
*/
46+
public static void demonstrateStructure() {
47+
System.out.println("Java Program Structure:");
48+
System.out.println("1. Package declaration (optional)");
49+
System.out.println("2. Import statements");
50+
System.out.println("3. Class declaration");
51+
System.out.println("4. Class variables and methods");
52+
System.out.println("5. Main method (entry point)");
53+
System.out.println();
54+
}
55+
56+
/**
57+
* Shows how to use imported classes
58+
*/
59+
public static void showCurrentTime() {
60+
Date currentTime = new Date();
61+
System.out.println("Current time: " + currentTime);
62+
System.out.println("Program completed successfully!");
63+
}
64+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Day 01 - Comments.java
3+
* Understanding Comments in Java
4+
*
5+
* This program demonstrates the three types of comments in Java:
6+
* 1. Single-line comments
7+
* 2. Multi-line comments
8+
* 3. Documentation comments (JavaDoc)
9+
*/
10+
11+
/**
12+
* This is a documentation comment (JavaDoc)
13+
* It's used to generate documentation for your code
14+
*
15+
* @author Your Name
16+
* @version 1.0
17+
* @since 2025
18+
*/
19+
public class Comments {
20+
21+
// This is a single-line comment
22+
// It starts with // and continues to the end of the line
23+
24+
/*
25+
* This is a multi-line comment
26+
* It starts with /* and ends with */
27+
/*
28+
* You can write multiple lines
29+
* of comments like this
30+
*/
31+
32+
/**
33+
* Main method - demonstrates different comment types
34+
* @param args command line arguments
35+
*/
36+
public static void main(String[] args) {
37+
// Print information about comments
38+
System.out.println("=== Java Comments Demo ===");
39+
System.out.println();
40+
41+
// Demonstrate single-line comments
42+
System.out.println("1. Single-line comments:");
43+
System.out.println(" // This is a single-line comment");
44+
System.out.println();
45+
46+
// Demonstrate multi-line comments
47+
System.out.println("2. Multi-line comments:");
48+
System.out.println(" /* This is a multi-line comment */");
49+
System.out.println();
50+
51+
// Demonstrate documentation comments
52+
System.out.println("3. Documentation comments:");
53+
System.out.println(" /** This is JavaDoc comment */");
54+
System.out.println();
55+
56+
// Show best practices
57+
System.out.println("Best Practices:");
58+
System.out.println("- Use comments to explain WHY, not WHAT");
59+
System.out.println("- Keep comments up to date with code changes");
60+
System.out.println("- Use meaningful variable and method names");
61+
System.out.println("- Write self-documenting code when possible");
62+
63+
// Calculate and display a simple example
64+
int number = 42; // This is the answer to everything
65+
System.out.println("\nExample: The number is " + number);
66+
}
67+
68+
/**
69+
* This method demonstrates how to use JavaDoc comments
70+
* for documenting methods
71+
*
72+
* @param name the name to greet
73+
* @return a greeting message
74+
*/
75+
public static String greet(String name) {
76+
return "Hello, " + name + "!";
77+
}
78+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Day 01 - HelloWorld.java
3+
* Your first Java program
4+
*
5+
* This program demonstrates the basic structure of a Java application
6+
* and shows how to print text to the console.
7+
*/
8+
public class HelloWorld {
9+
10+
/**
11+
* The main method is the entry point of any Java application
12+
* @param args command line arguments (not used in this example)
13+
*/
14+
public static void main(String[] args) {
15+
// This is a single-line comment
16+
System.out.println("Hello, World!");
17+
18+
// Print multiple lines
19+
System.out.println("Welcome to Java Programming!");
20+
System.out.println("This is Day 01 of your Java learning journey.");
21+
22+
// Print without moving to next line
23+
System.out.print("Java is ");
24+
System.out.print("awesome!");
25+
System.out.println(); // Move to next line
26+
27+
// Print with formatting
28+
System.out.println("Let's learn Java together!");
29+
}
30+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Day 01 - Java Basics and Setup
2+
3+
## 📚 What You'll Learn Today
4+
5+
- Understanding what Java is and its history
6+
- Setting up your Java development environment
7+
- Writing your first Java program
8+
- Understanding the basic structure of a Java program
9+
- Running Java programs from command line
10+
11+
## 🎯 Key Concepts
12+
13+
### What is Java?
14+
Java is a high-level, object-oriented programming language that runs on billions of devices. It's known for its "Write Once, Run Anywhere" capability.
15+
16+
### Java Program Structure
17+
Every Java program has these essential components:
18+
- **Class declaration**: `public class ClassName`
19+
- **Main method**: Entry point of the program
20+
- **Statements**: Instructions that perform actions
21+
22+
### Basic Syntax Rules
23+
- Java is case-sensitive
24+
- Statements end with semicolons (;)
25+
- Code blocks are enclosed in curly braces {}
26+
- File name must match the public class name
27+
28+
## 📁 Files in This Day
29+
30+
1. **HelloWorld.java** - Your first Java program
31+
2. **BasicStructure.java** - Understanding Java program structure
32+
3. **Comments.java** - Different types of comments in Java
33+
34+
## 🚀 How to Run
35+
36+
1. Open command prompt/terminal
37+
2. Navigate to this folder
38+
3. Compile: `javac HelloWorld.java`
39+
4. Run: `java HelloWorld`
40+
41+
## 💡 Exercises
42+
43+
1. Modify the HelloWorld program to print your name
44+
2. Create a program that prints multiple lines
45+
3. Experiment with different comment types
46+
47+
## 🔍 Common Issues
48+
49+
- **'javac' is not recognized**: Make sure Java is installed and PATH is set
50+
- **File not found**: Ensure you're in the correct directory
51+
- **Compilation errors**: Check for typos and missing semicolons
52+
53+
## 📖 Additional Resources
54+
55+
- [Oracle Java Documentation](https://docs.oracle.com/javase/)
56+
- [Java Tutorial](https://docs.oracle.com/javase/tutorial/)
57+
58+
---
59+
60+
**Next Day**: Day 02 - Variables and Data Types

0 commit comments

Comments
 (0)