converting .class into .java - java

I deleted a Java project from my hard disk in an attempt to do some refactoring with Eclipse. Luckily I found a recent version of an Executable Jar File and decrompressed it into a bunch of .class files.
I've read some 'decompiling' threads on SO and tried showmycode.com, but I was hoping for more. Isn't it possible to convert .class files into the .java files that made them, comments included - nothing changed? Or find the in the .jar file? What are my best options if not? Other answers on the topic seem outdated. Do I need to download software?

You will not be able to get your comments back, they are lost when you go from .java to .class. As to how to do it any "Java Decompiler" can do it, your code will not be exactly what you wrote, however the code you get back will be functionally the same as what you originally wrote.
JD is a decompiler I have used before and have been happy with its output.

Related

Changing java build location in VSCode (code-runner)

Hopefully a simple question with a simple answer! All I'm trying to do is separate a .java and .class files; I'm compiling using code-runner and have not found a way to change the default build location (same folder as .java files). I've tried searching a few keywords in the settings.json, as well as looked through the preferences/settings, but I haven't found anything useful.
Would appreciate if somebody could point me in the right direction!
maybe you can try to disable the code-runner, instead of use the "java: force java compilation" command(Ctrl+Shift+P), then the vscode will help you compile the .java file automatically, and location the .class file in the satisfied place. as the code-runner just place the .class files alongside the .java files.

how to work on a project that solely consists of .class files in eclipse?

it's been a while since i've been working with java and especially with eclipse. My professor sent me a huge folder with many subfolders and subsubfolders, that mainly contain .class java files. Now I'm supposed to work on these files, but i just can't seem to figure out how to get all of them working. I found a few solutions for single class files, but i have a whole folder hirarchy here that i want to work on.
I hope you can help me - I read something about decompiling? How does that work?
Note that I have around 50 different files here that need to be accessible.
Thank you very much!
I suppose the class you are attending is not something like "CS 902 - Reverse Engineering", because if that was the case, you would know what to do with the .class files.
So, one of the following holds true:
Your professor has made a mistake, and instead of sending you the java files, he/she sent you the class files instead.
Your professor sent you the entire project, which contains both .java and .class files, and for some reason you have only managed to find the .class files, while the .java files are there, and you just haven't found them. Unfortunately, the convention in the java world is to store .class files in a subfolder under the project root, so if you copy the project folder, you are copying .class files together with everything else.
Your assignment is to write new code which makes use of classes and interfaces supplied by your professor, but your professor does not want you to have the source code of those files. In this case, you can still work with the .class files, because the public definitions contained therein are parseable by Eclipse and usable in your project, without any reverse engineering. So, what you need to do is to find a way to tell eclipse that these .class files form a "Class Library" which is supposed to be used by your project, and then go ahead and develop new .java files making use of the library. I don't remember how this is done in Eclipse, but you should be able to find it out by yourself, or look it up, or perhaps someone else might post a how-to answer. However, at this point we do not even know whether this is in fact what you need to do.
You can use a java decompiler like JD-GUI, you can find it at http://jd.benow.ca/ . This is a very handy tool to have when you want to view a decompiled version of your jar. There are plugins available for eclipse and intellij as well.

Classpath of a decompiled Jar file

So I'm not CS major or anything and I've been just poking around stuff to practice some Java skills I watched from a video. I know this isn't the major way to do it but please, let me.
So I extracted a .jar file of this: http://www.zenlunatics.com/quizcards/ (i also have its outright source version). It's open source. I used JD gui to get the source code and got everything in .java. However, once I imported it and tried to run it in Eclipse, it says there is "no main type."
I've searched around and it seems there has to be a public static ... String[] args and I don't see that in any of the generated .java files.
I tried searching about it on youtube and he's getting .class instead of .java files. So, say I renamed .jar to .zip and extracted class files, do I just edit the main .class and build? Any tips, please.
Thanks!
Looking in the source code download the main method is in the QuizCards class (QuizCards.java).
Since there is a source code download you should use that.

.class into .java?

Well, I had just finished coding a java project and went into testing it using eclipse. It was exporting fine and I went ahead and created a new file in src named "config.yml" and it all of a sudden removed all the .java files in my project!
Fortunately, I still have the .jar which contains all the .class files, but I seem to be unable to edit the code (i'm guessing this is to do with it being a .class instead of .java) so, is there any way I can transfer these .classes back to .java ?
btw, if you're recommending any software please note that i'm on a macbook so i'll be limited to what i can use..
Try this (JD-GUI). Have a Mac version and it's nice.
It will show to you the code from the class file.

Problems importing WAR files in Eclipse?

I was unfortunately forced to result to uploading a WAR file as my backup for a web application I am working on.
Luckily I have the most recent WAR file available. I am using Eclipse IDE and am using the Web Tools plugin for all the J2EE work that I am doing with the Dynamic Web Application Project.
When I imported my WAR file, and ran it on a local server, everything works fine. The problem I a ran into is that in the Java Resources/src folder that all my packages and .java files were now only consists of all the same packages, but they are empty.
I checked to see if I could find the files and I found the .class files in an "Imported files" folder that is not accessible in the Eclipse Project Explorer. I believe that I need to do some type of build or something so that my .java files are available for me, but unfortunately this is one area where I lack.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
Also, I would like to configure this environment as it was before where my Java Resources:src folder contaiend the packages and .java files.
One thing I would also like to know is, one way or the other, am I able to obtain the .java source code files if I have access to the .class files?
The short answer is No. There is no way to regenerate original source files from bytecode files.
If you were really, really desperate you could try to use a Java bytecode decompiler on your bytecode files, but the result will be be nothing like your original source code.
All comments and javadocs will be gone.
All original code layout will be gone.
Original local variable and parameter names may be gone, depending on your original compiler switches.
Constant expressions may have been pre-evaluated, and loops, string concatenations and other constructs may have been transformed unrecognizably.
Depending on the maturity of the decompiler, the Java code might not be semantically equivalent to the original code, and might not even be compilable.
I hope you haven't spent too long developing this application because the best answer may be to start again.

Categories