Are JAD decompiled files 100% accurate. I am decompiling some jar files to get the source code and when i am trying to build the project with these java files it is not showing the accurate build. Does i am doing it wrong or the decompiled files are not accurately same as the original one.
Short answer: 99% of the time, decompiled code will not look like the original code, but it should behave the same way. So, assuming the decompiler doesn't make any mistakes, it should be accurate in function, but not in implementation.
Long answer: When the Java compiler translates your source to byte code, it performs certain operations that change how to code looks. I am not an expert on the details of the Java compiler, but A simple optimisation that many compilers perform is inserting small methods into the location in code where they are called.
For example, lets say we compile this code:
public class c
{
public int add(int a, int b)
{
return a + b;
}
public static void main(String [] args)
{
int i = add(1, 2);
}
}
Since b is only one line, and it can safely be substituted with it's contents, a smart compiler may change the main method into this:
public static void main(String [] args)
{
int a = 1, b = 2
int i = a + b;
}
or this:
public static void main(String [] args)
{
int i = 1 + 2;
}
This would be done because the overhead for calling a method is worse than the overhead of putting the method's contents directly into the place it's called.
I have no idea what the Java compiler would do in this situation, but it does make changes to the code like this. It isn't necessarily inaccurate, because it does do the same thing as the original code. Since the compiler doesn't leave the details of these changes anywhere in the .class file, there is no way for a decompiler to know whether an optimisation was performed at any given point in the code, of if it was written that way.
There are also a number of other things that may not survive the transition to byte code (variable names and comments, for instance).
So yes, when you look at decompiled code, you are looking at what the .class file looks like, rather than what the .java file looks like. Even though it seems inaccurate, it should run the same.