テーマ: java
-
JUnit 5 と xUnit.net で単体テストを書く:注釈、ライフサイクル、パラメーター化ケースの比較
JUnit Jupiter は @Test でテストを示し、既定では新しいインスタンス上の各テストの前後に @BeforeEach と @AfterEach を実行し、@ParameterizedTest とソース注釈でデータ駆動のケースを扱う。xUnit.net は [Fact]、コンストラクター、IDisposable で新しいインスタンス上のテストごとの準備と後始末を行い、[Theory] と [InlineData] でケースを、フィクスチャで高コストの共有コンテキストを扱う。両方で同じ形のテストを書くと、多言語チームの慣習をそろえられる。
-
Sizing a JVM inside a container: heap percentage, non-heap memory and CPU count
The JVM reads cgroup limits by default (UseContainerSupport) and sizes the heap as a percentage of the container's memory, not the host's; heap is only part of the footprint, so set MaxRAMPercentage to leave room for metaspace, thread stacks, direct buffers and code cache, check the CPU count the JVM sees, and verify with -Xlog:os+container and native memory tracking before trusting a limit.
-
Maven versus Gradle: what a newcomer needs to build someone else's JVM project
Maven describes a project declaratively in pom.xml and runs fixed lifecycle phases (validate, compile, test, package, verify, install, deploy) with plugin goals bound to them; Gradle runs a graph of tasks configured by build.gradle(.kts) scripts and plugins. Both resolve transitive dependencies but with different conflict rules (Maven: nearest definition; Gradle: highest version), and both ship a wrapper script that pins the build tool version.
-
Java records, sealed types and pattern matching for switch
Records (JDK 16) are transparent, immutable data carriers with a generated canonical constructor, accessors, equals, hashCode and toString; sealed types (JDK 17) restrict which classes may extend or implement them so that a pattern switch (JDK 21) over the hierarchy can be checked for exhaustiveness. Together they give Java a lightweight sum type.
-
JVM garbage collection: the collectors, the defaults and the few flags worth setting
HotSpot ships Serial, Parallel, G1 and ZGC; it picks G1 on machines it considers server-class (two or more processors and at least 1792 MB) and Serial otherwise, with a default maximum heap of a quarter of memory. For most services the flags worth setting are the maximum heap, GC logging, and only after reading logs a collector or a pause-time goal.
-
信頼できないデータのデシリアライズ:pickle と Java serialization
オブジェクトのネイティブなシリアライズ形式は、受信側に任意のオブジェクトを構築するよう指示し、その構築はコードを実行します。Python の pickle 文書も、このモジュールは安全ではないと明言しています。信頼できない入力からこれらを決してデシリアライズせず、旧来のインターフェースで避けられない場合は、ストリームが指定できるクラスを制限し、ペイロードに署名します。
-
After moving a JVM service to virtual threads, what changed in throughput, memory and pinning incidents, and what had to be rewritten?
Open question: JEP 444 states that pinning does not make an application incorrect but might hinder its scalability, and JEP 491, delivered in JDK 24, removes pinning for synchronized blocks; for services that switched request handling to virtual threads, what did the change do to throughput and memory, which pinning or pool-exhaustion incidents occurred, and which code and libraries had to change?
-
Java virtual threads in outline: what changes and what does not
JEP 444 (JDK 21) adds virtual threads: cheap threads scheduled by the JDK onto a small pool of carrier platform threads, which unmount while blocked on most JDK I/O so that thread-per-request code scales without an asynchronous style. They are not faster, must never be pooled, and until JEP 491 (JDK 24) blocking inside synchronized pinned the carrier.
-
Date and time format tokens: strftime, Java, Go, .NET and Moment/date-fns translated
The same letter means different things across formatting libraries: Java's uppercase Y is a week-based year rather than a calendar year, and D is a day of the year in Java and date-fns but a day of the month in Moment — a token table to check before trusting a generated format string.
-
Java のストリームとループ:パイプラインが分かりやすい場合とそうでない場合
ストリームは、1つの終端操作で閉じる中間操作の遅延パイプラインである。コレクションの絞り込み、変換、収集には読みやすいが、パッケージ文書はラムダ内の副作用を非推奨としており、再利用はできず、検査例外にもなじまない。状態を伴う早期終了、インデックスを使う処理、変更にはループのほうが明確である。
-
Why applications ignore the OS trust store: Java cacerts, Python certifi, Node.js and curl
Adding a CA to the operating system's trust store does not make every application trust it. Java, many Python installs, Node.js and curl builds can carry their own CA bundle or keystore, each with its own file location and override environment variable, so a certificate error can persist after the OS-level fix.
機械可読: JSON