This is a simple Java project that demonstrates how to use Streams and Records (Java 16+) to read, parse, and summarize weather data from a CSV file. The program calculates basic weather statistics such as average temperature, maximum/minimum temperatures, and the number of humid days.
-
Uses Java Records for clean, immutable data models
-
Uses Java Streams for parsing and summarizing weather data
-
Reads from a CSV file (
data.csv) -
Calculates:
- Average temperature
- Maximum temperature
- Minimum temperature
- Number of days with humidity above 70%
-
Lightweight and beginner-friendly
Weather Project/
├── src/
│ └── WeatherApp.java
└── data.csv
date,temperature,humidity
2025-01-01,12,70
2025-01-02,15,65
2025-01-03,10,80
2025-01-04,8,75
2025-01-05,14,60
The project uses a record:
record WeatherReading(String date, double temperature, double humidity) {}And reads the CSV using Streams:
List<WeatherReading> readings = Files.lines(path)
.skip(1)
.map(line -> line.split(","))
.map(parts -> new WeatherReading(
parts[0],
Double.parseDouble(parts[1]),
Double.parseDouble(parts[2])
))
.toList();javac .\src\WeatherApp.javajava -cp .\src WeatherAppEnsure data.csv is located in the project root, not inside src.
Follow these steps to run the project in Visual Studio Code.
You need JDK 17 or higher.
Download from: 👉 https://adoptium.net
Check installation:
java -versionIn VS Code, open Extensions (Ctrl + Shift + X) and install:
- Extension Pack for Java (by Microsoft)
- Code Runner (optional)
- Go to File → Open Folder
- Select your:
Weather Project/
VS Code will automatically detect it as a Java project.
Weather Project/
├── src/
│ └── WeatherApp.java
└── data.csv
❗
data.csvmust be in the root folder.
- Open
WeatherApp.java - Click the ▶ Run button above the
mainmethod
Open a terminal:
Terminal → New Terminal
Compile:
javac .\src\WeatherApp.javaRun:
java -cp .\src WeatherApp=== Weather Summary ===
Total days: 5
Average temperature: 11.8
Max temperature: 15.0
Min temperature: 8.0
Days with humidity > 70%: 2
- Java 17+
- VS Code or any Java-compatible IDE
- Java Records
- Java Streams
- File handling (
Files.lines) - Functional programming with lambdas
- Basic data summarization
Feel free to fork this repository and submit pull requests!