Structure of a Java Program: Classes, Methods and Statements
See how a Java source file is organised, from package and import lines to classes, methods and statements, using one annotated example.
2,881 posts about Java: questions with answers, tutorials and articles, newest first.
See how a Java source file is organised, from package and import lines to classes, methods and statements, using one annotated example.
Create HelloWorld.java, compile it with javac and run it with java. Learn what each line means and how to fix common errors.
Download a current LTS JDK, point JAVA_HOME at its folder, add its bin directory to PATH and verify the setup on Windows, macOS or Linux.
A step-by-step Java study path: language basics, OOP, collections, streams, concurrency, JVM, modern Java 25, JDBC, Hibernate, Spring Boot, testing and interview prep.
A step-by-step guide to building a Kafka Streams topology in Spring Boot, with configuration, a word count example, state stores and testing.
Enable @EnableMethodSecurity and protect service methods with @PreAuthorize, @PostAuthorize and @Secured, including ownership rules and tests.
Step-by-step setup for running Spring Boot on AWS Fargate: image, ECR, task definition, load balancer, health checks and scaling.
Deploy and operate a Spring Boot application on EKS with ECR images, actuator probes, graceful shutdown, autoscaling, disruption budgets and IAM roles for pods.
These Spring annotations are shortcuts for @RequestMapping with a fixed HTTP method. See a CRUD controller, status codes and the mistakes to avoid.
Test a real Spring context end to end. See @SpringBootTest, MockMvc, TestRestTemplate and Testcontainers with working examples for Spring Boot 3.
@Autowired makes Spring inject matching beans into your classes. See injection styles, qualifiers, optional dependencies and common errors.
messages.properties holds externalised text that Spring's MessageSource serves by key and locale. See locale files, configuration and usage in code and templates.
Add multi-language support to a Spring Boot app with Thymeleaf: message bundles, locale resolvers, a language switcher and tests for each locale.
Create a Kafka Streams app in Spring Boot 3 using StreamsBuilder and @EnableKafkaStreams, with a word-count topology, serde settings, error handling and tests.
The actuator starter adds health checks, metrics and diagnostic endpoints to Spring Boot. See how to expose, secure and customise them with Micrometer.
The /actuator/metrics endpoint lists Micrometer metrics for JVM, HTTP and databases. See how to enable it, read a metric and export to Prometheus.
Add Actuator and the Micrometer Prometheus registry, expose the endpoint, record custom metrics and scrape them with Prometheus and Grafana.
Learn why a Kubernetes Service matters: stable IP and DNS, load balancing, ClusterIP, NodePort and LoadBalancer types, with YAML and troubleshooting steps.
Containerise a Spring Boot app, deploy it on Kubernetes and expose it with ClusterIP, NodePort or LoadBalancer Services and health probes.
A Kubernetes Deployment declares the desired state of a stateless app and manages Pods through ReplicaSets, with rolling updates, rollbacks and scaling.