VS Code: Getting Better and Better for Java
- May 18, 2021
- 11670 Unique Views
- 3 min read
VS Code is getting better and better for Java. In the last two months, we have made progresses in all key areas including core language support, testing, debugging, refactoring and project management. Let's uncover the new hidden and less hidden gems!
Type hierarchy
VS Code has already supported call hierarchy for Java, so what about type hierarchy?
Together with Red Hat, we are very happy to announce type hierarchy is publicly available from the latest release of Language Support for Java published by Red Hat.
The feature allows you to view type hierarchy in class, supertype, or subtype view:

Generating tests
Automatically generating testing method templates and importing testing packages is a handy feature to improve coding efficiency.
Starting from April, you can generate the method templates directly from a test file. In May, we will also add support for generating from a source file.To generate testing method templates, open or create a test file under project’s test folder, right-click on file editor to invoke context menu, select “Source Action…” and then “Generate Test…”, and finally select methods to generate:

Note: for generating from a test file, testing dependency need be added into your project.
Package refactoring when moving file
When a .java file is moved from one folder to another, VS Code can automatically update package declaration and importing statements.
The latest release of Language Support for Java published by Red Hat now supports this feature. In addition to automatic updating, the feature also allows you to review and undo package changes:

Classpath configuration
Managing path for source code, output, runtime, and libraries is an important project management task, almost every Java developer will perform. For those using build tool like Maven or Gradle, the tool allows managing these paths through its configuration file.
However, for those not using the build tool, especially like students, they need rely on IDE/editor tool to manage. Responding to that need, we released classpath configuration feature. You can launch the classpath configuration from “JAVA PROJECTS” explorer or by clicking Ctrl+Shift+P to open command palette and then typing “configure classpath” on the palette.

This feature is released as part of Java Extension Pack. Please, make sure you have installed the latest version of the pack.
Debugging enhancements
Inline values
Debugger for Java extension is now able to show variable values inline in editor when stepping through source code:

You can enable this feature by selecting Files->Preferences->Settings menu, searching for “debug.inlineValues” on settings view, and selecting the option.

Customized variables view
You can right-clicking the view to bring up customization menu.

Debugging enhancements were demonstrated at VS Code 1.56 Release Party.
Maven enhancements
Lifecycle support
Now, you can directly execute common lifecycle phases from Maven explorer view by clicking the run icon next to a phase:

Refined creating project experience

Until next time, happy coding!
Don’t Forget to Share This Post!
Comments (2)
Tobiloba
3 years agoI see that you save the point of interest as text in the DB but the response gotten from ChatGPT is JSON. Does this mean you convert the response into string using libraries like gson before saving it in the database?
Denis Magda
3 years agoHey, The response is a String object in the JSON format [1]. The repository takes this JSON string as is and stores to the database [2]. Presently, Spring Data auto-generates the CREATE TABLE statement on the startup and sets the "point of interest" column's type to "text" (or "varchar", don't remember). However, it's always possible to ask Spring Data to use the "json" or "jsonb" type for the column if you wish to query the JSON at the database level. Finally, Vaadin displays a list of PointsOfInterests. Those are generated using the org.json library [3]. Let me know if you have other questions. Hope this helps. [1] https://github.com/YugabyteDB-Samples/budget-journey-gpt/blob/main/src/main/java/com/yugabyte/com/TripsAdvisorService.java#L103 [2] https://github.com/YugabyteDB-Samples/budget-journey-gpt/blob/main/src/main/java/com/yugabyte/com/TripsAdvisorService.java#L74 [3] https://github.com/YugabyteDB-Samples/budget-journey-gpt/blob/main/src/main/java/com/yugabyte/com/TripsAdvisorService.java#L114