docs: Add cleaned-up Git merge vs rebase guide with commit graphs#9
Closed
CodeCrafterX7 wants to merge 3 commits intoSomeshdiwan:masterfrom
CodeCrafterX7:master
Closed
docs: Add cleaned-up Git merge vs rebase guide with commit graphs#9CodeCrafterX7 wants to merge 3 commits intoSomeshdiwan:masterfrom CodeCrafterX7:master
CodeCrafterX7 wants to merge 3 commits intoSomeshdiwan:masterfrom
CodeCrafterX7:master
Conversation
What
- Documented **JAR (Java ARchive)** files as packaged archives for Java applications and libraries.
- Key features:
- File extension `.jar`.
- Bundles multiple `.class` files, resources (images, configs), and metadata into a single archive.
- Built on ZIP format with a special `META-INF/MANIFEST.MF` file.
- Used for distribution, deployment, and execution of Java programs.
- Can be executable (with a Main-Class entry) or non-executable (used as a library).
Why
- Simplifies distribution by combining many class files/resources into one file.
- Enables reusability of code as libraries (e.g., external dependencies).
- Supports portability across platforms with the JVM.
- Provides versioning and metadata for deployment tools.
How
- **Creating a JAR file:**
1. Compile Java program:
```
javac Main.java
```
2. Package into JAR:
```
jar cfe MyApp.jar Main Main.class
```
- `c` → create archive.
- `f` → output to file.
- `e` → specify entry point (Main-Class).
java -jar MyApp.jar
jar tf MyApp.jar
Lists files inside archive.
Examples
1. **Hello World executable JAR**
- `Main.java`:
```java
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World from JAR!");
}
}
```
- Compile and package:
```
javac Main.java
jar cfe Hello.jar Main Main.class
java -jar Hello.jar
```
- Output:
```
Hello, World from JAR!
```
2. **Library JAR**
- Create utility classes, bundle into `Utils.jar`.
- Add to another project’s classpath:
```
java -cp .;Utils.jar MyApp
```
Logic
- Inputs: compiled `.class` files and resources.
- Outputs: compressed `.jar` archive.
- Flow:
1. Java compiler generates `.class`.
2. jar tool packages classes/resources into `.jar`.
3. JVM runs `java -jar` if Main-Class is defined.
- Edge cases:
- Without Main-Class in manifest, `java -jar` fails.
- Paths with spaces must be quoted.
- Complexity / performance:
- Simple ZIP compression; overhead minimal.
- Concurrency / thread-safety:
- Multiple JARs can be used simultaneously on the classpath.
Real-life applications
- Delivering Java applications as single executable files.
- Packaging reusable libraries (e.g., `gson.jar`, `mysql-connector.jar`).
- Used in build tools (Maven, Gradle) for dependency management.
- Required in Java EE/ Jakarta EE deployments (WAR/EAR contain JARs internally).
Notes
- Executable JAR requires `META-INF/MANIFEST.MF` with Main-Class specified.
- Non-executable JARs serve as libraries only, added to classpath.
- JARs can be signed for integrity and security.
- Still widely used even with newer formats (like JMOD in Java 9+).
Someshdiwan
approved these changes
Oct 1, 2025
Someshdiwan
approved these changes
Oct 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 PR Title:
📄 Description: