How to decompile Java Class file in VS Code

6.5k Views Asked by At

enter image description here

So I'm a new java developer and VS code is currently the platform I use. To my understanding every time you create a new object in Java, a class file should be generated as well. As explained in this video { https://www.youtube.com/watch?v=dFuVh_Bzy9c&list=PLsyeobzWxl7pe_IiTfNyr55kwJPWbgxB5&index=50&ab_channel=Telusko beginning from min mark "3:00" } My problem is that whenever I run my program it doesn't create a class file automatically even when creating a class file manually. When I try to manually create a class file I get this message,

"This file is not displayed in the text editor because it is a Java class file. Click here to decompile and open."

After I decompile I get this message "Error while getting decompiled source."

I just really need some advice and help I've been trying to figure this out for about a week now. I tried configuring the paths, installing/uninstalling extensions, reinstalling the JDK. I guess I really just don't know what I'm doing can someone please help me.

The image provided is an example of what happens every time. This only pops up after trying to manually configure a Class file. It doesn't configure automatically.

2

There are 2 best solutions below

6
Pulkit Pareek On BEST ANSWER

VS Code doesn't create Java class files automatically. If you want to create a class file just run
'javac Please.java'
this will create a Please.class file
You can now run this file by typing 'java Please' in the terminal

For Ex: Creating a sample HelloWorld java file creating a sample hello world java file

when I created this file and run it using the run button present in the top right corner, It just output Hello World and does not create any java .class file.

But if I want a java .class file, I can create It using javac.
For that I just wrote in the terminal 'javac HelloWorld.java' enter image description here

And now the .java file is compiled into a .class file
When I click on Decompile Class File
It just decompiles .class file into a Java source file
enter image description here

0
JRichardsz On

Do you want to compile or decompile? I think you need to compile. Fix the question title if this is true.

As a experienced user in netbeans, eclipse, intellij and visual code, I recommend you to use eclipse for java development. Don't use visual code. That ide is perfect for c# and javascript.

If you choose eclipse, I can help you to configure your workspace.

Compile java with vs code

Anyway if you want to use vs code, basically you will need to try plugins and configure them :/

Compile with cli

Since you are trying simple classes, you could use the shell to compile and run your java class. This method is the ultra fast way to do it, even faster than Eclipse

  • install java in your machine
  • validate with java -version
  • compile with javac Please.java
  • run with java Please

enter image description here

You could continue using vs code to develop and the shell to compile like a pro.