.JAVA Java Source Code
.java

Java Source Code

Java (.java) files contain source code in the Java programming language, developed by Sun Microsystems in 1995 and now maintained by Oracle. Java compiles to JVM bytecode that runs on any platform with a Java Virtual Machine, powering enterprise backends, Android apps, and big data systems.

بنية الصيغة
Header schema
Records structured data
Source CodeText FormatJava 21+ LTSJVM Bytecode1995
بواسطة FileDex
غير قابل للتحويل

Source code format. Conversion is not applicable.

أسئلة شائعة

How do I open and inspect a .java file?

A .java file is plain UTF-8 text. Open it with any text editor for reading. For development, use IntelliJ IDEA (Community Edition is free) or VS Code with the Java Extension Pack. These provide syntax highlighting, auto-completion, refactoring, and integrated debugging.

What is the difference between JDK, JRE, and JVM?

The JVM (Java Virtual Machine) executes bytecode. The JRE (Java Runtime Environment) includes the JVM plus standard libraries — enough to run Java programs. The JDK (Java Development Kit) includes the JRE plus development tools (javac compiler, jdb debugger, jar tool). Developers need the JDK; end users need only the JRE.

Why does the filename have to match the class name in Java?

The Java compiler uses filename-to-classname mapping to locate source files during compilation. If Main.java contains public class Main, the compiler knows where to find it. This convention also helps developers and IDEs locate classes in large codebases. Only one public class is allowed per .java file.

Is Java slow compared to C++ or Go?

Java's JIT compiler optimizes hot code paths at runtime, reaching near-native performance for long-running applications. The JVM's startup overhead (class loading, JIT warmup) makes it slower for CLI tools and serverless functions. GraalVM Native Image compiles Java ahead-of-time, eliminating startup latency.

ما يميز .JAVA

What is a Java file?

Java files contain source code written in the Java programming language, one of the most widely used languages in enterprise software, Android development, and backend systems. Java code is compiled to bytecode (.class files) that runs on the Java Virtual Machine (JVM), enabling write-once-run-anywhere portability.

اكتشف التفاصيل التقنية

How to open Java files

  • IntelliJ IDEA (Windows, macOS, Linux) — Industry-leading Java IDE
  • Eclipse (Windows, macOS, Linux) — Free, popular IDE
  • VS Code (Windows, macOS, Linux) — With Java Extension Pack
  • Any text editor — Java files are plain text

Technical specifications

Property Value
Typing Static, strong
Paradigm Object-oriented (primarily)
Compilation javac to bytecode to JVM
Build Tools Maven, Gradle, Ant
Current Version Java 21+ (LTS)

Common use cases

  • Enterprise applications: Spring Boot, Jakarta EE backends.
  • Android development: Native Android apps.
  • Big data: Apache Hadoop, Spark, Kafka.
  • Microservices: Cloud-native backend services.

المرجع التقني

نوع MIME
text/x-java-source
المطوّر
Sun Microsystems (now Oracle)
سنة التقديم
1995
معيار مفتوح
نعم

البنية الثنائية

Java source files are plain-text documents encoded in UTF-8 (or UTF-16 with a BOM in older codebases). There are no binary headers or magic bytes. Each .java file must contain exactly one public class whose name matches the filename. The file begins with an optional package declaration, followed by import statements, then class/interface/enum/record definitions. The javac compiler parses Java source into an abstract syntax tree, performs type checking, and emits JVM bytecode in .class files. The .class files contain a binary format (magic bytes CA FE BA BE) that the JVM loads and executes. Build tools (Maven, Gradle) automate compilation, testing, and packaging into JAR/WAR archives.

1991James Gosling begins the Green Project at Sun Microsystems, creating Oak (later renamed Java) for embedded devices1995Java 1.0 released with the JVM, applets, and the 'Write Once, Run Anywhere' promise2004Java 5 (Tiger) adds generics, annotations, autoboxing, enhanced for-loop, and enums2006Sun open-sources the JDK under the GPL as OpenJDK2014Java 8 introduces lambda expressions, streams, and the java.time API — the most adopted Java release2017Java 9 introduces the module system (Project Jigsaw) and switches to 6-month release cadence2021Java 17 LTS released with sealed classes, pattern matching for instanceof, and records2023Java 21 LTS released with virtual threads (Project Loom), record patterns, and sequenced collections
Compile and run a Java program أخرى
javac Main.java && java Main

Compiles Main.java to Main.class bytecode, then runs it on the JVM. Since Java 11, single-file programs can also be run directly with java Main.java without explicit compilation.

Build with Maven أخرى
mvn clean package -DskipTests

Cleans previous build artifacts, compiles source, runs annotation processors, and packages the project into a JAR or WAR. -DskipTests skips test execution for faster builds during development.

Build with Gradle أخرى
gradle build --parallel

Compiles, tests, and packages the project using the Gradle build system. --parallel enables concurrent task execution across modules for faster builds in multi-module projects.

Profile with Java Flight Recorder أخرى
java -XX:StartFlightRecording=duration=60s,filename=app.jfr -jar app.jar

Runs the application with built-in JFR profiling enabled for 60 seconds. The .jfr file can be analyzed in JDK Mission Control to inspect GC behavior, thread states, and hot methods.

Check for bugs with SpotBugs أخرى
mvn com.github.spotbugs:spotbugs-maven-plugin:check

Runs static analysis on compiled bytecode to find null pointer dereferences, resource leaks, concurrency bugs, and performance issues. Reports findings as XML or HTML.

JAVA JVM BYTECODE (.CLASS) render lossless The javac compiler translates Java source into platform-independent bytecode. The .class file contains instructions for the JVM, not native machine code.
JAVA JAR ARCHIVE render lossless A JAR bundles compiled .class files, resources, and a manifest into a single ZIP-format archive for distribution and deployment.
JAVA NATIVE IMAGE (GRAALVM) render lossless GraalVM Native Image compiles Java bytecode ahead-of-time into a platform-specific executable with no JVM dependency, achieving millisecond startup times.
متوسط

نقاط الضعف

  • Deserialization attacks: Java's ObjectInputStream can instantiate arbitrary classes, enabling remote code execution via gadget chains in common libraries
  • Log injection (Log4Shell): CVE-2021-44228 demonstrated how JNDI lookups in Log4j could execute remote code via crafted log messages
  • XML External Entity (XXE): default XML parser settings in Java allow external entity resolution, enabling file read and SSRF attacks
  • Reflection abuse: Java reflection can access private fields and methods, bypassing access control when SecurityManager is not configured

الحماية: FileDex displays Java source files as read-only text. No compilation, execution, or server-side processing.

OpenJDK أداة
Open-source JDK implementation — the reference Java compiler and runtime
Maven أداة
Declarative build tool using pom.xml with dependency management from Maven Central
Gradle أداة
Flexible build system with Groovy/Kotlin DSL, used by Android and Spring projects
Spring Boot مكتبة
Framework for building production-ready Java web applications with minimal config
IntelliJ IDEA أداة
JetBrains IDE with deep Java intelligence, refactoring, and debugger integration
JUnit 5 مكتبة
Standard Java testing framework with parameterized tests and extension model