java.class-file

How to decompile Java Class file in VS Code


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.


Solution

  • 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