This episode covers Java application configuration: properties files, YAML, and environment variables, using java.util.Properties and modern configuration libraries, handling multiple environment configurations, and best practices for storing secrets and credentials.

Production applications must not hardcode configuration such as database URLs or API keys. Episode 11 covers configuration and environment variables — how to separate settings from code so applications are flexible and secure.
You will learn properties and YAML files, reading environment variables, using java.util.Properties and modern libraries such as Spring, managing configuration for multiple environments, and best practices for storing secrets. This ability is crucial when an application moves from development to production.
A .properties file is the classic Java format using key=value pairs:
app.name=BelajarJava
server.port=8080
db.url=jdbc:postgresql://localhost:5432/tokoUse java.util.Properties to load and read:
import java.io.*;
import java.nio.file.*;
import java.util.Properties;
public class BacaProperties {
public static void main(String[] args) throws IOException {
Properties props = new Properties();
try (InputStream in = Files.newInputStream(Path.of("config.properties"))) {
props.load(in);
}
String nama = props.getProperty("app.name");
int port = Integer.parseInt(props.getProperty("server.port"));
System.out.println(nama + " di port " + port);
}
}props.load(in) loads all the key-value pairs, then getProperty retrieves their values.
YAML is easier to read for nested structures and is the standard in Spring Boot:
app:
name: BelajarJava
server:
port: 8080
db:
url: jdbc:postgresql://localhost:5432/toko
pool-size: 10YAML uses indentation to show hierarchy — clearer for complex configuration.
YAML can be read with Jackson Dataformat YAML:
mvn dependency:get -Dartifact=com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.2import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import java.nio.file.*;
public class BacaYaml {
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
JsonNode node = mapper.readTree(Path.of("application.yml").toFile());
System.out.println(node.get("app").get("name").asText());
}
}Environment variables separate configuration from code completely and are ideal for sensitive values or values that differ between environments. Set them from the terminal:
export DB_URL="jdbc:postgresql://localhost:5432/toko"
export APP_PORT=8080Read environment variables in Java:
public class BacaEnv {
public static void main(String[] args) {
String dbUrl = System.getenv("DB_URL");
String port = System.getenv().getOrDefault("APP_PORT", "8080");
System.out.println("DB: " + dbUrl + " port: " + port);
}
}System.getenv("DB_URL") retrieves the variable value, and getOrDefault provides a default value when it is not found.
Modern libraries such as Spring support profiles for multiple environments: dev, staging, and prod. Create a separate file per environment:
application.yml -> konfigurasi umum
application-dev.yml -> konfigurasi development
application-prod.yml -> konfigurasi produksiActivate the profile when running the application:
java -jar aplikasi.jar --spring.profiles.active=prodWith profiles, common configuration goes in the main file, and only the differences are overridden per environment.
Secrets such as database passwords and API keys must not enter the repository. Separate public and secret configuration. Gitignore files that contain secrets:
echo ".env" >> .gitignore
echo "application-secret.yml" >> .gitignoreIn production, do not store secrets in configuration files. Use environment variables, a secret manager such as Vault or AWS Secrets Manager, or the secret features of your cloud platform. The principle: the code is the same for all environments, secrets come from outside at runtime.
Warning
Never write passwords, API keys, or tokens in source code. Use environment variables or a secret manager, and make sure files that contain secrets are in .gitignore.
Episode 11 covers application configuration: properties and YAML files, environment variables, java.util.Properties and modern libraries such as Spring, multiple environment configuration with profiles, and best practices for storing secrets and credentials.
Key takeaways:
key=value format; YAML for nested structures.java.util.Properties loads files via props.load().In the next episode, episode 12, we will discuss basic networking and HTTP client — socket programming with java.net.Socket and ServerSocket, the modern HTTP API with java.net.http.HttpClient, making GET and POST requests, consuming REST APIs, and asynchronous requests with CompletableFuture. Time to talk to other services!