MisterHazza
MisterHazza

Reputation: 198

Difference between .jar file and .java file

I am trying to compile my java project I have coded in Eclipse, using the javac <name>.java command in the terminal on mac. However, when I export the project I have created, it is exported as a .jar file. Can anyone tell me how to convert this to a java file, how to export the project as a .java file, or simply the difference between a .jar file and .java file?

Upvotes: 1

Views: 6059

Answers (2)

SwissCodeMen
SwissCodeMen

Reputation: 4875

A .jar-file is a Zip archive containing one or multilple java class files. This makes the usage of libraries (consisting of multiple classes) more handy. Directories and .jar-files are added to the classpath and available to the ClassLoader at runtime to find particular classes inside of it. JAR = Java ARchive. A .java-file contains Java code. A Java file is compiled to produce a class file that can be loaded by the JVM.

Upvotes: 5

Software Engineer
Software Engineer

Reputation: 16100

In Java, the .java files are the source-code, and .jar files contain the compressed and packaged compiled .class files.

Upvotes: 1

Related Questions