How does Java know external jar methods?

What I am not getting is how does Java know the referenced jar methods? If it is compiled for run only and you cannot read it, I don’t see how you can see the methods still. An example of my question is similar if you made a jar that displays a window on the screen using a method called "ShowABox". And you add it to another Java project. Then how does the IDE know that a method called "ShowABox" exists since the jar is already compiled? You cannot read class files in the IDE so that it can read methods?

+4
source share
5 answers

All the information you are talking about is actually stored in class files for this very reason.

As for viewing the code in class files, you can do this and it will also prove that the information is saved. Check out the Java Decompiler . Note that you can even build this in eclipse if you want to see it right there.

+4
source

Compiled classes contain bytecode. Methods still have their real names, but their code is compiled into a JVM instruction.

You can read the java class file format specification on the wiki , read the "Constant pool" paragraph, method names (like other class information) in the constant pool.

Just try to open some .class file in a text editor, method names will be found there. (.class files are often located in the project / bin folder or open .jar as an archive and get the .class file from there)

+2
source

A JAR is nothing more than all class files archived in a single file with an attached manifest. Each class file fully describes its public interface.

0
source

JAR files have a very specific format - see http://en.wikipedia.org/wiki/JAR_ (file_format) - and they contain a class of files that also have a very specific format - see http://en.wikipedia.org / wiki / Java_class_file . This format, in addition to providing the Java virtual machine with the information needed to execute the code, also provides the IDE and compilers with the information they need to search for classes, interfaces, fields, methods, etc.

0
source

Yar is nothing more than an archive containing compiled Java .class files compressed for compactness into a single file. Its contents are compiled binaries organized in a directory structure. Thus, you can think of it as a directory with files, but compress it into one archive (as in a zip file). The jar itself is not binary ("exists because the jar is already compiled") - it does not compile itself, but rather contains compiled elements.

0
source

All Articles