I’m new to java and learned that when creating a .java file usually there’s a .class file generated automatically, which happened to the previous java files I created.
However, I forgot since when VSCode stops doing this when I create new java file.
Another problem is, when creating a new java file, the shortcut to type "main" and press enter doesn’t generate
public static void main(String[] args) {
}
anymore. I have to literally type out the whole thing, otherwise I have to close this new file, open again, wait a few seconds to half a min or so for the shortcut to work.
Any reason why?
2
Answers
Sounds like you’ve used some sort of IDE before, maybe IntelliJ or Eclipse.
The
.class
filesThe
.class
files are compiled Java source files, containing JVM bytecode. These are generated when you build your Java program, either via a build tool (Maven, Gradle, Ant, etc..) or by compiling the sources. Now, if you use an IDE in most cases the IDE will take care of building your project. If you use the stock VSCode without any Java related plugins, VSCode doesn’t know how to build a Java project out of the box. I believe you can define a build task, and run that, but it doesn’t support it out-of-the-box, without any plugins. So you should look around in the VSCode plugin marketplace what Java-experience-enhancing plugins you can add.Code snippets and shortcuts
Not sure why you have to reopen files for shortcuts to work. That being said, you’re looking for code snippets, or IIRC IntelliJ calls these live-templates. These are, well, templates for code generation, which you can invoke in your editor. IIRC VSCode doesn’t have any Java related code snippets, you have to add them yourself or install a plugin that provides these. In IntelliJ, you have built in templates or snippets for stuff like the main function, for-each blocks, etc.. but again, IntelliJ is a JVM-focused IDE, a very good one too. VSCode is a really good tool, but you may have to install some plugins and add stuff in order to have the cosy IDE-like experience.
The
.class
file is generated by compiling the.java
file. The following settings in settings.json control the generation of.class
files in the bin directory.In addition, you need to download the Extension Pack for Java, read the official document for more help.
Also check the following settings to control the location of code snippet suggestions.