2

Use JDK , I can compile a .java file into a .class file, then I can run the .class file, does this mean that the .class file is the final executable file running on JVM ?
Moreover, what's a jar file ? and the difference between jar file and .class file ?

1

2 Answers 2

4

1. A class file is a byte code files, which is executed by the JVM, it has no meaning outside the JVM. Making it meaningful only on JVM but not outside, is what makes every java program run in its own sandbox .

2. Jar file is a collection of all the class file, libraries necessary to run the program, consider its an easy way to pack all the files and depending library and providing a single file. We also have Runnable Jars which can be known as Executable Jar

////////// EDITED PART//////////////////

Now this byte-code is converted to machine level executable during Run-time by the JIT (Just In Time Compiler). JIT will look for the runtime intensive part of the program during Runtime, and then it will convert it into machine level executable, this part of the program is known as Hot-spot, and the JIT is known as Hot-Spot-Compiler.

Sign up to request clarification or add additional context in comments.

11 Comments

Thanks ! But how to make a jar file ?
I am using Eclipse for creating jar as well as Runnable jar
you mean a Jar is different from a Executable Jar ? if so , is there any use of a Jar ?
It's probably worth mentioning that a .jar file is actually just a .zip file with some .class (or .java, or both) files inside it.
I have mentioned it in my answer.. But still i want to clarify this... when we create a simple jar file, it means a way to pack different classes and libraries into a single file, But creating an Executable Jar will make your app run by double clicking it... but make sure its an GUI app, cause command line program needs to be executed from commond line itself
|
1

A jar (java archive) as its name says is an archive or collection of java classes that are ready to be executed.

A java decompiler is a tool that makes a reverse engineering from .class extension to .java extension.

To make a jar use following link

http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

Or using windows command promt

jar cf JAR_FILE_NAME FILE_NAMES_OR_DIRECTORY_NAME
e.g.
jar cf MyApp1.jar C:\JavaProject\MyApp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.