When you see a .java file for classes like Thread in IntelliJ IDEA, it’s actually because of two main things: decompiled sources and source attachments. Here’s how it works:
Compiled JDK files: The JDK classes are indeed packaged as .class files in JARs, like rt.jar (or modules in newer JDKs). But these are compiled files, not the original .java source files.
Decompiled Source Code: By default, IntelliJ can actually decompile these .class files, letting you view the code in a readable format. Even without the original source, it’s able to reconstruct something that looks very close to Java code—minus the comments or certain annotations, which don’t carry over when code is compiled.
Source Attachments: When you install a JDK, it usually comes with a src.zip file in the root JDK directory. This src.zip contains the original .java source files, and IntelliJ automatically attaches it to the JDK if it’s available. With this attachment, IntelliJ shows you the actual .java files instead of decompiled code.
So, when you Ctrl + Click on a class like Thread, IntelliJ is showing you the .java file from this src.zip if it’s available. If you searched your disk and couldn’t find Thread.java, it’s likely because you don’t have this src.zip file. Not all JDK installations include it, but you can usually download a version that does.