Saturday, June 20, 2020

Create a Java Package and Class in Visual Studio Code

After you've created a Java project in Visual Studio Code (VS Code), you're probably wanting to create the initial package and a Java Class. This guide will cover just that. This example configuration uses the Maven build system and Maven folder architecture, although essentially the same process can happen with a basic Java project too.

Rewind - Create a Java Project First
If you missed the Create a Java Project in VS Code, check it out first. 

Create the First Java Source Folder
First off, you need a Java source folder. Create the folder src/main/java.

Typical Maven architecture follows after:
 src/main/java   Java source directory in a Maven project.
 src/main/test  Testing source directory in a Maven project.
 src/main/webapp   Webapp directory with static resources and server instructions. 

Create the First Project Package
Now you're ready to add your source code to the project but you'll need a package or namespace to add it to. The first thing you'll want to do is add your first base Java package. For example if my package is named com.brandondonnelson, the first base directory would work out to be; src/main/java/com/brandondonnelson. 

Create the first base base package in this directory src/main/java/com/brandondonnelson.

For example, in this image, you'll see the Java source folder contains the first package. The first base package being com.brandondonnelson. 

Example creating the Java source folder and first base package:
      (Click on the animated gif for a larger view)

1 comment:

Unknown said...

I discovered your site web site on bing and check a couple of your early posts. Always maintain up the great operate. I simply additional increase Rss to my MSN News Reader. Seeking forward to reading much more by you down the road!… Best essay wirter

Trying out the Dart Analysis Server

I wanted to see how the Dart Analysis Server was put together and worked. I started looking to see how I could wire it up and try out the co...