Pages

Topics

Tools

↑↓navigate↵openescclose

Java guides

Every published Java guide, newest first, with practical examples you can copy into your own project.

3,965 guides across 14 topics

Topics

Latest Java guides

Illustration comparing java.util.Random and ThreadLocalRandom for concurrent Java applications
Java

Java Random vs ThreadLocalRandom Comparison

Compare java.util.Random and ThreadLocalRandom in Java: how contention, thread safety, seeding, and API usage affect concurrency, and how to choose between them.

JavaRandomThreadLocalRandomConcurrency
SecureRandom class generating random bytes with a shield representing security
Java

Java Secure Random: Using SecureRandom Instead of Random

This article explains how to generate secure random values in Java with SecureRandom: seeding, thread safety, performance, and when to use it instead of Random.

SecureRandomJava SecurityRandom Number GenerationCryptography
Illustration of ThreadLocalRandom providing per-thread random number generators in parallel lanes without shared state contention
Java

Java ThreadLocalRandom: Contention-Free Random Numbers

See how Java ThreadLocalRandom uses per-thread seed state to avoid contention, with code examples for bounded generation, primitive streams, and edge cases.

ThreadLocalRandomJava ConcurrencyRandom Number Generationjava.util.concurrent
Illustration of Java random number generation within a range, showing a number line with bounds and a random value.
Java

Java Random Range: Generate Integers in a Range

Learn how to generate random integers in a range in Java using Random, ThreadLocalRandom, SecureRandom, and the RandomGenerator interface.

javarandomThreadLocalRandomSecureRandom
Illustration of Java Random nextInt generating a random integer within a specified range.
Java

Java Random nextInt: Usage, Bounds, and Thread Safety

java random nextint: Learn how to use Java's Random.nextInt() correctly, including range generation, bound handling, thread safety, and performance tradeoffs.

JavaRandomnextIntThreadLocalRandom
Illustration of Java's Random class showing a seed input and multiple output streams, with a thread-safety indicator and alternatives.
Java

Java Random Class: Usage, Seeding, and Thread Safety

Learn how to use Java's Random class correctly: constructors, methods, seeding for reproducible tests, thread safety, and when to choose ThreadLocalRandom or SecureRandom.

java.util.RandomThreadLocalRandomSecureRandomrandom number generation
Java code snippet showing Math.random() usage with a dice roll example, illustrating random number generation.
Java

Java Math.random(): Generating Random Numbers in Java

Learn how to use Java's Math.random() to generate random doubles and integers, avoid off-by-one errors, and choose between Random, ThreadLocalRandom, and SecureRandom.

Math.randomRandom numbersJava Random classThreadLocalRandom
Diagram showing Math.ceil rounding up and Math.floor rounding down on a number line
Java

Java Math.ceil and Math.floor: Rounding Direction Explained

Understand how Java's Math.ceil and Math.floor round doubles, including negative-number behavior, edge cases, and code examples for choosing the right method.

Math.ceilMath.floorroundingfloating-point
Illustration of Java Math.round rounding a decimal number to the nearest integer
Java

Java Math.round: How to Round Numbers Correctly

Understand how Math.round works in Java, including tie-breaking, negative numbers, and when to use BigDecimal for precise rounding.

Math.roundJava roundingfloating-pointBigDecimal
A Java square root calculation showing Math.sqrt returning a double value from a numeric input.
Java

Java Math sqrt: Calculating Square Roots in Java

A practical guide to Java's Math.sqrt method: syntax, return behavior for negative and NaN inputs, precision concerns, and alternatives such as BigDecimal.sqrt.

Math.sqrtJava MathSquare RootDouble Precision