Networking
20 questions in 7 subtopics.
Sockets
Write a minimal blocking TCP echo server withServerSocket that can serve several clients at once. What would you change on Java 21?A service has thousands of sockets in TIME_WAIT and CLOSE_WAIT states. Explain what each state means and which one points to a bug in your Java code.Java.net.http HttpClient
Usejava.net.http.HttpClient to send a GET request with a 5 second timeout and parse the body as a String. Show both the synchronous and asynchronous call.Compare java.net.http.HttpClient with Apache HttpClient, OkHttp and Spring's RestClient or WebClient for a service that calls many downstream APIs.Design a shared HTTP client library used by many teams for calling internal services. What defaults and features do you build in?Teams call internal services with five different HTTP client libraries, each with different defaults. Do you standardise on one, and how do you sequence the change across the organisation?URL and URI
What is the difference betweenjava.net.URL and java.net.URI? Why is URL.equals considered dangerous, and what changed for URL constructors in recent JDKs?A client builds request URLs by string concatenation: "https://api/x?q=" + userInput. Some requests fail and one security test injects extra parameters. What is wrong and how do you build URIs safely?TLS and certificates in Java
A Java client fails with PKIX path building failed: unable to find valid certification path to requested target when calling an internal HTTPS service. What does it mean and how do you fix it properly?Certificates for your services now rotate every few days through an internal CA. Java services keep failing after rotation until they restart. How do you make TLS reload work?Your platform runs a mix of JDK versions from several vendors. A new security rule requires TLS 1.3 where possible, no TLS 1.0 or 1.1, and central trust management. How do you roll this out?Certificate lifetimes keep getting shorter and post-quantum algorithms are being added to JDKs. Over the next several years, how should your organisation manage TLS and cryptography in Java services?DNS caching in the JVM
How does the JVM cache DNS lookups? Explainnetworkaddress.cache.ttl and networkaddress.cache.negative.ttl and what happens in containers that call services with changing IPs.After a database failover that changed the endpoint's IP, one Java service kept connecting to the old address for a long time while others recovered quickly. What would you check?Infrastructure moved from fixed servers to cloud endpoints whose IPs change frequently, yet JVM and library defaults date from the old model. How do you govern network-related defaults such as DNS TTL, connection lifetime and keep-alive across the fleet?Connection timeouts
Explain the difference between a connect timeout, a read (socket) timeout and an overall request timeout. What happens if none is set on a Java client?During an incident a slow downstream service caused your service's thread pool to fill and the service stopped answering health checks. Which timeout settings and patterns would have prevented it?Timeouts, retries and DNS settings are defined differently in every client library and repeatedly cause incidents. Where should this responsibility live in a large organisation: in each service, in shared libraries, or in the platform such as a service mesh?HttpURLConnection
Legacy code calls a REST service with HttpURLConnection. Threads hang forever when the service is slow, and connections are not reused. Show what is missing in the code, and say what replaces HttpURLConnection in modern Java.A security scan finds HttpURLConnection used directly in 90 places across 30 services, many without timeouts, andRestTemplate configured with SimpleClientHttpRequestFactory, which also uses it. Plan the retirement of HttpURLConnection usage.No question matches these choices.