Browser Support Test — Java source
Audit your real browser against 30 modern web capabilities - WebGPU, WASM, WebAuthn, Service Workers and more. Get a weighted readiness score, copy-paste detection snippets, and a shareable link.
This is the Java implementation — the same logic the interactive tool runs, in a shareable, citable form.
// browser-support-test — Java polyglot showcase port.
//
// Runtime capability probe, weighted score, and support tier.
//
// This is the Java sibling of src/tools/BrowserSupportTest.tsx (+ the
// browser-support/* modules) that powers the live tool.
//
// ILLUSTRATIVE PORT: the live tool detects *browser* features at runtime
// (navigator/window probes) — a browser-only concern that cannot run in a
// JVM process. This port shows the ANALOGOUS pattern for Java: probes query
// the JVM surface — Runtime.version(), system properties, and
// class-presence lookups via Class.forName — the mechanism Java uses to
// gate APIs on JDK version, and the direct equivalent of
// `'feature' in window`. The scoring algorithm and tier thresholds below
// are byte-for-byte the same as the TypeScript lib's; only the probe
// targets differ.
//
// Language: Java 17 (standard library only).
// Ported from src/tools/BrowserSupportTest.tsx (+ browser-support/* modules).
// Source: CosmoDev polyglot showcase port.
// License: display source — part of CosmoDev's polyglot tool pages.
//
// (The class is package-private so the showcase filename java.java compiles
// as-is — a public class would demand BrowserSupportTest.java.)
package org.cosmolabs.cosmodev.browsersupport;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.function.BooleanSupplier;
/** Runtime capability probe, weighted score, and support tier. */
final class BrowserSupportTest {
private static final String SUPPORTED = "supported";
private static final String LIMITED = "limited";
private static final String UNSUPPORTED = "unsupported";
private static final String UNKNOWN = "unknown";
/** One capability the audit can check: {@code probe} returns true when
* the capability is present in THIS runtime. */
record Check(String id, String title, String category, double weight, BooleanSupplier probe) {}
/** Outcome of one probe. */
record FeatureResult(String id, String status) {}
/** contribution × weight. Same values as src/tools/browser-support/score.ts. */
private static double contribution(String status) {
if ("supported".equals(status)) return 1.0;
if ("limited".equals(status)) return 0.5;
if ("needs-https".equals(status)) return 0.3;
return 0.0; // unsupported, unknown
}
/** Class-presence probe: true when {@code name} is loadable in THIS JDK
* (looked up without running static initializers). */
private static boolean hasClass(String name) {
try {
Class.forName(name, false, BrowserSupportTest.class.getClassLoader());
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
/** Weighted readiness 0–100; matches computeScore() exactly. Results
* whose id isn't in the catalog are ignored. */
static int computeScore(List<FeatureResult> results, List<Check> catalog) {
double earned = 0.0;
double possible = 0.0;
for (FeatureResult r : results) {
for (Check c : catalog) {
if (c.id().equals(r.id())) {
earned += contribution(r.status()) * c.weight();
possible += c.weight();
break;
}
}
}
if (possible == 0.0) return 0;
return (int) Math.round(earned / possible * 100.0);
}
/** tier_for mirrors tierFor() in the island — same thresholds.
* Returns {label, tone}. */
static String[] tierFor(int score) {
if (score >= 90) return new String[] {"Fully modern", "text-success"};
if (score >= 75) return new String[] {"Very capable", "text-success"};
if (score >= 55) return new String[] {"Capable, minor gaps", "text-accent"};
if (score >= 35) return new String[] {"Showing its age", "text-fg-muted"};
return new String[] {"Legacy browser", "text-danger"};
}
/** Representative catalog of JVM capability probes. */
private static List<Check> checks() {
return List.of(
new Check("jvm-64", "64-bit JVM", "Platform", 1.0,
() -> "64".equals(System.getProperty("sun.arch.data.model"))),
new Check("unix", "Unix platform", "Platform", 2.0,
() -> !System.getProperty("os.name", "")
.toLowerCase(Locale.ROOT).startsWith("windows")),
new Check("records", "Records", "Language", 2.0,
() -> hasClass("java.lang.Record")),
new Check("sequenced", "SequencedCollection", "Language", 1.0,
() -> hasClass("java.util.SequencedCollection")),
new Check("nio", "NIO files", "Data", 2.0,
() -> hasClass("java.nio.file.Files")),
new Check("virtual-threads", "Virtual threads", "Runtime", 3.0,
() -> hasClass("java.lang.VirtualThread")),
new Check("vector-api", "Vector API", "Cpu", 2.0,
() -> hasClass("jdk.incubator.vector.VectorSpecies"))
);
}
/** Run probes; a throw degrades to 'unknown' so one failure can't
* abort the audit. */
static List<FeatureResult> runChecks(List<Check> catalog) {
List<FeatureResult> out = new ArrayList<>(catalog.size());
for (Check c : catalog) {
String status;
try {
status = c.probe().getAsBoolean() ? SUPPORTED : UNSUPPORTED;
} catch (RuntimeException | Error e) {
status = UNKNOWN;
}
out.add(new FeatureResult(c.id(), status));
}
return out;
}
public static void main(String[] args) {
List<Check> catalog = checks();
List<FeatureResult> results = runChecks(catalog);
int score = computeScore(results, catalog);
String[] tier = tierFor(score);
long supported = results.stream()
.filter(r -> SUPPORTED.equals(r.status()))
.count();
System.out.printf("Java %s · %s%n",
System.getProperty("java.version"), System.getProperty("os.name"));
System.out.printf("%d/%d capabilities · readiness %d · %s%n",
supported, results.size(), score, tier[0]);
// LIMITED is intentionally absent from probes — kept for vocabulary parity.
assert !LIMITED.isEmpty();
}
}
Also available in 13 other languages
Every CosmoDev tool ships its pure logic in TypeScript (web) and Go (CLI), with authored implementations in a dozen-plus languages — the same contract, ported. Compare all languages side by side →